ESP8266, UART to send data

Hi guys !

I hope I can find some answers here.

In my project, I would like to communicate between arduino (uno or mega) and computer via wifi.
The arduino will sense different parameters (several integers e.g. "255 1024 328“, send via UART (or an other way) to an esp8266 which will transfer to a computer (with maxmsp) through an existing wifi network. Besides, I would like to be able from my computer to send to arduino information, still using esp8266 as gateway (I already have a working patch on maxmsp).

Firstly, I tried with i2c between arduino and esp but no luck, maybe because of interrupt pin needed for i2c and which interferes with the wifi timing. So I was thinking about UART.

Secondly, I have to use tcp procole instead of UDP.

And finally, I would avoid using anyhting else than Arduino IDE, unless there is a really stable way to
realise the project.

Is there someone who has already done that ?

Thanks in advance,

Chris

You have two choices basically:

  1. ESP8266 core for the Arduino and download it to the ESP8266
  2. use the default firmware that comes standard with most ESP8266 modules

Do you have a code ?

You are suppose to come up with the code.

You could use a simple software serial protocol to communicate between the two.

I have done this before.. having the ESP serving up a 'web page' that has some links/buttons on it..

when clicked (submitted) I parse the posted data (command sent).. and pass this over to my connected Pro-Micro..

my Pro-Micro reads this serial data/command and behaves accordingly (as an HID device connected to a PC)..

so not exactly the same as your projects.. but serial communication between the two is possible and easy to do.

Hi,

Yeah I have a code.
Here it is. If anybody has suggestions to improve it, I would be really happy !
Specially, I don't know exactly how to use flush, yield, setting the esp8266 speed, signal power,

I'm encountering some lags when I use it. The reception stops for half second sometimes.
Besides, the signal slow down randomly and I don't know why !

NB:
The general idea is to sense physical interaction with the uno, send collected data via UART to ESP8266 which will transfer over an existing WIFI router to computer (running MaxMSP for example).

The specifications would be:

  • Use of esp8266-12
  • Use TCP protocol (to make sure that the transferred data is consistent)
  • Go as fast as possible (I'm struggling using UART faster than 9600 bauds)
  • Robust set up (it has to run for month without any reset because it will be in remote area)

So to make sure before introducing sensing in my project, I'm only generating a signal from 0 to 1024 with arduino Uno and sending these integers over UART and then wifi.

I visualise on computer the signal (triangle waves). So I notice when signal goes slower by wider triangles.
And finally, I visualize signal interruptions with the button in MaxMSP which turns off when no signal is received.

Signal visualisation on MaxMSP:

MaxMSP visualisation
=> We can see on this figure that the second triangle slowed down a bit at the beginning. The more I let the set up running, the worst it is in term of signal speed.

Arduino Uno side :

//   ARD UNO        ESP8266
//         D10 <-> TX                         // Unhook before upload sketch
//         D11 <-> RX                         // Unhook before upload sketch
//         GND <-> GND

#include <SoftwareSerial.h>
#define     RXpin      10                     // MOD
#define     TXpin      11                     // MOD
String      UARTsendData;                     // AUTO

SoftwareSerial espSerial(RXpin, TXpin);

void setup() { // -----------------------------------------------------------------------
  Serial.begin(57600);                        // For com with computer
  espSerial.begin(9600);                      // For com with ESP
}

void loop() { // ------------------------------------------------------------------------
  // Generating a triangle wave forms
  for (int i = 0; i < 1024; i++) {         
    UARTsendData = i;                     
    UARTsend();                            
  }                                        
  for (int i = 1023; i > 0; i--) {          
    UARTsendData = i;                   
    UARTsend();                           
  }                                     
}

void UARTsend() { // --------------------------------------------------------------------
  espSerial.print(UARTsendData);
  espSerial.println("F");
}

ESP side:

//   ARD UNO        ESP8266
//         D10 <-> TX                         // Unhook before upload sketch
//         D11 <-> RX                         // Unhook before upload sketch
//         GND <-> GND

#include <ESP8266WiFi.h>
#define   RcvCount 10
#define   Tempo    1

const char*       ssid             = "Z3K";                      // MOD
const char*       pwd              = "pwd";                      // MOD
const char*       hostIP           = "192.168.43.220";           // MOD
const int         sendPort         = 8889;                       // MOD
const int         recvPort         = 8890;                       // MOD

String            UARTrcvData;                            // AUTO
char              UARTrcvBuffer;                          // AUTO
int               UARTrcvCount;                           // AUTO

String            WIFIsendData;                           // AUTO
String            WIFIrcvData;                            // AUTO
char              WIFIrcvBuffer;                          // AUTO
int               WIFIrcvCount;                           // AUTO

WiFiServer server(recvPort);
WiFiClient client;

void setup() { // -----------------------------------------------------------------------
  Serial.begin(9600);                         // For com with ARD
  WIFIconnect();
  WIFIserverConnect();
  server.begin();
  client.setNoDelay(1);
  Serial.println("\nInitialized");
}

void loop() { // -----------------------------------------------------------------------
    UARTreceive();                        
    WIFIsendData = UARTrcvData;          
    WIFIsend();                         
    WIFIreceive();                       
}

void WIFIconnect() { // ----------------------------------------------------------------
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pwd);

  while (WiFi.status() != WL_CONNECTED) {
    delay(Tempo);
  }
}

void WIFIserverConnect() { // ----------------------------------------------------------
  if (!client.connect(hostIP, sendPort)) {
  }
}

void WIFIreceive() { // ----------------------------------------------------------------
  WIFIrcvCount = 0;
  WIFIrcvBuffer = 'N';
  WIFIrcvData = "";

  WiFiClient client = server.available();

  if (client.connected()) {
    while (WIFIrcvBuffer != 'F' && WIFIrcvCount < RcvCount) {
      WIFIrcvBuffer = client.read();
      if (WIFIrcvBuffer != 'F') {
        WIFIrcvData += WIFIrcvBuffer;
        WIFIrcvCount++;
      }
    }
    if (debug == true) {
      Serial.println(WIFIrcvData);
    }
  }

  client.flush();
}

void WIFIsend() { // -------------------------------------------------------------------
  if (WiFi.status() != WL_CONNECTED) {
    WIFIconnect();
  }

  client.flush();

  if (client.connected()) {
    client.println(WIFIsendData);
  }
}

void UARTreceive() { // ----------------------------------------------------------------
  UARTrcvCount = 0;
  UARTrcvBuffer == 'N';
  UARTrcvData = "";

  while (UARTrcvBuffer != 'F' && UARTrcvCount < RcvCount) {
    while (Serial.available() > 0) {
      UARTrcvCount = UARTrcvCount + 1;
      UARTrcvBuffer = (char)Serial.read();
      if (UARTrcvBuffer != 'F') {
        UARTrcvData += UARTrcvBuffer;
      }
    }
  }
}

Nobody for a little help ?

I am unfamiliar with MaxMsp. You may want to see if there is someone else who is using it.

I am thinking you need to scale back.
Perhaps being able to implement the following will help you.
Newbies have a tending to have grand schemes when small steps are more helpful.Arduino & ESP8266 Webserver | Martyn Currey