Getting Started with Arduino Mega
This guide teaches you how to get started using the Arduino Mega and Adafruit WINC1500 Wi-Fi Shield with Atmosphere. This includes creating your first project, programming the project’s firmware into the Arduino Mega, registering the device to Atmosphere, and having its data displayed on a dashboard.
This guide demonstrates a simple project that sends an integer to the cloud every five seconds, and displays the updated value on the dashboard.
Prerequisite: You should already have an Atmosphere account.
- Arduino Mega 2560
- Adafruit WINC1500 Wi-Fi Shield
The Arduino Mega doesn’t have built-in connectivity, so connecting it to the Adafruit WINC1500 Wi-Fi Shield helps enable it for Wi-Fi and connect to Atmosphere.
- Atmosphere IoT Agent. The Atmosphere IoT Agent is a local application that runs in the system tray and acts as an intermediary between the computer’s connectivity protocol drivers and the browser running Atmosphere, and is used here to assist in programming the device and connecting it to Atmosphere. While the agent is running, a device with Atmosphere firmware installed on it can be registered to Atmosphere directly without the assistance from an additional connection like BLE or Wi-Fi if it’s connected to your computer. You can download the Atmosphere IoT Agent from its downloads page.
The project in this guide doesn’t use IoT Studio’s Application tab to build an app interface and since the Arduino Mega will be registered to Atmosphere directly via a UART connection with your computer, the Atmosphere IoT app is not required here.
Step 1 of 8: Create a New Project
Navigate to Atmosphere IoT Studio from the side menu. When you visit IoT Studio for the first time in a session, you are brought to the Studio Projects screen.
- Click the button. This displays a New Project window.
- Select the Arduino Mega project type and give the project a name, then click Create.
This opens a new project in IoT Studio.
This guide walks through the step-by-step process to perform actions in IoT Studio, but doesn't cover the in-depth aspects of IoT Studio itself. To learn more about using IoT Studio, its areas and features, and Studio elements, visit the Atmosphere Studio section.
Step 2 of 8: Create the Project’s Embedded Firmware
The first aspect of building this sample project is adding elements to the Embedded tab to create the project’s embedded firmware. This involves setting an interval to read an integer value, which will initiate an operation that increments the value every five seconds.
- Add the following elements to the canvas by clicking them in the Element Toolbox:
- Interval element: The interval element sets the project to run at the time set in the element’s properties, which by default is set to once per second (1000 ms).
- Variable element: The variable element allows you to get and set a variable value during project runtime. In this instance, we’ll be setting an integer value.
- Operation element: The operation element performs a mathematical operation on numerical data fed into it. For this project, the operation will add five to the value sent to it.
- Click the interval element to view its properties. In its properties area, change the Time field to
5000. This means the interval will run every five seconds when the project starts.
- Click the variable element, and in its properties change the Initial Value field to
0, then modify its Initial Data Type field to
Integer. This means the value will be an integer that starts at 0.
- Click the operation element, and in its properties change the Operation field to
Addition (+), then modify its Operand field to
5. This means when a numerical value is sent to it, the operation performed against the value will add five to it.
- Connect the interval element to the variable element. This creates an event between them, which can be seen in either the interval element’s properties, or by clicking the connector’s button. The event added is within the
Intervaltrigger. In the Ability field within the event, set the ability to
Get Value. This means that when the interval element is triggered (which is every five seconds), it will read the integer value.
- Next, connect the variable element to the operation element, which also creates a
Perform Operationevent within the
Value Retrievedtrigger. This event performs the operation set in the operation element whenever a value is retrieved from the variable element (every five seconds).
- Lastly, connect the operation element back to the variable element. This creates a
Set Valueevent within the
Operation Performedtrigger, which updates the value of the variable element whenever the operation is performed.
That wraps up the first aspect of the project within the Embedded tab. To this point, an interval has been set that will run every five seconds, and when run will read the integer value from the variable element, which then has its value incremented by five from the operation element. The value of the variable is then updated once the operation is performed.
The Embedded tab canvas should resemble the following image:
Step 3 of 8: Enable the Arduino Mega’s Wi-Fi Connectivity
The next aspect of building this sample project is enabling it for Wi-Fi connectivity. This involves adding a WINC1500 element from the Element Library into the project.
- From the Embedded tab, click the Add Element button located in the bottom of the Element Toolbox. This opens the Element Library, which includes numerous elements for sensors and other devices that can be incorporated into a project.
- In the Element Library, locate the WINC1500 element in the table and turn on its enable switch by clicking it to import it into the Element Toolbox. When done, click Save.
- Add the WINC1500 element to the canvas from the Element Toolbox. This element is configured to work as intended by default, so none of its properties need to be changed. Likewise, it doesn’t need to be connected to any other element; if it’s included in the project it will work properly so long as the Wi-Fi shield is connected to the Arduino Mega.
When the WINC1500 element is added to the canvas, notice that cloud elements (Device Event and Cloud Event) are then populated into the toolbox. By adding a connectivity aspect to the project -- since the Arduino Mega doesn't natively include one -- these elements are now accessible for use.
Step 4 of 8: Enable the Project’s Cloud Connectivity
The last aspect of building this sample project is enabling it for cloud connectivity. This is done on both the Embedded and Cloud tabs.
- While still in the Embedded tab, add a Device Event element to the canvas. The Device Event element is a coupled element between the Embedded and Cloud tabs that enables a project’s data to be sent to Atmosphere.
- Connect the variable element to the Device Event element. This adds the
Send Eventevent to the
Value Retrievedtrigger, which sends the integer value to Atmosphere when the variable is updated.
- Click the Cloud tab to move to the cloud area of the project. Notice how the Element Toolbox has changed, and that the coupled Device Event element is displayed on the canvas.
- Add a cloud storage element to the canvas, and connect the existing Device Event element to it. This allows Atmosphere to store data sent to it from the connected Device Event element.
That’s all for creating the project! With the added cloud connectivity, the project will send the integer value from the Embedded tab to the Cloud tab through a Device Event element, where it’s connected to a cloud storage element to store the data on Atmosphere.
The final canvas for each tab should resemble the following images:
Step 5 of 8: Compile the Project
Once the project is finished, it needs to be compiled. Compiling readies the entire project’s source code for deployment.
- From any tab, click the button in the project options menu on the top-right of the screen. You’ll see a loading message on the screen indicating compiling has started, and will be notified when the project is compiled.
Step 6 of 8: Program Firmware into the Device
With the project compiled, your Arduino Mega can be programmed with the project’s embedded firmware.
Prior to programming a device, ensure you have the following configuration:
- The device is connected to the computer via USB to an available communication port.
- The Atmosphere IoT Agent is installed and running.
- An Internet connection is maintained.
With setup complete, you can program your board:
- While the Embedded tab is active, click the button from the tab’s toolbar. This displays the Program Firmware window.
- Under Device Port, select the communication port the device is connected to.
- Click Program to start programming. When complete, you’ll be notified that the device is programmed with the project’s embedded firmware.
Step 7 of 8: Register the Device
With firmware installed, the device can now be recognized and connected to Atmosphere. Prior to connecting a device, ensure your Atmosphere IoT Agent is running in your system tray. This is needed to check your computer’s communication ports for a device it recognizes, which will find the Arduino Mega.
To register the Arduino Mega:
- Navigate to the Devices area, and click the Scan button in the top-right of the screen to display the Scan window. When the window opens it automatically starts scanning for available devices within range.
- The list of available devices appears. Select the Arduino Mega you just programmed and click Register. This brings you to the Wi-Fi settings screen.
- If the device doesn’t show up, try restarting the agent in your system tray. If you do so, refresh your browser and try adding a device again.
- Configure your Wi-Fi network settings to connect the device. When Wi-Fi settings are entered, the Arduino Mega will connect to Atmosphere over Wi-Fi and remain connected as long as the Wi-Fi connection is maintained.
The device is now registered to Atmosphere and is displayed on the page.
Step 8 of 8: View Device Data
Now that the device’s data is sent to Atmosphere, let’s view it through one of the many dashboard widgets available. In this guide we’ll use a data glance to display the numerical value and view it increment every few seconds. We’ll do this directly on the device’s console page, so click on the newly-added Arduino Mega to enter its console.
- To add a widget to the device’s dashboard, click the button on the right side of the screen. This displays the menu of available widgets. Select the data glance widget to add a data glance to the dashboard.
- Once on the dashboard, click the widget’s menu icon to display its menu, then click Settings.
- In the data glance’s settings, modify the following properties:
- Name: Give the widget a name, such as “Arduino Mega Int Counter.”
- Icon: Select an icon that you think best represents the value.
- Color: Give the widget a color.
- In the Data Source field, click Select, then choose the following configuration options for the widget:
- Select Cloud Storage: Click the cloud storage that is storing the variable element data.
- Select Value: Select the value dataset.
- When finished click Save. The data glance is then populated with the integer value, which updates every five seconds.
Congratulations, you just finished a complete Arduino Mega project with Atmosphere!
If you're interested in a slightly more advanced version of this project, try out the Arduino Mega WINC1500 Wi-Fi Shield Demo available in Studio's Demo Projects section. This demo is similar to the project used in this guide, but also uses the Atmosphere app to press a button to receive the current time and display the time on a debug console by sending it from the cloud back to the device using the Cloud Event element.