Bluetooth communication on Thingy91 (Peripheral mode)

Hi. 

I'm trying to add Bluetooth capability to the "Asset Tracker V2" project. I was able to do it on the nRF9160DK board. I could not find a working example to make the Bluetooth work on Thingy91! I've tried these links:

https://devzone.nordicsemi.com/f/nordic-q-a/56955/nrf52840_pca20035-on-the-nrf-thingy-91-does-not-have-working-bluetooth-samples

https://devzone.nordicsemi.com/f/nordic-q-a/51693/hci_uart-on-thingy-91

https://devzone.nordicsemi.com/f/nordic-q-a/56147/making-thingy91-a-peripheral-bluetooth-device

I used the ".hex" files provided on those pages and flashed it on Thingy91 (Both hex files for the nRF9160 and nRF52840 SoC); It does not work for me. I can see in the RTT terminal that it fails to communicate with the Bluetooth module. I get this in the RTT terminal:

SEGGER J-Link V7.58b - Real time terminal output
J-Link OB-K22-NordicSemi compiled Jul  2 2021 10:44:28 V1.0, SN=960090377
Process: JLink.exe
***** Booting Zephyr OS build v2.0.99-ncs1 *****
[00:00:00.505,981] <err> at_host: UART check failed: 12. Dropping buffer and retrying.
Application started
Initializing Bluetooth..
[00:00:00.835,998] <wrn> bt_hci_core: opcode 0x0000 pool id 5 pool 0x2002f390 != &hci_cmd_pool 0x2002f36c
Establishing LTE link (this may take some time) ...
Bluetooth ready
Scanning...
[00:00:01.264,465] <dbg> lte_lc.w_lte_lc_connect: Network mode: AT%XSYSTEMMODE=1,0,1,0
[00:00:02.444,335] <dbg> lte_lc.parse_nw_reg_status: Network registration status: 2
[00:00:02.593,322] <wrn> bt_driver: Discarding event 0x3e
[00:00:28.907,348] <dbg> lte_lc.parse_nw_reg_status: Network registration status: 2
[00:00:28.946,655] <wrn> bt_driver: Discarding event 0x3e
[00:00:28.978,057] <wrn> bt_driver: Discarding event 0x3e

I'm using the Thingy91 V1.6.0 (PCA20035) and nRF9160DK V1.1.0 (PCA10090) hardware for my tests.

I tried this, and it works (for nRF9160DK):

- Build the hci_lpuart project for the nRF9160DK board

- Build the asset_tracker_v2 project

- Added this to nrf9160dk_nrf9160_ns.overlay file:

&nrf52840_reset {
	status = "okay";
	gpios = <&interface_to_nrf52840 5 GPIO_ACTIVE_HIGH>;
};

/ {
	chosen {
		zephyr,bt-uart=&lpuart;
	};
};

&gpiote {
	interrupts = <49 NRF_DEFAULT_IRQ_PRIORITY>;
};
&uart2 {
	current-speed = <1000000>;
	status = "okay";
	tx-pin = <18>; /* <&interface_to_nrf52840 1 0>; */
	rx-pin = <17>; /* <&interface_to_nrf52840 0 0>; */
	/delete-property/ rts-pin;
	/delete-property/ cts-pin;
	/delete-property/ hw-flow-control;

	lpuart: nrf-sw-lpuart {
		compatible = "nordic,nrf-sw-lpuart";
		status = "okay";
		label = "LPUART";
		req-pin = <21>; /* <&interface_to_nrf52840 3 0>; */
		rdy-pin = <19>; /* <&interface_to_nrf52840 2 0>; */
	};
};

- Added this to nrf9160dk_nrf9160_ns.conf file:

CONFIG_NRF_SW_LPUART=y
CONFIG_NRF_SW_LPUART_INT_DRIVEN=y
CONFIG_UART_2_ASYNC=y
CONFIG_UART_2_INTERRUPT_DRIVEN=n
CONFIG_UART_2_NRF_HW_ASYNC=y
CONFIG_UART_2_NRF_HW_ASYNC_TIMER=2

- Added Bluetooth functionality to send out a notification alert message on button press

This works with no problem on the nRF9160DK board.

I tried to do the same for Thingy91:

- Build the hci_lpuart project for the Thingy91 board (selected the board from "Nordic boards"; it was not listed in Compatible boards). It uses the P1.0, P0.25, P0.19 and P0.22 as UART1 to communicate with nRF9160. These pins are connected to P0.22 to P0.25 of the nRF9160.

- Build the asset_tracker_v2 project

- Added this to thingy91_nrf9160_ns.overlay file:

/ {
	chosen {
		zephyr,bt-uart=&lpuart;
	};
};

&uart1 {
	current-speed = <1000000>;
	status = "okay";
	tx-pin = <22>; /* <&interface_to_nrf52840 1 0>; */
	rx-pin = <23>; /* <&interface_to_nrf52840 0 0>; */
	/delete-property/ rts-pin;
	/delete-property/ cts-pin;
	/delete-property/ hw-flow-control;

	lpuart: nrf-sw-lpuart {
		compatible = "nordic,nrf-sw-lpuart";
		status = "okay";
		label = "LPUART";
		req-pin = <24>; /* <&interface_to_nrf52840 3 0>; */
		rdy-pin = <25>; /* <&interface_to_nrf52840 2 0>; */
	};
};

