platform | services | language |
---|---|---|
arduino |
iot-hub, stream-analytics, event-hubs, web-apps, documentdb, storage-accounts |
c |
In this tutorial, you begin by learning the basics of working with your
XinaBox CW02 WiFi and SL06 xChips using Arduino IDE.
You will also learn how to connect your CW02 xChip device to the Azure cloud by using [Azure IoT Hub].
Connect the XinaBox CW02 WiFi xChip to an IoT hub that you create.
Run a sample application on xChip CW02 to fetch time from the internet, and ambient light data from the xChip SL06(APDS-9960).
This sample application will also send the collected data to your IoT hub.
-
How to create an IoT hub and register the XinaBox CW02 WiFi xChip.
-
How to connect the XinaBox CW02 WiFi xChip to your computer, and to the xChip SL06(APDS-9960).
-
How to collect data from the xChip SL06(APDS-9960) using the provided sample application which executes in the XinaBox CW02 WiFi xChip.
-
How to send the data collected from the internet and the SL06(APDS-9960) xChip to your IoT hub.
You will require the following before proceeding:
-
XinaBox IP01(FTDI) xChip,
-
XinaBox CW02(ESP32) xChip,
-
XinaBox SL06(APDS-9960) xChip.
-
A Computer with the latest Arduino IDE.
-
A free USB socket on your computer.
-
Access to the internet via a wireless router.
- In the [Azure portal], click New > Internet of Things > IoT Hub.
- In the IoT hub pane, enter the following information for your IoT hub:
Name: The name you have chsen for your new IoT hub. If the name you enter is valid, a green check mark appears.
Pricing and scale tier: Choose the free F1 tier, which is sufficient for your sample application. See [pricing and scale tier].
Resource group: Create a resource group to host the IoT hub or use an existing one. See [Using resource groups to manage your Azure resources].
Location: Choose a location closest to your location.
Pin the dashboard: Check this option for easy access to your IoT hub from the dashboard.
- Click Create. It could take a few minutes for your IoT hub to be created. You can see progress in the Notifications pane.
- Once your IoT hub is created, click it from the dashboard. Make a note of the Hostname, and then click Shared access policies.
- In the Shared access policies pane, click the iothubowner policy, and then copy and make a note of the Connection string of your IoT hub. For more information, see [Control access to IoT Hub].
-
In the [Azure portal], open your IoT hub.
-
Click IoT devices under Explorers.
-
In the Device Explorer pane, click Add to add a device to your IoT hub.
- Add the following details.
Device ID: The ID of the new device.
Authentication Type: Select Symmetric Key.
Auto Generate Keys: Check this field.
Connect device to IoT Hub: Click Enable.
-
Click Save.
-
After the device is created, open the device in the IoT devices Explorer pane.
- Make a note of the
Connection string(secondary key)
and copy it for later use.
Connect the XinaBox Wifi xChip CW02 and xChip SL06(APDS-9960) to your computer
Make sure your XinaBox xChips are arranged as follows.
Plug the XinaBox IP01 xChip, with CW02 xChip and SL06(APDS-9960) xChip connected as above, into a USB port on your computer.
-
Install Arduino IDE
-
Make sure to install the latest release.
Follow the instructions provided here to get support for your CW02(ESP32) in Arduino IDE.
Once installed if you navigate to "Tools->Board" you will see that new boards have been added to the Arduino IDE as seen below
- Go to this Github Page XinaBox SL06
- Follow the installation guide provided on the page.
- Go to this Github Page XinaBox CORE
- Follow the installation guide provided on the page.
The next steps are:
- Select the XinaBox CW02 from the Board options
- Select your Port for programming.
After the above setup, the XinaBox CW02 is ready to be programmed.
In this section, you use the Arduino IDE to open, verify, and load a sample application onto the XinaBox CW02 WiFi xChip.
The application collects time data off an internet time server, and data from the XinaBox sensor xChip SL06, once every 30 seconds, and then sends the data to your IoT hub.
The XinaBox sample application is hosted on GitHub.
Clone the sample repository from GitHub that contains the sample application.
To clone the sample repository, follow these steps:
-
Open a command prompt or a terminal window.
-
Go to a folder where you want the sample application to be saved.
-
Run the following command:
git clone https://github.com/XinaBoxSamples/iot-hub-xinabox-cw02-client-app.git
-
In Arduino IDE, open "File->Open" and navigate to the folder which contains the sample application.
-
Open the
app.ino
file of the sample application.
- Scroll down
app.in
to line 18, as seen below:
-
Modify the required fields to connect your Access Point,
-
Save the file,
Your Arduino Sketch is now ready to be uploaded.
Don't have a real SL06(APDS-9960) sensor?
The sample application can simulate ambient light in case you don't have a real SL06(APDS-9960) sensor. To set up the sample application to use simulated data, follow these steps:
-
Open the
app.ino
file in the app folder. -
Locate the below line of code and change the value from
False
toTrue
:SIMULATED_DATA = False
-
Save the file with Control-S.
Verify the sample application is running successfully
If you see the following output from the serial console window, the sample application is running successfully.
Note that the message log below includes messages sent from the xChip CW02 device to Azure, and also 1 message sent from Azure to the xChip CW02 device.
The following image shows how the message was sent from the "Device->Message to device" menu in Azure.
You have successfully connected an XinaBox CW02 xChip to the Azure IoT hub you created, and sent the captured sensor data to your IoT hub.
You have now learned how to run a sample application that collects sensor data and sends it to an Azure IoT hub. To explore how to store, analyze and visualize the data from this application in Azure using a variety of different services, please click on the following lessons: