Sending data from Arduino Uno to Built-In ESP8266 Module

I'm using UNO+WiFi R3 ATmega328P+ESP8266, 32Mb flash, USB-TTL CH340G, Micro-USB chip to do some project of mine. So the chip I have is already have ESP8266 module connected to the Arduino Uno chip. My problem is how can I transfer data between both of them? For ex. I have an input from Arduino Uno and I want to send that input to my server using ESP8266 (from Arduino Uno to ESP8266). Another example is I have received data that I fetched from the internet using ESP8266 and I want to process the data and show the final result using my Arduino Uno (from ESP8266 to Arduino Uno). How can I achieve those? Thanks in advance.

Posting a schematic not a frizzy picture would help. You have some things connected together but with my eyes I see nothing. A hand drawn sketch would work. Be sure to show all power and ground connections. Also post links with technical information on each of the hardware devices, azon, and others only give sales information. Note any distances over about 10".

@gilshultz , what are you talking about? it is one board with ATmega and esp8266 on-board. and there is no picture in the post.

If you have an esp8266, why do you need the UNO?
The esp has far more capabilities, (other than pins and 5v capability) resources, and speed than the UNO.

--- bill

Sorry for the lack of information, I will give the information now:
Wifi code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

int scaleResult;

// WiFi CREDENTIALS
const char *ssid = "Moe_Family's";
const char *password = "Blessed Family";
const char *serverName = "http://68.183.228.158/scales/receive-result";

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");
  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}


void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("From ESP Connected!");
    WiFiClient wifiClient;
    HTTPClient httpClient;

    Serial.write("100.00");
    scaleResult = Serial.read();
    Serial.println(scaleResult);

//    if (Serial.available())
//    {
////      scaleResult = Serial.read();
//      scaleResult = 100;
//      Serial.println("Serial available!");
//    }
//    else
//    {
//      scaleResult = 0;
//      Serial.println("Serial not available!");
//    }

    // check if scale result is indeed received
    // if received, send the data
    // else ignore
    if (scaleResult > 0)
    {
      httpClient.begin(wifiClient, serverName);
  
      httpClient.addHeader("Content-Type", "application/json");
      httpClient.addHeader("Scale-MAC-Address", "EC:FA:BC:19:6D:D0");
      String data = String("{\"scale_result\":");
      data.concat(String(scaleResult));
      data.concat("}");
      int resCode = httpClient.POST(data);
  
      Serial.println("Res Code: ");
      Serial.println(resCode);
  
      httpClient.end();

      scaleResult = 0;
    }
  }
  delay(1000);
}

Arduino Code:


#include "HX711.h"

HX711 scale(3, 2);

float calibration_factor = 1000; // this calibration factor is adjusted according to my load cell
float units;
float ounces;
float avgUnits;
int finalUnits;
int count;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor");
  Serial.println("Press - or z to decrease calibration factor");

  scale.set_scale();
  scale.tare();  //Reset the scale to 0
}

void loop() {
  // put your main code here, to run repeatedly:

  scale.set_scale(calibration_factor); //Adjust to this calibration factor

  units = scale.get_units(), 1;
  if (units < 0)
  {
    units = 0.00;
    avgUnits = 0.00;
    count = 0;
  }
  // reset scale to 0 because of error number
  if (units <= 50.00)
  {
    scale.tare ();
    avgUnits = 0.00;
    count = 0;
  } 
  else
  {
    // wait for 3 second to get the average scale result
    delay(1000);
    count++;
    avgUnits += units;
  }

  // save the average final result
  if (count == 3)
  {
    finalUnits = round(avgUnits/count);
    Serial.print("Reading: ");
    Serial.print(finalUnits);
    Serial.print(" gram");
  }
  Serial.print(" calibration_factor: ");
  Serial.print(calibration_factor);
  Serial.println();
  delay(1000);

  if(Serial.available())
  {
    char temp = Serial.read();
    if(temp == '+' || temp == 'a')
      calibration_factor += 50;
    else if(temp == '-' || temp == 'z')
      calibration_factor -= 50;

    // send the data here to ESP8266 when serial is available
    Serial.write(finalUnits);
  }
}

Also, the ESP and Arduino is built-in.

"ESP8266" can mean many things. ESP8266 is that microcontroller proper, but it's also come to mean an ESP01 or a NodeMCU, or even an ESP8266-based board that follows the UNO form-factor (and others).

OP specified the board exactly:

Major thread on using that unit
https://forum.arduino.cc/t/robotdyn-atmega328-uno-r3-wifi-how-to-use-it/567092

Yep.

