1

I am trying to read data from a Blynk widget via ESP8266 and Arduino UNO and trying to send it to another slave Arduino UNO. But, the problem is the data is taking some time to reach to the slave Arduino for further processing and I need it to be fast as it is needed for controlling a drone.

If any one can help, please help. I am a tenth grader and a newbie. So, I don't have a lot of experience.

Here is the code for the master Arduino:

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>   //We are using software serial so as not to conflict with serial download and monitor

SoftwareSerial mySerial(5,6); // RX, TX

int of=0;
int throttle=0;

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "wifi_name";
char pass[] = "wifi_pass";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&Serial);
WidgetLED l(V3);

void setup()
{
 // Debug console
 Serial.begin(9600);
 delay(10);
 // Set ESP8266 baud rate
 Serial.begin(ESP8266_BAUD);
 delay(10);
 Blynk.begin(auth, wifi, ssid, pass);
 mySerial.begin(9600);
}

void loop()
{
 Blynk.run();
 l.on();
 mySerial.write(of);
 mySerial.write(throttle);
}

BLYNK_WRITE(V1)
{
  of = 100+param.asInt();
}

BLYNK_WRITE(V2)
{
  throttle = param.asInt();
}
timemage
  • 4,690
  • 1
  • 10
  • 24
coder-ari
  • 21
  • 1
  • 1
    how do you know that the bottleneck is the baud rate? ... the slave code could easily be running slow – jsotola Jan 16 '21 at 17:01
  • 1
    If the distance (wires) between the 2 processors is short enough, you might consider I2C or SPI. Also, for speed you should make sure you are using all the hardware support available and not emulating serial ports using software. If there are not enough hardware resources on the processors used on the Arduino boards you picked out - consider using a more capable processor on a different Arduino board. – st2000 Jan 16 '21 at 18:44
  • A *practical* answer to the maximum baud of `SoftwareSerial` is non-trivial and probably not as helpful to you as you might expect in solving the fundamental problem of getting information from Blynk through to whatever in your project actually needs that information timely. Typically in aerial (I presume) drone applications, people are concerned about weight as well. So, I'm curious: are all three of these things going to be mounted on the drone? (Why) do you need all three? – timemage Jan 17 '21 at 20:25
  • Yes all three are mounted on the drone... but i have quite powerful motors and 10*4.5 blades @timemage – coder-ari Jan 18 '21 at 09:00
  • @jsotola yeah that was the problem....thank you for ur help but now there is another problem it is tipping over :) – coder-ari Jan 18 '21 at 09:01
  • @st2000 i could not use spi because i could not understand how it works.... and i2c i did not use because already my arduino is communicating with the bmp via i2c i dont know if it supports two wires(Wire.h).... – coder-ari Jan 18 '21 at 09:03
  • I2C supports more than two devices on the same bus (same Wire instance) such that having multiple buses is often unnecessary. The case is similar with SPI except that multiple select lines are typically needed. When using an UNO as a slave, you may find I2C easier because it has a built-in flow control mechanism (clock stretching). – timemage Jan 18 '21 at 11:50

0 Answers0