Zephyr reference samples for Thingy53 dev kit, simple reference samples and sensors server
- Air quality with BME688 driver and library integrating Bosch's BSEC2 library for IAQ (Indoor Air Quality) measurements.
- Mesh Network with OpenThread broadcasting UDP packets as client and running a sensors server.
- C++ application with json inputs for config and outputs for sensors enables direct mapping to MQTT
- RGB Led, Light color, Battery
- Raspberry pi server repo : https://github.com/HomeSmartMesh/raspi
Below is an open box Nordic Thingy53 attached to USB and j-Link debugger
- Nordic's Thingy53 IoT Prototyping platform
- Segger's j-Link Edu mini (optional)
Used Sensors in this repo's samples
-
BME688 Digital nose : low power gas, pressure, temperature & humidity sensor with AI
-
Color sensor BH1749NUC
- BH1749NUC Datasheet
- Measures Red, Green, Blue and IR
- Illuminance Detection Range 80 klx (0.0125 lux/count)
The following drivers and libraries have been created in this repo
- BME688 Zephyr Driver : in drivers/sensor/bme688
BME68x-Sensor-API
vendor driver integration https://github.com/boschsensortec/BME68x-Sensor-API- Using Zephyr's Sensor API in C language for usage in BME688 simple forced mode
- Driver extension functions to use BME688 in Parallel mode and get all x10 gas measures
- BME688 Server : in subsys/bme688_server
- C++ wrapper to configure the BME688 usage in json structure (temperatures profile and durations)
- handler delivers the sensor results in a json structure (temperature, humidity, pressure, gas-0..gas-9)
Bosch-BSEC2-Library
.a vendor's binary integration for IAQ (Indoor Air Quality) measurements https://github.com/boschsensortec/Bosch-BSEC2-Library
BME688 Components and Data
mkdir thingy53
cd thingy53
>west init -m https://github.com/HomeSmartMesh/sdk-hsm-thingy53 --mr main
>west update
building a sample
cd hsm/samples/20_sensors_server
west build
west build -- -DOVERLAY_CONFIG="overlay-logging.conf"
flashing using an attached debugger
>west flash
recover by deleting flash
>west flash --recover
flashing manually
- connect to USB
- power on while holding SW2 down, see details on updating thingy53 through USB
- with nRFConnect Programmer flash
hsm\samples\20_sensors_server\build\zephyr\dfu_application.zip
Serial Port
- USB Serial Port : with the config
CONFIG_STDOUT_CONSOLE=y
this board creates a UAB virtual COM port of stdout. Note using the nRFSDK Connect Serial Terminal allows auto detection and reconnect of serial ports, very useful to recover automatically after flashing - RTT Debugger Serial Port : using
CONFIG_USE_SEGGER_RTT=y
it is possible to have logs with the attached debugger and without using the board USB device, this needs rebuild the sample differently though.
sample with joiner config CONFIG_OPENTHREAD_JOINER_PSKD
are 13_ot_joiner, 14_ot_udp_echo_server, 15_udp_json_endpoint and 20_sensors_server
Note: Make sure to press the Thingy53 button after the raspberry pi commissioner is started. The button will reset the device and try to join thread networks on the new startup.
joining info:
- the
eui64
can be known by first flashing the logging version withoverlay-logging.conf
- without knowing the
eui64
it is also possible to commission with '*' aseui64
parameter
on the raspberry pi
sudo ot-ctl
commissioner start
commissioner joiner add * ABCDE2
for convenience and given that this repo is providing samples for thingy53_nrf5340_cpuapp
board, it has been configured in the CMakeLists.txt to be taken as default board, it is still possbile to override it with -b option.
simplest program for checking UART with a live counter
controlling the colors of the Red Green and Blue LEDs with pwm
- function for setting x3 float colors
- function for blinking a color
- Power Management Integrated Circuit specification nPM1100_PS_v1.3.pdf
- Thingy53 schematics
PCA20053_Schematic_And_PCB.pdf
used pios
- Battery Measure ENABLE P0.16
vbatt.power-gpio
inthingy53_nrf5340_common.dts
- Battery Measure BAT_MEAS P0.06/AIN2
vbatt.io-channels
inthingy53_nrf5340_common.dts
- Battery charging Indicator CHG PMIC_STATUS P1.00
battery-charge-gpios
inapp.overlay
Note: Do not use this sample, it is for info only, using BME680 driver for BME688 can only fetch temp,hum,press but not gas due to difference in registers config
- this sample is based on BME680 Zephyr sample from Nordic's fork nRF BME680 Zephyr sample
- this samples uses the device drivers declaration
bosch,bme680
in the thingy53 dts filethingy53_nrf5340_common.dts
used for- Temperature
- Air pressure
- Humidity
- sample demonstrating the usage of the BME688 C driver wrapper over Zephyr's sensor API and using Bosch's
BME68x-Sensor-API
- config flag
CONFIG_BME688=y
Output
del_period = 142590
Temperature(deg C), Pressure(Pa), Humidity(%), Gas resistance(ohm)
25.24, 95917.63, 40.48, 23992.50
new data , no Gas Index , Gas Meas Valid , Heat Stability
references
- Nordic DevZone Forum : https://devzone.nordicsemi.com/f/nordic-q-a/98569/gas-resistance-values-from-bme688-on-thingy-53
- introducing usage additional custom functions to enable usage of BME688 in prallel mode still in C language
- config flag
CONFIG_BME688=y
bme688_set_mode_default_conf()
bme688_data_get()
!! crashing to be fixed !! in the meanwhile and for parallel mode see 06_bme688_parallel
samples/07_bme688_parallel_cpp
- a C++ wrapper for bme688_server library
- config flags
CONFIG_BME688=y
andCONFIG_BME688_SERVER=y
set_bme688_config()
with temperatures and durations in a json structurestart_bme688()
with a handler that gets a json structure with temperature, humidity, pressure, gas-0..gas-9
- Enables the BSEC2 part of the bme688_server library,
Bosch-BSEC2-Library
.a vendor's binary integration for IAQ (Indoor Air Quality) measurements https://github.com/boschsensortec/Bosch-BSEC2-Library - new flag
CONFIG_BME688_BSEC2=y
in addition toCONFIG_BME688=y
andCONFIG_BME688_SERVER=y
- returns
iaq
,iaq_accuracy
,co2_eq
,breath_voc
,stabilization
andrunin
calculated from the bsec2 library
- Color sensor BH1749NUC
- BH1749NUC Datasheet
- Measures Red, Green, Blue and IR
- Illuminance Detection Range 80 klx (0.0125 lux/count)
- provides a shell on the USB UART interface that allows to manually configure the openthread stack
build
cd thingy53/hsm/samples/11_openthread_shell
>west build
- using a fixed openthread network config allows to hard-code network credentials for testing only (not suited for deployment), even when used for local deployments it is unpractical as the device needs to be flashed everytime the network parameters change
- loops sending alive counter messages as thread udp packets
overlay-logging.conf
uses RTT and USB log for openthread state and loop count
build options
>west build
>west build -- -DOVERLAY_CONFIG="overlay-logging.conf"
- Commissioning with a joiner PSKd (Pre-Shared Key for the Device)
ABCDE2
- needs the commissioner to be ready for this device
- short SW2 button press < 1 sec : soft reset
SYS_REBOOT_WARM
- will retry joining if not attached
- long SW2 button press > 1 sec : OpenThread Farctory reset (delete credentials) and
SYS_REBOOT_COLD
- will try joining a new network
overlay-logging.conf
uses RTT and USB log and prints the following on startup- Joiner
eui64
- Joiner
pskd
built with in the provided config - the qrcode text containing the
eui64
andpskd
as parameters - a url to a generated qrcode image to be used for joining
- Joiner
- loops sending alive counter messages as thread udp packets
build options
>west build
>west build -- -DOVERLAY_CONFIG="overlay-logging.conf"
- OpenThread broadcasts udp packet
- separate
udp_rx_handler
thread - binds to port 4242 and echoes back received characters (printed as text)
- OpenThread server endpoint can receive json commands and send back responses
- OpenThread Joiner device
- OpenThread mesh client broadcasts udp json packet with Voltage, Alive counter, Charging status, ambient light RGB IR, Temperature, pressure, humidity and Indoor Air Quality
- OpenThread server endpoint can receive json commands and send back responses
on rasp
>sudo ot-ctl
udp open
udp send ff02::1 4242 hi_there_now
- MQTT publish sample
- reliable ot tx rx, e.g. tcp, websocket, session,... for packet request response
- Python MQTT Translator for request response with json bodies
- RGB Led notification service
- sensors json logger service (configurable sensors and rates)
- ot lifecycle, if not connected, restart after timeout, which will retry join
- system lifecycle, watchdog restart
- power measurements
- microhpone streaming
- microphone local
This repository is a Zephyr workspace application that contains the samples source code only therefore lightweight to clone and manage, yet it tracks an exact reference of all dependencies that get deployed once initialized with west init
- k_sleep in interrupt functions might lead to os crash, usage of LOG effect unclear so to be avoided
- Fifo, Lifo, Queue take pointers only, user allocates the data but there's also
k_fifo_alloc_put
- Message Queues copy the data provided in a ring buffer, (overwrite oldest)
- Work queues are used to delay functions execution or order multiple functions execution
- step one is to get familiar with Zephyr a good reference is https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/develop/index.html
- second is to focus on the subsection for west https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/develop/west/index.html
This repository is targetting an nRF dev kit, thereforeit is safer to derive it from nRF's fork of Zephyr and other dependencies. the steps are :
- west.yml dependencies taken from https://github.com/nrfconnect/sdk-nrf/blob/main/west.yml
- the default remote is hsm instead of ncs, therefore in the
projects:
the remote ncs needs to be added where applicable - in the application
zephyr
, thename-allowlist
helps reduce the dependencies from Zephyr - note also some Zephyr dependencies can be replaced with top level projects such as mbedtls which is then taken from nRF fork and not from Zephyr
- in case of Kconfig wanrings, it is necessary to compare with the original repo (ncs/nrf) and find the directory (dependency) where that flag is used e.g. missing config for
NRF_MODEM_LIB_SHMEM_CTRL_SIZE
which default isNRF_MODEM_SHMEM_CTRL_SIZE
defined innrfxlib\nrf_modem\Kconfig
that shows a dependency fromnrfconnect/nrf
tonrfconnect/nrfxlib
- Kernel services : https://docs.zephyrproject.org/latest/kernel/services/index.html
- https://www.hackster.io/wassimfilali/indoor-air-quality-with-thingy53-and-bme688-5c763b
- https://devzone.nordicsemi.com/f/nordic-q-a/98569/gas-resistance-values-from-bme688-on-thingy-53
- https://devzone.nordicsemi.com/f/nordic-q-a/92593/using-bsec-2-library-for-bme688-with-thingy53
- https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/How-to-convert-gas-res-to-AIQ-in-thingy53/m-p/67211/highlight/false#M13176
- https://www.hackster.io/mahmood-ul-hassan/how-to-read-nordic-thingy-53-onboard-bme688-sensor-003560
- https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/IAQ-from-BME688-on-NRF9160-ZephyrRTOS/m-p/50953