The Arduino101 features the Intel Curie Processor with a Bluetooth Low Energy Radio, Inertial Measurement Unit and sensors, in an Arduino Uno format.
Today we'll be learning about the Bluetooth Low Energy Radio and a simple method to get access to sensors and peripherals on your phone or tablet using the Blynk GUI Library to make our user interface.
ImportantThe following project was tested using a few specific versions of libraries and applications - as the most recent versions have some bugs in them.
If you experience problems, first make sure you are using these tested versions:
- Arduino IDE Version 1.8.1
- Intel Curie Board File Version 1.0.7
- Blynk Version 0.4.6
Bluetooth Low Energy support in Blynk is still in BETA test status, so this is pretty new code that is being actively developed. Bluetooth security is also low. Be warned, there may be bugs and dragons here, as you are on the bleeding edge now...
InstallationOn your laptop or computer, please install :
- Install the Arduino IDE Version 1.8.1 from https://www.arduino.cc/en/Main/OldSoftwareReleases#previous
- Install the Intel Curie Board File Version 1.0.7 from https://www.arduino.cc/en/guide/arduino101#toc2
- Install the Arduino_101_BLE_Relays.ino sketch from below.
On your smartphone or tablet, please install :
Start the Blynk Application on Android or iPhone- After installing the Blynk application, start it up
- While Blynk is free, they do charge for using many "widgets" (it's how they stay in business...) for complicated GUI displays, this basic example should fit within a "free" account. You can add "Energy" in the store, usually start with a small amount (< $20), that will last for a number of different Blynk projects.
- Blynk can "clone" a user interface project using a QRcode image - shine your camera at the image below :
Press the "Setup" icon (the Nut Icon on the top right), and you'll get the setup menu like this :
Press the "Email All" button, and it Blynk will email you a unique authorization code for your device. You will need to enter that Auth Code String into your Arduino sketch (program) and then download it to your hardware in order to pair your device with your smartphone.
Plug in your Arduino101The first time you plug in your Arduino101 board, it may take several minutes to identify and load drivers. Don't worry if you get an error the first time, the USB serial port can get disabled during Arduino101 reset, and can sometimes fail before the drivers get loaded. Note which serial port get assigned (i.e. COM7, etc.)
Program your Arduino101 Bootloader- Start the Arduino IDE
- Under "Tools->Board Manager" select the Arduino/Genuino101 board
- Under "Tools->Board Manager" select the correct serial port (i.e. COM7)
- Under "Tools->Board Manager" select Programmer: Arduino/Genuino101 Firmware Update
- Under "Tools->Board Manager" select "Burn Bootloader"
This will insure that your boards file and bootloader version match. If you have problems uploading, try burning the bootloader again.
Program your Arduino101- Cut the Blynk Auth Code from your Email and paste it into the Arduino Sketch in place of the "XXXX''s"
- From the Arduino IDE select "Sketch->Upload", and your project will compile and get loaded into flash memory.
- The default Device name under Bluetooth is "hack01", you can change this in the sketch if you wish to uniquely identify your board.
If not already installed, unplug the Arduino101 and add the boards as shown:
The first thing we need to do is to connect to the Arduino101 Bluetooth - so press the little "Bluetooth" icon on the display:
Now press the "Connect BLE device" button:
Select your device from the list, in the workshop they should have different names for each team's device. "hack02" is shown here...
The internal gears will spin a bit, and then you should get a connected message:
Use the <- back arrow to return to the Relayer setup screen
Now make sure to press the "play" arrow in the upper right hand corner of the screen to change from "setup" mode to "live" mode. If you press the buttons in "setup" mode (which has the dotted background screen), you can change the button settings. In "live" mode, the four buttons operate the four (4) relays, turning them on and off.
In a Blynk enabled sketch, you can either call out physical device pins to manipulate, or use virtual device pins. I prefer virtual device pins for flexibility in porting a project to different boards and/or devices. Virtual pins also allow for arbitrary data types to be passed back and forth across a connection - making it easy to use Wi-Fi, or Bluetooth radios with little or no code changes.
Virtual Pins
Virtual pins are named V0 thru Vxx and use a simple access method:
BLYNK_WRITE(V1) {
int pinData = param.asInt();
digitalWrite(relay1_pin, pinData);
}
V1 controls Relay1, V2 controls Relay2, V3, controls Relay3, etc.
Under the Widget settings for buttons, slider, etc is a pin select menu, just pick an unused virtual pin number to add a new function, either read or write or both.
The widget above will display a value sent from the device on VIrtual Pin V5 with a range of 0-1023 and update frequency of 1 second. Simple widgets, like the button, have less parameters to set. Use "Delete" to remove unwanted widget and to restore your "Energy Points" for making other projects.
Don't Flood the Server...Free accounts are limited to the amount of data they can upload to the server, typically 10 pins per second, which is plenty for most applications. The easiest way to do that is to use a SimpleTimer set to interrupt once per second and update the pins. Another trick I use is to only send data change updates, not the raw data; and if your input data is noisy, then filter it first. See this ESP32/Blynk project for a more advanced example using timers data change flags and filters.
Okay, I got it, what's next?Now that we have simple control of pins working from the Bluetooth Low Energy radio, in the next project we'll read the Inertial Measurement Unit and transmit the sensor data back to the smartphone. The Arduino101 has both a 3D Gyro and a 3-D Accelerator that we'll wire up in the next installment...
Comments