12. Interface and application programming

This week, I used Blynk to connect and control Arduino UNO with a smartphone.

Assignments

group assignment:

  • Compare as many tool options as possible.

individual assignment:

  • Write an application that interfaces a user with an input &/or output device that you made.

X. Group Assignment


Link to group session page.

X. Individual Assignment


Blynk is one of the platform to realize Internet of Things using your smartphone.
So I tried turn on/off D13 pin of Arduino UNO which is connected to on-board LED on Arduino UNO.

First, Created a project and set the type of connection.
Made a virtual button to set the pin number to D13.

And then, downloaded Blynk Library from this link. This library is used for working Blynk on Arduino or other microcontroller boards.

Opened Arduino IDE and

For the sketch, I used the sample sketch: Toolbar_File -> Examples -> Blynk -> Boards_USB_Serial -> Arduino_Serial_USB.

Code1 - Arduino_Serial_USB

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  =>
  =>          USB HOWTO: http://tiny.cc/BlynkUSB
  =>

  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT DebugSerial


// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";


void setup()
{
  // Debug console
  DebugSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void loop()
{
  Blynk.run();
}

Connected Arduino UNO to my PC and wrote the sample sketch to Arduino UNO.
And then, pened Terminal and ran sudo ./blynk-ser.sh at the directory: Arduino -> libraries -> blynk-library-master -> scripts.

Failure

Download socat before I run sudo ./blynk-ser.sh.
I try to ran ./blynk-ser.sh but couldn’t… So I installed socat with Homebrew.
brew install socat
and then I ran it again so I could make it!!

2. Drive a motor with IoT

It is very easy to drive a motor with Blynk.
Connected the motor driver modules which I made at week11 to Arduino UNO and turned On/Off the assigned pin using Blynk.
I could use the same sketch as the above Code1.

3. Temperature and humidity sensing with IoT

Next, I used ESP-32 board that I made in Week9: Input Devices and tried sensing the temperatutre and humidity from DHT11 Temperature and Humidity Sensor.

The connection between my board and the sensing kit board are shown in the below image;

So first, I set Blynk app. to read temperature and humidity values.

  • Create a New Project: Tem_Sensor
  • Choose device: ESP32 Dev Board
  • Connection Type: WiFi

Go to Tem_Sensor Project and open Widget Box page. To show the sensing values, I choose Gauge Widget(one for each value).

Push Gauge Widget button and set the condition as below;

  • Name: Temperature
  • Input: V6 (input the value assigned in program later.), Value Range: 0 - 50
  • Refresh Interval: 1sec

Setting has finished.
Set the humidity gauge in the same way.

Next, Programming…

That was very hard to me because I needed to combine some codes in the multiple program.

Based on the sample code: ESP32_WiFi (File -> Example -> Blynk -> Boards_WiFi -> ESP32_WiFi), I added some code in the sample code: DHT11 (File -> Example -> Blynk -> More -> DHT11).

Code2 - TemSensor_ESP32

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on ESP32 chip.

  Note: This requires ESP32 support package:
    https://github.com/espressif/arduino-esp32

  Please be sure to select the right ESP32 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Q5w_0fjC59zECCrusC__YS_4CceL1gyN";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Buffalo-G-88C8";
char pass[] = "h5xcv6aa5btkj";

#define DHTPIN 32          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();
  timer.run();
}

Blynk.virtualWrite(V5, h) code shows the humidity value in the gauge and Blynk.virtualWrite(V6, t) code shows the temperature value in the gauge.
Please make sure to write the same Pin No. in that code as the No. set in gauge widget(V5, V6).

Active #DHTTYPE DHT11 code to use DHT11 at this time.

Failure

Assign the correct pin to send the sensing value
Firstly, I connected sensor pin of the sensor module with pin 6 in my board. But the error occurred in the serial monitor like below;

[3191] Connecting to blynk-cloud.com:80 [3481] Ready (ping: 100ms). Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled. Memory dump at 0x400d3004: ef440000 ffffffff ffffffff Core 1 register dump: PC : 0x400d3008 PS : 0x00060430 A0 : 0x800d3e5e A1 : 0x3ffb1f80 A2 : 0x3ffc129c A3 : 0x00000001 A4 : 0x00000000 A5 : 0x00002327 A6 : 0x00000000 A7 : 0x3ffba264 A8 : 0x800d1c6b A9 : 0x3ffb1f60 A10 : 0x3ffc1044 A11 : 0x000003e8 A12 : 0x400d1b38 A13 : 0x00000000 A14 : 0x00000001 A15 : 0x00000000 SAR : 0x0000000a EXCCAUSE: 0x00000000 EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff Backtrace: 0x400d3008:0x3ffb1f80 0x400d3e5b:0x3ffb1fb0 0x40088f49:0x3ffb1fd0

Thought about this issue with the member in Kamakura, we resulted that the above error seems to occur because the CPU attempts to read an instruction from IRAM at an address in which never contained an instruction to begin with. So I tried change the pin no. from DHTPIN 6 to DHTPIN 32 referred to website (← Sorry for referring to Japanese site).
Then the sensing succeeded!

But actually, I can’t understand the critical issue of this error. Oguri-san who is one of the member in Kamakura, check the operation with DHTPIN35 but somehow the error: “Failed to read from DHT sensor!“ occurred. So to understand this problem deeply, I think I need to understand the structure ESP32 as well as its pin assignment.

X. Conclusions


Submission

2. Project Management

Score (Max: 100)

  • Hierarchy: 100
    I planed to do from DC geared motor pump, DC motor pump, and Stepper motor.

  • Triage: None

  • Spiral Development: 100

  • Supply-side Time Management: None

  • Parallel Development: 50

  • Document as you work: 100

MEMO


What I wanted to learn more

  • Processing, p5.js

  • XR (VR, AR, MR)