Professional Documents
Culture Documents
University of Cagliari: Blynk Platform
University of Cagliari: Blynk Platform
Blynk platform
Claudio Marche
claudio.marche@outlook.it
Claudio Marche
Blynk platform
1/34
http://mclab.diee.unica.it
Summary
• The Blynk IoT platform
• Virtual pins
Blynk platform
Claudio Marche 3/34
http://mclab.diee.unica.it
Blynk platform (2)
To work with Blynk, you need:
Blynk platform
Claudio Marche 6/34
http://mclab.diee.unica.it
Blynk platform – Mobile (3)
Done! Ready to build the first interface!
• Logout button
• Scan for a prebuilt shared interface
Blynk platform
Claudio Marche 7/34
http://mclab.diee.unica.it
Blynk platform – Mobile (4)
• Give a project name
• Choose “NodeMCU” in the
“CHOOSE DEVICE” field
• Choose “WiFi” in the
“CONNECTION TYPE” field
• Tap on “Create Project”
Blynk platform
Claudio Marche 8/34
http://mclab.diee.unica.it
Blynk platform – Mobile (5)
• “Back to projects selection” button
• “Project settings” button
• “Run the interface” button
• Interface canvas
Tap over the interface canvas to show the
“Widget Box”
Blynk platform
Claudio Marche 9/34
http://mclab.diee.unica.it
Blynk platform – Mobile (6)
• Energy meter balance
• Widgets list – scroll to show more
• Widget
• Widget energy
Tap on the “Button” widget to add it on the
interface canvas
Blynk platform
Claudio Marche 10/34
http://mclab.diee.unica.it
Blynk platform – Mobile (7)
• Use the handlers to resize the widget
• Press and drag the widget to move it
• Move it in the upper left corner to
duplicate the widget
• Move it in the upper right corner to
delete (and recycle energy) the widget
Blynk platform
Claudio Marche 11/34
http://mclab.diee.unica.it
Blynk platform – Mobile (8)
• Tap on the Button widget to show the
Button Settings
• Name of the widget
• Color
• Connected pin
• OFF / ON value
• Mode
• ON / OFF labels
Blynk platform
Claudio Marche 12/34
http://mclab.diee.unica.it
Blynk platform – Mobile (9)
• Tap on PIN field to open pin selection
• There are two possibilities:
• Digital (physical pins)
• Virtual (virtual pins)
• Choose “Digital”
• Choose “D4” (ESP8266 builtin LED)
• Tap OK to confirm and go back
• In the “Button Settings” screen tap OK
Blynk platform
Claudio Marche 13/34
http://mclab.diee.unica.it
Blynk platform – Mobile (10)
• Resize the Button widget
using the handlers
• Tap on Project Settings
button
• Write down (or email it) the
Authorization Token
• Tap ok to go back
KEEP the Authorization Token PRIVATE!!
Blynk platform
Claudio Marche 14/34
http://mclab.diee.unica.it
Blynk platform – NodeMCU (1)
Add a new library named “Blynk”
• “Sketch” – “Include Library” – “Manage Libraries…”
• Search for Blynk an install the library
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
void setup() {
// Debug console
Serial.begin(115200);
void loop() {
Blynk.run();
}
Blynk platform
Claudio Marche 17/34
http://mclab.diee.unica.it
Blynk platform – NodeMCU (4)
Opening port
Blynk platform
Claudio Marche 19/34
http://mclab.diee.unica.it
Blynk – PWM (2)
• Use the handlers to
• resize the slider widget
Blynk platform
Claudio Marche 20/34
http://mclab.diee.unica.it
Blynk – PWM (3)
• Set OUTPUT as “D4”
Note the “BUSY” label: it warns the user
that the D4 pin is shared with another
widget (the button widget)!
• Turn off the switch “Send values on
release only”
• Tap ok “OK” button
Blynk platform
Claudio Marche 21/34
http://mclab.diee.unica.it
Blynk – PWM (4)
• Tap on the “Play” button and move the
slider cursor to dim the ESP8266 LED
Blynk platform
Claudio Marche 22/34
http://mclab.diee.unica.it
Blynk – Virtual Pins (1)
• A virtual pin is a pin that is not directly connected to a
physical pin.
• They are used to exchange data between the app and
the microcontroller/board
• Virtual pins are named Vx where x = 1, 2, …
Blynk platform
Claudio Marche 23/34
http://mclab.diee.unica.it
Blynk – Virtual Pins (2)
• Sending data from the board to the app:
Blynk.virtualWrite(VirtualPin, data)
BLYNK_WRITE(VirtualPin) {
...
}
Blynk platform
Claudio Marche 24/34
http://mclab.diee.unica.it
Read temperature data (1)
To do
• Blynk app:
• Add Value Display or Labeled Value widget
• Eading Rate: PUSH
• Connect to V5 virtual pin
• NodeMCU:
• Read temperature data form a DHT11 sensor
• Send the data using V5
Blynk platform
Claudio Marche 25/34
http://mclab.diee.unica.it
Read temperature data (2)
DHT11 NodeMCU
VCC (+) 3V3
GND (-) GND
S D4
Install
- DHT sensor library
Blynk platform
Claudio Marche 26/34
http://mclab.diee.unica.it
Read temperature data (3)
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "DHT.h”
BlynkTimer timer;
Blynk platform
Claudio Marche 27/34
http://mclab.diee.unica.it
Read temperature data (3)
void setup(){
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(1000L, myTimerEvent);
void loop(){
Blynk.run();
timer.run(); // running timer every second
}
Blynk platform
Claudio Marche 28/34
http://mclab.diee.unica.it
MEMs sensors
• Micro-Electro-Mechanical systems is the technology of
microscopic devices with moving parts.
• MEMS are made up of components between 1 and
100 micrometers in size
• Examples:
• Accelerometers
• Gyros
• Microphones
• BioSensors
Blynk platform
Claudio Marche 29/34
http://mclab.diee.unica.it
Read accelerometers data (1)
Library: SparkFunLSM9DS1.h
MPU9250 member functions
9DoF NodeMCU
Constructor(Wire, address) VCC 3V3
int begin() GND GND
Float ax() SCL D1
SDA D2
float ay()
float az()
Blynk platform
Claudio Marche 30/34
http://mclab.diee.unica.it
Read accelerometers data (2)
• Add three “Level H” widgets to canvas
and resize it
• Modify the “Level H” widgets Settings as
follow:
Name Pin Range
X V1 -2…+2
Y V2 -2..+2
Z V3 -2..+2
BLYNK_READ(V1)
{
imu.readAccel();
Blynk.virtualWrite(V1, imu.calcAccel(imu.ax)); //sending to Blynk
}
BLYNK_READ(V2)
{
imu.readAccel();
Blynk.virtualWrite(V2, imu.calcAccel(imu.ay)); //sending to Blynk
}
BLYNK_READ(V3)
{
imu.readAccel();
Blynk.virtualWrite(V3, imu.calcAccel(imu.az)); //sending to Blynk
}
Blynk platform
Claudio Marche 32/34
http://mclab.diee.unica.it
Read accelerometers data (4)
// Before initializing the IMU, there are a few settings
// we may need to adjust. Use the settings struct to set
// the device's communication mode and addresses:
imu.settings.device.commInterface = IMU_MODE_I2C;
imu.settings.device.mAddress = LSM9DS1_M;
imu.settings.device.agAddress = LSM9DS1_AG;
if (!imu.begin())
{
Serial.println("Failed to communicate with LSM9DS1.");
while (1)
;
}
Add these lines of code in the
setup() function
Blynk platform
Claudio Marche 33/34
http://mclab.diee.unica.it
To Do
To do (for the next lesson)
• Install Python 3
• Install Pycharm Professional
Blynk platform
Claudio Marche 34/34
http://mclab.diee.unica.it