This application will allow you to connect the ATmega4809 microcontroller to the AWS cloud.
View the detailed app note here.
What You Will LearnYou will learn how to send sensor data to the AWS cloud through Bluetooth. You will do this by connecting two click boards to the ATmega4809 microcontroller and providing the logic for sending from the sensor click board to the Bluetooth click board. The Bluetooth module sends the data to the gateway running the Greengrass core and that will send it to the server
Build the Weather SensorConnect the Mikroe Clicks and the Curiosity Nano board to the Curiosity Nano Base for Click Boards.
Simply connect the Curiosity Nano board in its slot, the RN4870 Click in the first mikroBUS slot (mikroBUS 1) and the Weather Click in the second slot (mikroBUS 2). The Curiosity Nano and Base board might require soldering pins and sockets to them.
Explore How the ATmega4808 Code WorksWe wrote this code to make it easy for you to both configure and deploy a working solution. It provides two functionalities: the command state for prototyping purposes and the application state to run the weather sensor functionality.
The Command State
During the command state, the MCU acts as a UART bridge between the serial terminal and the RN4870/71 module.
This functionality opens a line of communication to the RN4870/71 module so that you can use your PC to retrieve the module MAC address. You can also enter the command state to make any desired configurations, such as changing the name of the module.
The command state is only for prototyping purposes, and will not be used in the final application.
TheApplicationState
The BLE-connected weather sensor operation takes place during the application state.
During this state, the MCU reads data from the weather sensors and updates the characteristic values.
The characteristic values are then sent to the cloud gateway through the RN4870/71 BLE module.
You can download the whole project from Github and use it to program the MCU. This tutorial will also explain how to modify the configuration for the Weather Click from MCC.
Interested in a more thorough how-to? Check out the app note to see a detailed explanation of how to program the MCU from scratch
1. Download the files from this GitHub repository.
2. Connect the board to your computer and open MPLAB X.
3. Click on the File menu
4. Click on Open Project
5. In the Open Project tab navigate to where you downloaded the project, select it and click on open project
6. Click on the Blue Shield icon to open MCC. You might have to select the file MyConfig.mc3 when you open it.
7. In the project resources tab, navigate to the Mikro-E Clicks drop down and the Sensors drop down and select Weather.
8. You can now modify the configuration of the Weather sensor. There are several preset sample applications like “Indoor” or “Gaming” or you can set it up yourself by selecting the “Custom” option and changing the other parameters. If a preset is selected, the other options won’t do anything.
9. Press Generate and wait while MCC generates the code and adds it to your project.
10. Click on the Make and Program Device button (green downward pointing arrow icon) to compile the code and program the ATmega4809 MCU.
1. You need to get the MAC address from the RN4870 module and write it in the lambda function code for the Raspberry Pi cloud gateway.
2. Open an UARTserialterminal program like Hercules, Tera Term, or CoolTerm. Hercules will be used in this tutorial.
3. Open Device Manager and navigate to Ports (COM & LPT).
4. Identify the Curiosity Virtual COM port. It is COM5 in this example, but it may be different on your machine.
5. Set up a connection on that port with 115200baud rate, 8 bit data size, no parity. Also enable DTR and RTS as the debugger requires it for data transmission.
6. Send the character “/”. This will make the RN4870 enter into the command state where it stops sending data and can receive commands that configure it. Refer to theRN4870 BLE Module User's Guide for more information on commands.
7. Send the character “d” to receive the information from the RN4870 module and identify the MAC address.
8. From the repository you downloaded from GitHub, open the folder named AWS_Lambda and find the file named lambda_function.py. Open it with a text editor like Notepad++ or Atom.
9. Find the variable called DEVICE and replace the default MAC address with your specific RN4870 ModuleMAC address.
1. The Raspberry Pi gateway should have greengrass already configured by following this tutorial.
2. In Module 3 at the “Create and Package a Lambda function” you can skip the first four steps as the zip file is already provided in the repository. The file is named AWS_Lambda.7z and can be upload as it is.
3. You can now test the setup by subscribing to the topic BLE/data.
4. You should receive data as in the previous picture.
Comments
Please log in or sign up to comment.