Seems to be pretty much represent the worst of both worlds! :dizzy_face:

wow. I had no idea that the board description in the original post was an actual board vs multiple individual boards interconnected.
Just me, but I don't see the value of a board like that.
If a UNO form factor is desired, there are ESP based boards for that with either ESP8266 or ESP32.
And once you are using an ESP part, why would you want to hamper it with an AVR?
i.e. just do everything on the more powerful ESP part.

--- bill

But not much use at all. The "WeMOS D1 R3" sticks an ESP-12 or similar in a UNO-like board, but not all the digital pins connect - or are multiple pins for each I/O on the ESP, and there is only one analog pin, and the pins are of course 3.3 V logic only.

A waste of a board. :roll_eyes:

What I have done for now, which still does not work, is:
Arduino code:


#include "HX711.h"
#include <ArduinoJson.h>

HX711 scale(3, 2);

float calibration_factor = 1000; // this calibration factor is adjusted according to my load cell
float units;
float ounces;
float avgUnits;
int finalUnits;
int count;

void setup() {  
  Serial.begin(115200);

  scale.set_scale();
  scale.tare();  //Reset the scale to 0
}

void loop() {
  // put your main code here, to run repeatedly:

  scale.set_scale(calibration_factor); //Adjust to this calibration factor

  units = scale.get_units(), 1;
  if (units < 0)
  {
    units = 0.00;
    avgUnits = 0.00;
    count = 0;
  }
  // reset scale to 0 because of error number
  if (units <= 50.00)
  {
    scale.tare ();
    avgUnits = 0.00;
    count = 0;
  } 
  else
  {
    // wait for 3 second to get the average scale result
    delay(1000);
    count++;
    avgUnits += units;
  }

  // save the average final result
  if (count == 3)
  {
    finalUnits = round(avgUnits/count);

    // send the data here to ESP8266 when serial is available
    DynamicJsonBuffer jbuffer;
    JsonObject& root = jbuffer.createObject();
    root["result"] = String(finalUnits);
    root.printTo(Serial);
    Serial.println();
  }
  delay(1000);
}

ESP code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ArduinoJson.h>

const char* scaleResult;

// WiFi CREDENTIALS
const char *ssid = "Moe_Family's";
const char *password = "Blessed Family";
const char *serverName = "http://68.183.228.158/scales/receive-result";

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
}


void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    WiFiClient wifiClient;
    HTTPClient httpClient;
    
    bool StringReady;
    String json;
    DynamicJsonBuffer jbuffer;
    JsonObject& root = jbuffer.createObject();

    // DEBUGGING CODE
//    root["result"] = "100.89";
//    root.printTo(Serial);
//    Serial.println();
    // END DEBUGGING CODE
    
    json = Serial.readString();
    StringReady = true;
    if (StringReady){
      StaticJsonBuffer<200> jsonBuffer;
      JsonObject& root = jsonBuffer.parseObject(json);
    }

    scaleResult = root["result"];

    // check if scale result is indeed received
    // if received, send the data
    // else ignore
    if (scaleResult > 0)
    {
      httpClient.begin(wifiClient, serverName);
  
      httpClient.addHeader("Content-Type", "application/json");
      httpClient.addHeader("Scale-MAC-Address", "EC:FA:BC:19:6D:D0");
      String data = String("{\"scale_result\":");
      data.concat(String(scaleResult));
      data.concat("}");
      int resCode = httpClient.POST(data);
  
      httpClient.end();

      scaleResult = 0;
    }
  }
  delay(1000);
}

So what I'm trying to do here is to try to send the data through Serial. When the scale result is received, Arduino will print the result as a JSON format to the Serial on 115200 baud rate, which is the same as ESP's baud rate. Then ESP will read its data printed earlier and send the data to my backend server. I have switched the 1,2,3,4 dips on and Arduino is indeed printing the scale result, however, I did not see my ESP sending the data to the backend server. I also did a debugging session alone on the ESP module and added a debugging code there. When the debugging code is included, the ESP did send the data to the backend server. Can someone help me debug it? I have searched some solutions like using AltSoftSerial to connect both module's serials, but ESP is not compatible for that library.

I have this same board running Tasmota in the ESP8266.
I am trying to transfer some data from my OpenEnergy Monitor shield in Arduino directly to ESP8266.
Now I am able to send Serial.print from Arduino to ESP8266 and receive in Tasmota a single line with Arduino´s data, but this is not enough to solve my problem.
Is there any way to bypass data read in Arduino GPIO direct to ESP8266 GPIO? Or even redirect from Ardunio´s GPIOX to ESP8266´s GPIOY?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.