Communicate two microcontrollers via BLE

Hello,

I'm using a nRF52 DK to test BLE communication with another microcontroller. What I need to test is the nRF52 pairing with another brand microcontroller, send a data stream and close the connection.

Could you please tell me which example from the Bluetooth samples list I can use for starting?

Thanks for your attention.

Regards,

Parents Reply Children
  • Hello ,

    Thank you very much. I've reviewed this example and it is supposed to connect with the first device with an strong signal. Is there a way to force the board to connect with the device with a given MAC address?

  • The application must always decide whether to connect to a device or not. In this case a filter for 'a strong signal' is used, but you can filter for whatever metric you want, including the BLE address (MAC). We have an in-house Scanning module, but you can also use the standard blutetooth sub-system APIs as demonstrated in the Bluetooth: Central / Heart-rate Monitor sample. 

    Unknown said:
    Thank you very much. I've reviewed this example and it is supposed to connect with the first device with an strong signal.

    That is true for the zephyr/samples/bluetooth/central sample. The central_hr sample does use a scan filter however. See /samples/bluetooth/central_hr/src/main.c line 163:

    static void start_scan(void)
    {
    	int err;
    
    	/* Use active scanning and disable duplicate filtering to handle any
    	 * devices that might update their advertising data at runtime. */
    	struct bt_le_scan_param scan_param = {
    		.type       = BT_LE_SCAN_TYPE_ACTIVE,
    		.options    = BT_LE_SCAN_OPT_NONE,
    		.interval   = BT_GAP_SCAN_FAST_INTERVAL,
    		.window     = BT_GAP_SCAN_FAST_WINDOW,
    	};
    
    	err = bt_le_scan_start(&scan_param, device_found);
    	if (err) {
    		printk("Scanning failed to start (err %d)\n", err);
    		return;
    	}
    
    	printk("Scanning successfully started\n");
    }

  • Thank you. Now I can use the MAC to decide to which device connect. Which function should be used to send a string of data to the peer device?

  • First you will need a Characteristic to communicate the string through. We recommend the Nordic UART Service (NUS) because it is a simple Service with one Rx Characteristic and one Tx Characteristic, where both transmits data in the form of strings. 

    You can also test the NUS service by connecting the nRF52 to a smartphone that runs the nRF Toolbox app. Then you don't need to implement the NUS service on your peer device before you can verify that the NUS service runs as intended on your nRF52.

  • Hello ,

    Can I use the NUS to send data to an ESP32 module? I've been trying for a while but the Tx function always fails.

Related