8:40 am

November 4, 2020

greetings'
I am making a project where i read temperature sensor data using an Arduino Uno and i send these readings to the esp8266 nodemcu using software serial. I am able to send the data successfully from the Uno to thew nodemcu but when I try to upload the data to ThinigSpeak the data received data is completely incorrect.
please have a look at my codes and advice .
UNO CODE
________________
#include
#include
#include
#include
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
SoftwareSerial SUART(2, 3); //SRX=Dpin-2; STX-DPin-3
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup(void)
{
// start serial port
Serial.begin(115200);
SUART.begin(115200); //enable SUART Port
//Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Temp:");
lcd.begin(16,1);
}
void loop(void)
{
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperature readings
Serial.println("DONE");
Serial.print("Temperature is: ");
Serial.println(sensors.getTempCByIndex(0));
float temperature = sensors.getTempCByIndex(0);
SUART.println(temperature); //sends the data using software serial
lcd.setCursor(0,1); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Temp: "); // Prints string "Distance" on the LCD
lcd.print(sensors.getTempCByIndex(0)); // Prints the distance value from the sensor
lcd.print(char(223));
lcd.print(" C");
delay(1000);
}
___________________________________________
NODEMCU CODE
_______________________________________________
#include
SoftwareSerial SUART(4, 5); //SRX=Dpin-D2; STX-DPin-D1
#include
//#include
#include
WiFiClient client;
#include "ESP8266WiFi.h"
char ssid[]= "WiFIName";
char password[]="PASS";
int status = WL_IDLE_STATUS;
unsigned long myChannelNum = ************ ; // channel num from ThinSpeak
const char *myWriteAPIKey = "************" ; // API key from ThingSpeak
void setup()
{
Serial.begin(115200); //enable Serial Monitor
SUART.begin(115200); //enable SUART Port
WiFi.begin(ssid,password);
ThingSpeak.begin(client);
}
void loop()
{
byte n = SUART.available(); //n != 0 means a character has arrived
if (n != 0)
{
char x = SUART.read(); //read character
char y = SUART.write(x);
Serial.print(y); //show character on Serial Monitor
delay(1000);
ThingSpeak.setField(1,y);
ThingSpeak.writeFields(myChannelNum, myWriteAPIKey);
}
}
8:30 am


Moderators
March 7, 2017

Do you have a paid license? The 1 second delay on your node MCU is a bit fast. But you are only sending 1 character. I would wait and save a bunch of characters
Also it seems strange to write the character right back to the SUART right after you receive it.
I would directly program the node MCU to send the data to ThingSpeak, skipping the Uno. Have a look at the examples.
FYI, MATLAB answers is the preferred location for ThingSpeak Community support.
Most Users Ever Online: 166
Currently Online:
30 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
Advantagetreeexperts, laundrydaddyuk, techhhelp5, ken, tran, huldacormierModerators: cstapels: 460
Administrators: Hans: 405, lee: 457