In this session we will develop four programs using the Mbed OS online compiler described in the lecture and deploy them on the NUCLEO F446RE board.
The three applications are
- The hardware hello world program Blinky that turns an LED on and off.
- Temperature and humidity sensor
- Motion detection
- Data transmission using LoRaWAN
- NUCLEO-F446RE
- LoRaWAN Transciever Shield (Custom made for DSA by ARM!)
- USB Connector
- Temperature sensor
- Motion sensor
Follow these instructions from DSA 2018 Nyeri by Jan Jongboon to set up. Refer to the original repo here.
-
Sign up for an Mbed account https://os.mbed.com.
-
Go to the NUCLEO-F446RE platform page and click Add to your Mbed compiler.
-
Import the example program into the Arm Mbed Compiler by clicking this link.
-
Click Import.
-
In the top right corner make sure you selected 'NUCLEO-F446RE'.
This has cloned the repository.
-
Click Compile.
-
A binary (.bin) file downloads, use drag-and-drop to copy the file to the NODE_F446RE device (like a USB mass storage device).
Note: Here's a video.
-
When flashing is complete, hit the RESET button on the shield.
-
Open
select_program.h
. -
Set:
#define PROGRAM HELLO_WORLD
-
Click Compile.
-
A binary (.bin) file downloads, use drag-and-drop to copy the file to the NODE_F446RE device (like a USB mass storage device).
-
When flashing is complete, hit the RESET button on the shield.
-
You should notice the led on the nucleo board flashing.
-
Open
hello_world.cpp
and change the value of the constantconst float BLINK_PERIOD_S = 1;
to a smaller or larger value and recompile the program and drag-and-drop the .bin to the Nucleo board. Confirm that the blinking rate has now changed.
-
Let's connect up the hardware.
-
To achieve this connection we will use male-female cables to connect the sensor to the board as shown
-
On the online compiler, open
select_program.h
. -
Set:
#define PROGRAM TEST_TEMP
-
Click Compile.
-
A binary (.bin) file downloads, use drag-and-drop to copy the file to the NODE_F446RE device (like a USB mass storage device).
-
We need to view the program output with temperature and humidity values on the console. In linux we do the following
$ ls /dev/ttyACM*
/dev/ttyACM0
Then connect to the board using screen:
sudo screen /dev/ttyACM0 9600 # might not need sudo if set up lsusb rules properly
Windows
If you are on Windows, install:
- ST Link - serial driver for the board.
- Run
dpinst_amd64
on 64-bits Windows,dpinst_x86
on 32-bits Windows. - Afterwards, unplug your board and plug it back in.
- (Not sure if it configured correctly? Look in 'Device Manager > Ports (COM & LPT)', should list as STLink Virtual COM Port.
- Run
- Tera term - to see debug messages from the board.
Linux
If you're on Linux, install:
- screen - e.g. via
sudo apt install screen
MacOS
Nothing required.
-
Let's connect the motion detector
-
Connect red to AVDD, black to GND, yellow to D6.
-
On the online compiler, open
select_program.h
. -
Set:
#define PROGRAM MOTION_DETECT
-
Compile, flash, ...
-
View the output on the console. You should see motion detected when you move your hand over teh sensor
Follow instructions on Jan's repo in the Grabbing credentials from The Things Network section.
Get the device address, network session key and application session key.
-
Click the Copy button next to 'Device Address' to copy to clipboard.
-
Click the
< >
button of the Network session key and Application session key values to show the value as C-style array. -
Click the Copy button on the right of the value to copy to clipboard.
Paste these keys into the file inc/device_addresses.h
in the appropriate sections:
- Put Device Address on the first line, prefixed with
0x
! - Put Network Session Key on the second line, don't forget to add
;
at the end. - Put Application Session Key on the third line, don't forget to add
;
at the end.
-
Connect the temperature sensor as you did earlier.
-
Connect the LoRa sheild on top of the Nucleo board.
-
The correct orientation of the LoRa shield is when all the logos are on the top.
-
On the online compiler, open
select_program.h
. -
Set:
#define PROGRAM TEMP_TRANSMIT
-
Compile, flash, ...
-
View the output on the console. You get something similar to
=========================================
DSA 2018 Green House Monitor
=========================================
Sending every 20 seconds
[DBG ][LSTK]: Initializing MAC layer
[DBG ][LSTK]: Initiating ABP
[DBG ][LSTK]: Frame Counters. UpCnt=0, DownCnt=0
[DBG ][LSTK]: ABP Connection OK!
Connection - In Progress ...
Connection - Successful
Temp=23.000000 Humi=55.000000
Moist=0.000000
Sending 11 bytes
[INFO][LSTK]: RTS = 11 bytes, PEND = 0
[DBG ][LMAC]: Next Channel Idx=0, DR=4
[DBG ][LSTK]: Frame scheduled to TX..
11 bytes scheduled for transmission
- You should see the data on the console also appear on TTN in your device under the data tab.