Turning "Old" Arduinos into Perfectly Usable IoT Devices

Dual MCU communication with EasyTransfer

And some simple, unrefined, demo code running Blynk on a ESP8266 that is sending control signals to an Arduino that is running a stepper motor.


  • Code for ESP8266 - Running Blynk and sending control info to Arduino over Serial
#include <BlynkSimpleEsp8266.h>  // For Blynk
#include <ESP8266WiFi.h>  // For Blynk & OTA
#include <ESP8266mDNS.h>  // For OTA
#include <WiFiUdp.h>  // For OTA
#include <ArduinoOTA.h>  // For OTA
#include <EasyTransfer.h>  // For EasyTransfer

EasyTransfer ET;

// Put your variable definitions here for the data you want to send
// THIS MUST BE EXACTLY THE SAME ON THE ARDUINO
struct SEND_DATA_STRUCTURE {
  int16_t SRVOstep;
  int16_t SRVOspeed;
  int16_t SRVOdir;
  int16_t LED13;
};

SEND_DATA_STRUCTURE ETdata;

char auth[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
char server[] = "xxxxxxxxxx";
int port = 8080;

BlynkTimer timer;

void setup() {
  Serial.begin(9600);
  ET.begin(details(ETdata), &Serial);

  WiFi.begin(ssid, pass);
  Blynk.config(auth, server, port);
  Blynk.connect();

  timer.setInterval(1000L, UpTime);

// Not necessary when only sending Serial data, but required if also receiving it in order to pause it for OTA programming.
  ArduinoOTA.onStart([]() {
    Serial.end();  
  });

  ArduinoOTA.setHostname("D1 Mini - Arduino Serial Servo");  // For OTA
  ArduinoOTA.begin();  // For OTA
}  // END Setup Loop



void UpTime() {  
  Blynk.virtualWrite(V0, millis() / 1000);  // Display Widget - Uptime in seconds
}



BLYNK_WRITE(V1) {  // Button Widget - Toggle Stepper control method with Built in LED indicator
  ETdata.LED13 = param.asInt();  // Arduino LED
  digitalWrite(2, !param.asInt());  // Wemos LED
  ET.sendData();
}



BLYNK_WRITE(V2) {  // Button Widget -  Servo rotation direction
  ETdata.SRVOdir = param.asInt();
  ET.sendData();
}



BLYNK_WRITE(V3) {  // Stepper Widget -  Pre-set step amounts from Step Widget (-200 to 200 with STEP set to 50)
  ETdata.SRVOstep = param.asInt();
  ET.sendData();
}



BLYNK_WRITE(V4) {  //  Slider Widget - Servo Rotation speed from Slider Widget (Range 10-100)
  ETdata.SRVOspeed = param.asInt();
  ET.sendData();
}



void loop() {
  Blynk.run();
  timer.run();
  ArduinoOTA.handle();  // For OTA
}  // END Void loop
  • Code for Arduino, controlling Stepper Motor (via L293D - dual H-bridge controller chip) and receiving directions via Serial from Wemos
#include <SoftEasyTransfer.h>  // For EasyTransfer
#include <Stepper.h> // For Stepper

#define STEPS 200  // Number of steps required for full 360° rotation of the stepper I used (1.8° per step)
Stepper stepper(STEPS, 2, 3, 4, 5);  // Pins used for L293D chip channels
int StepDir = 0;

#include <SoftwareSerial.h>  // For Software Serial
SoftwareSerial ETSerial(7, 8);  //  RX, TX Pins used for Soft Serial on UNO

SoftEasyTransfer ET;

// Put your variable definitions here for the data you want to receive
// THIS MUST BE EXACTLY THE SAME ON THE ESP
struct RECEIVE_DATA_STRUCTURE {
  int16_t SRVOstep;
  int16_t SRVOspeed;
  int16_t SRVOdir;
  int16_t LED13;
};

RECEIVE_DATA_STRUCTURE ETdata;

void setup() {
  pinMode(13, OUTPUT);
  stepper.setSpeed(100);

  ETSerial.begin(9600);
  ET.begin(details(ETdata), &ETSerial);
}



void loop() {
  ET.receiveData();

  if (ETdata.LED13 == 1) {  // Control speed and direction from Slider Widget
    digitalWrite(13, HIGH);
    stepper.setSpeed(ETdata.SRVOspeed);
    stepper.step(ETdata.SRVOdir * 1);
  } else {  // Control step and direction from Step Widget
    digitalWrite(13, LOW);
    stepper.setSpeed(25);
    stepper.step(ETdata.SRVOstep);
    delay(2000);
  }
}
1 Like