Maker.io main logo

How to Send Data Over Bluetooth in the Atmosphere IoT Studio

2019-11-13 | By Maker.io Staff

Breadboards

One of the key elements in the Atmosphere IoT Studio Platform is the Bluetooth element, which allows for sending and receiving data over Bluetooth. This element, while it may seem simple, has a few quirks that can catch you out. So, we will be looking at each step to using this element carefully. In this simple how-to, we will send the value of a GPIO input once every second!

BOM

Scheme-It

How to Send Data Over Bluetooth in the DigiKey IoT Studio

Sending Data over the IoT Studio

Atmosphere IoT Studio is an event-based code system, meaning that things happen when something else has happened (unlike typical code written on an Arduino). Therefore, the key to using the Bluetooth element is an event on the IoT device (such as an interval or button press) and an interval on the mobile application side. Since Bluetooth elements do not interact with the internet and only another Bluetooth device, you will need a smartphone with the Atmosphere IoT Studio app and Bluetooth capabilities.

The first step is to create a new project and to select the Adafruit Huzzah 32 device. It does not matter what you call this project, but it would make sense to call it something such as “Bluetooth Example – Sending Data.” Once that’s done, drop in an interval element, a GPIO element, and a Bluetooth BLE GATT Characteristic element.

How to Send Data Over Bluetooth in the DigiKey IoT Studio

The next step is to connect these blocks together, such that the interval connects to the GPIO block and the GPIO block connects to the BLE block.

How to Send Data Over Bluetooth in the DigiKey IoT Studio

Now that the blocks are connected, you will need to edit the blocks to ensure they are configured correctly. The interval element should be set to 300ms, the GPIO element should be connected to IO13 and be configured as an “Input Pull Up,” while the BLE element needs both read and write options set, as well as the write and read data type set to “Boolean.”

How to Send Data Over Bluetooth in the DigiKey IoT Studio 

At this point, you might think that you could now move to the app side, but it’s important to remember that you also have to configure the connections. The interval to GPIO connector should be triggered on an interval and the GPIO pin should be set to read. The connector between the GPIO pin and the BLE element should have its triggers changed to read (by default, it’s interrupt). When you change the triggers to read and there are no events, just click the add event button. From here, you can change the drop-down box to read.

How to Send Data Over Bluetooth in the DigiKey IoT Studio

Creating an App with a Bluetooth Element

Now that our device program has been completed, it’s time to create our app. Naturally, you might think that the Bluetooth element can be connected to other elements and have an “on data receive” trigger. However, this is not possible, and reading data from a Bluetooth element from the app side also requires an interval, triggering a BLE element to read the data that has been sent. The image below shows the button that you need to press to get to the app designer.

How to Send Data Over Bluetooth in the DigiKey IoT Studio

When you switch to the app designer, you will notice that there is already a Bluetooth element, which directly corresponds to the Bluetooth element on the device. In this designer window, you need to add an interval element, as well as a label. Then, connect the blocks together (as shown in the image below).

How to Send Data Over Bluetooth in the DigiKey IoT Studio

The connection between the interval and the BLE elements needs to trigger a read on an interval, while the connection between the BLE and label elements needs to be set to “Set Text” and the value of the text should be set to “readData.” For those who are curious, some boxes in Atmosphere IoT Studio use JavaScript, and this readData refers to a variable in JavaScript!

How to Send Data Over Bluetooth in the DigiKey IoT Studio

Save the project, compile it, program your device, and then provision the device from your smartphone using the Atmosphere IoT Studio app. When you push the button connected to IO13, you will find that the value on the app changes from true to false. You’re now sending data over Bluetooth!

制造商零件编号 3405
HUZZAH32 ESP32 FEATHER LOOSE HDR
Adafruit Industries LLC
¥162.39
Details
制造商零件编号 FIT0096
BREADBRD TERM STRIP 3.20X2.00"
DFRobot
¥24.43
Details
制造商零件编号 1825910-6
SWITCH TACTILE SPST-NO 0.05A 24V
TE Connectivity ALCOSWITCH Switches
¥1.30
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum