No serial comms from integrated ESP8266 to Arduino

Hi all,

I am setting up a “Duinotech” Uno clone with an integrated ESP8266 module to perform IOT data logging. I have the Arduino side of the board printing sensor data to the serial bus, the idea being the ESP8266 will collect the messages, perform some logic and send them on to ThingSpeak.

All aspects of the project appear to be working, with the exception of the serial comms between the two modules. While connected to the Arduino, I can see my messages being displayed in the serial monitor. When I switch to the ESP8266, the only messages I see are those generated by the ESP code itself. The result is the program never entering the while(Serial.available()) loop, and the sensor values never being updated.

Any assistance gratefully accepted!

TLDR: The Arduino chip on my “Duinotech” Uno+WiFi clone sends messages to the serial bus fine, but the ESP8266 does not receive them.

Arduino side code:

#include "ThingSpeak.h"
#include "secrets.h"
#include <ESP8266WiFi.h>

char ssid[] = SECRET_SSID;   // your network SSID (name) 
char pass[] = SECRET_PASS;   // your network password
int keyIndex = 0;            // your network key Index number (needed only for WEP)
WiFiClient  client;

unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;

// Initialize our values
int number1 = 0;
int number2 = 0;
int number3 = 0;
int number4 = 0;
String myStatus = "";
String receivedCommand = "";
bool dataIn = false;

void setup() {
  Serial.begin(115200);  // Initialise serial

  WiFi.mode(WIFI_STA); 
  ThingSpeak.begin(client);  // Initialise ThingSpeak
}

void loop() {

  // Connect or reconnect to WiFi
  if(WiFi.status() != WL_CONNECTED){
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(SECRET_SSID);
    while(WiFi.status() != WL_CONNECTED){
      WiFi.begin(ssid, pass);  // Connect to WPA/WPA2 network. Change this line if using open or WEP network
      Serial.print(".");
      delay(5000);     
    } 
    Serial.println("\nConnected.");
  }

  while (Serial.available()) {
    char c = Serial.read(); //read serial bus for sensor info from arduino
    Serial.print("HELLO");
    if (c = '[') { //start of sensor value
      receivedCommand = "";
      dataIn = true;
    } else if (dataIn && c != ']') { //still reading sensor value
      receivedCommand += c;
    } else if (dataIn && c == ']') { //end of sensor value, time to process it
      Serial.print("Received: ");
      Serial.println(receivedCommand);
      if (receivedCommand.startsWith("1")) { //indicating temp sensor 1
        receivedCommand.remove(0,1);
        number1 = receivedCommand.toFloat();
      } else if (receivedCommand.startsWith("2")) { //indicating temp sensor 2
        receivedCommand.remove(0,1);
        number2 = receivedCommand.toFloat();
      } else if (receivedCommand.startsWith("3")) { //indicating temp sensor 3
        receivedCommand.remove(0,1);
        number3 = receivedCommand.toFloat();
      } else { //indicating temp sensor 4
        receivedCommand.remove(0,1);
        number4 = receivedCommand.toFloat();
      }
    }
  }

  // set the fields with the values
  ThingSpeak.setField(1, number1);
  ThingSpeak.setField(2, number2);
  ThingSpeak.setField(3, number3);
  ThingSpeak.setField(4, number4);
  //Serial.println(number1);
  //Serial.println(number2);
  //Serial.println(number3);
  //Serial.println(number4);
  
  // write to the ThingSpeak channel
  int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  if(x == 200){
    Serial.println("Channel update successful.");
  }
  else{
    Serial.println("Problem updating channel. HTTP error code " + String(x));
  }  
  delay(20000); // Wait 20 seconds to update the channel again
}

ESP8266 code:

//Data logger: GPS and 4 channel temp data logger.
//Written by Nick de Wit, 2/11/2020

//Libraries

//IO pins
#define tempPin0 A0
#define tempPin1 A1
#define tempPin2 A2
#define tempPin3 A3

//Global variables
float Vo;
float T;
float Ro;
float R;
float B;
float To;
float T0;
float T1;
float T2;
float T3;

void setup() {
  
  Serial.begin(115200);
  analogReference(EXTERNAL);  //ref voltage is physically wired to 3.3V

  pinMode (tempPin0, INPUT);
  pinMode (tempPin1, INPUT);
  pinMode (tempPin2, INPUT);
  pinMode (tempPin3, INPUT);

  //Initialisations
  Ro = 100000;
  B = 4400.0;
  To = 298.15;

}

void loop() {
  
  T0 = getTemp(tempPin0);
  T1 = getTemp(tempPin1);
  T2 = getTemp(tempPin2);
  T3 = getTemp(tempPin3);

  Serial.print("Temp 1: ");
  Serial.print("[1");
  Serial.print(T0);
  Serial.println("]");
  
  Serial.print("Temp 2: ");
  Serial.print("[2");
  Serial.print(T1);
  Serial.println("]");
  
  Serial.print("Temp 3: ");
  Serial.print("[3");
  Serial.print(T2);
  Serial.println("]");
  
  Serial.print("Temp 4: ");
  Serial.print("[4");
  Serial.print(T3);
  Serial.println("]");

  for (int i = 0; i < 9; i++) {
    Serial.println(" ");
  }
  
  delay(15000);
}

float getTemp(int pinNo) {

  Vo = 0;                               //read analog pin voltage and average
  T  = 0;
  for (int i = 0; i < 60; i++) {
    Vo += analogRead(pinNo);
  }
  Vo /= 60;

  R = Ro / ((1023.0 / Vo) - 1.0);       //calculate resistance of thermistor

  T = R / Ro;                           //convert resistance to temperature
  T = log(T);
  T /= B;
  T += 1.0 / To;
  T = 1.0 / T;
  T -= 273.15;
  
  //T = T - 273.15;

  if (T > -50 && T < 200) {             //if temp reading is within sensible range
    T = T;                            //output to display variable
  } else {
    T = 0;                            //avoid garbage readout
  }
  return T;
}

Just guessing

I’m not familiar with Uno+WiFi in a single module (and I don’t plan to explore any of those beasts, this is just calling for trouble, why not just use an ESP directly!) but if this is a regular uno type architecture then there is only one serial port for the uno.

If it’s connected somehow to the serial input of the ESP part, then you probably can’t have the uno speak to the ESP and at the same time with the Serial monitor.

My advice: ditch that thing and go for an ESP alone. One throat to choke, no finger pointing between two processor and whatever half baked communication layer has been developed between the two.