&gpiote {
	interrupts = <49 NRF_DEFAULT_IRQ_PRIORITY>;
};

&nrf52840_reset {
	status = "okay";
	gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
};

- Added this to thingy91_nrf9160_ns.conf file:

CONFIG_NRF_SW_LPUART=y
CONFIG_NRF_SW_LPUART_INT_DRIVEN=y

# CONFIG_UART_1_NRF_UARTE=y
CONFIG_UART_1_ASYNC=y
CONFIG_UART_1_INTERRUPT_DRIVEN=n
CONFIG_UART_1_NRF_HW_ASYNC=y
CONFIG_UART_1_NRF_HW_ASYNC_TIMER=2

- Added Bluetooth functionality to send out a notification alert message on button press

It hangs up on Bluetooth initialization, and WDT resets the chip after time out. No errors are coming out!

I'm not sure what to do next! Any suggestion is appreciated. 

  • Hi,

    - Build the hci_lpuart project for the Thingy91 board (selected the board from "Nordic boards"; it was not listed in Compatible boards).

    Did you build hci_lpuart for thingy91_nrf52840 ?
    What SDK version are you using ?

    I could not find a working example to make the Bluetooth work on Thingy91!

    The sample lte_ble_gateway shows you how do to this. https://github.com/nrfconnect/sdk-nrf/tree/main/samples/nrf9160/lte_ble_gateway

  • Hi Sigurd.

    Did you build hci_lpuart for thingy91_nrf52840 ?

    Yes.

    What SDK version are you using ?

    I'm using SDK V1.9.1.

    The sample lte_ble_gateway shows you how do to this. https://github.com/nrfconnect/sdk-nrf/tree/main/samples/nrf9160/lte_ble_gateway

    I tried with samples in SDK. I built the hci_lpuart without any change and flashed it on nRF52840. I built the lte_ble_gateway by choosing the "Nordic boards" instead of "Compatible boards" and selecting thingy91_nrf9160_ns. I flashed this on nRF9160. 

    Thingy91 boots with blue led blinking. I see this in the terminal:

    *** Booting Zephyr OS build v2.7.99-ncs1-1  ***
    LTE Sensor Gateway sample started
    Initializing Bluetooth..
    Establishing LTE link (this may take some time) ...
    Bluetooth ready
    Scanning...
    Received unknown event 2
    Received unknown event 2
    Received unknown event 2
    Received unknown event 2
    Received unknown event 2
    Received unknown event 2
    Received unknown event 2

    and then the blinking stops. I don't have the Thingy52 to completely test what is mentioned in the link you sent. I'm assuming it's in central mode. I don't see it advertising. I'm not sure how I can make it advertise something to make sure it's working.

  • I put this in conf file:

    CONFIG_NRF_MODEM_LIB_TRACE_ENABLED=n
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_ZERO_LATENCY_IRQS=n
    CONFIG_BT=y
    CONFIG_BT_DEBUG_LOG=y
    CONFIG_BT_SMP=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DIS=y
    CONFIG_BT_DIS_PNP=n
    # CONFIG_BT_BAS=y
    # CONFIG_BT_HRS=y
    CONFIG_BT_DEVICE_NAME="xxxxxxxxxxx"
    CONFIG_BT_DEVICE_APPEARANCE=1152
    CONFIG_BT_DIS_MANUF="xxxxx"
    CONFIG_BT_DIS_MODEL="xxxxxx"

    added an advertising function in the ble_ready instead of scanning, and now I can see Thingy91 advertising.

    However, I copy the overlay content to my asset_tracker project and put the same initialization as described on the question; It hangs up and resets because of WDT. What else needs to be amended to add bluetooth to asset_tracker project? The asset_tracker uses a lot of sensors on Thingy91; Is there any hardware conflict that needs to be avoided?

  • Thanks for pointing me to the right direction. I copied these from lte_ble_gateway example to the asset_tracker_v2 conf file and now everything works fine:

    CONFIG_NRF_SW_LPUART=y
    CONFIG_NRF_SW_LPUART_INT_DRIVEN=y
    
    CONFIG_UART_1_ASYNC=y
    CONFIG_UART_1_INTERRUPT_DRIVEN=n
    CONFIG_UART_1_NRF_HW_ASYNC=y
    CONFIG_UART_1_NRF_HW_ASYNC_TIMER=2
    
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_RTT_CONSOLE=y
    CONFIG_UART_CONSOLE=n
    CONFIG_LOG_BACKEND_RTT=y
    
    CONFIG_AT_HOST_LIBRARY=n
    
    CONFIG_BT=y
    CONFIG_BT_H4=y
    CONFIG_BT_WAIT_NOP=y
    CONFIG_BT_CENTRAL=n
    CONFIG_BT_GATT_CLIENT=y
    CONFIG_BT_GATT_DM=y
    CONFIG_BT_SCAN=n
    CONFIG_BT_SCAN_FILTER_ENABLE=n

    The problem was that I did not added this line before:

    CONFIG_AT_HOST_LIBRARY=n

    Don't I need this to be set to yes for my LTE AT commands?

  • m.saadat said:
    Thanks for pointing me to the right direction. I copied these from lte_ble_gateway example to the asset_tracker_v2 conf file and now everything works fine:

    Great!

    m.saadat said:

    CONFIG_AT_HOST_LIBRARY=n

    Don't I need this to be set to yes for my LTE AT commands?

    If you don't plan to send AT commands over serial, then it's not needed.

Related