Skip to content

ciiram/dsa-abuja-mbed-demo

Repository files navigation

DSA 2018 Abuja - IoT Practical Session

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

  1. The hardware hello world program Blinky that turns an LED on and off.
  2. Temperature and humidity sensor
  3. Motion detection
  4. Data transmission using LoRaWAN

Hardware requirements

  1. NUCLEO-F446RE
  2. LoRaWAN Transciever Shield (Custom made for DSA by ARM!)
  3. USB Connector
  4. Temperature sensor
  5. Motion sensor

Set Up

Follow these instructions from DSA 2018 Nyeri by Jan Jongboon to set up. Refer to the original repo here.

  1. Sign up for an Mbed account https://os.mbed.com.

  2. Go to the NUCLEO-F446RE platform page and click Add to your Mbed compiler.

  3. Import the example program into the Arm Mbed Compiler by clicking this link.

  4. Click Import.

  5. In the top right corner make sure you selected 'NUCLEO-F446RE'.

    Select the correct platform

This has cloned the repository.

  1. Click Compile.

    Compile

  2. 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.

  3. When flashing is complete, hit the RESET button on the shield.

Blinky

  1. Open select_program.h.

  2. Set:

    #define PROGRAM HELLO_WORLD
    
  3. Click Compile.

    Compile

  4. A binary (.bin) file downloads, use drag-and-drop to copy the file to the NODE_F446RE device (like a USB mass storage device).

  5. When flashing is complete, hit the RESET button on the shield.

  6. You should notice the led on the nucleo board flashing.

  7. Open hello_world.cpp and change the value of the constant

    const 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.

Temperature and humidity measurement

  1. Let's connect up the hardware.

  2. Connect red to AVDD, black to GND, yellow to D7. temperature

  3. To achieve this connection we will use male-female cables to connect the sensor to the board as shown

cramming wires

  1. On the online compiler, open select_program.h.

  2. Set:

    #define PROGRAM TEST_TEMP
    
  3. Click Compile.

    Compile

  4. A binary (.bin) file downloads, use drag-and-drop to copy the file to the NODE_F446RE device (like a USB mass storage device).

  5. 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

Software to obtain console output

Windows

If you are on Windows, install:

  1. 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.
  2. Tera term - to see debug messages from the board.

Linux

If you're on Linux, install:

  1. screen - e.g. via sudo apt install screen

MacOS

Nothing required.

Motion detection

  1. Let's connect the motion detector

  2. Connect red to AVDD, black to GND, yellow to D6.

  3. On the online compiler, open select_program.h.

  4. Set:

    #define PROGRAM MOTION_DETECT
    
  5. Compile, flash, ...

  6. View the output on the console. You should see motion detected when you move your hand over teh sensor

Data Transmission over LoRa (Subject to Fixing our internet connection)

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.

  1. Click the Copy button next to 'Device Address' to copy to clipboard.

    device-address

  2. Click the < > button of the Network session key and Application session key values to show the value as C-style array.

  3. 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:

sim2

  • 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.
  1. Connect the temperature sensor as you did earlier.

  2. Connect the LoRa sheild on top of the Nucleo board.

  3. The correct orientation of the LoRa shield is when all the logos are on the top.

  4. On the online compiler, open select_program.h.

  5. Set:

    #define PROGRAM TEMP_TRANSMIT
    
  6. Compile, flash, ...

  7. 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
  1. You should see the data on the console also appear on TTN in your device under the data tab.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published