Good morning!
I’ve gotten this to work:
I got the TFT display to work with the Mega chip, but I haven’t found a library that supports TFT AND has examples that work.
To upload to the 8266, set switches 5,6,7 to ‘on’.
But to USE it, switch 7 back off.
One of the switch settings connects the 8266 with the Mega by COM3. Another setting says “Mega2560 + 8266”.
Since I already have the TFT working with the Mega, I’d like to stick with that. But I don’t know what writing has to be done to adapt.
I haven’t used an ESP peripheral, only ESP development boards.
I haven’t seen ESP Now work on an 8266 yet.
I uploaded this program to the 8266 chip on the Mega. Serial speed is correct, but I only get a short plug of serial gibberish- it’s very short until you switch 7. But then the gibberish plug just gets a little bit longer.
I’ve been using the ESP 32 with much gratification, but I want the Mega8266 for the receiver- with the TFT display.
Since this Mega8266 hasn’t cooperated much at all (won’t respond to MAC address request, etc.), I uploaded the script to a WeMos 8266.
The gibberish persists.
I can’t see anything that looks amiss in the program. Can you tell me why this script has a cross-platfom problem squirting out serial output?
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp-now-esp8266-nodemcu-arduino-ide/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <espnow.h>
// Structure example to receive data
// Must match the sender structure
typedef struct struct_message
{
int id;
float temperature;
float humidity;
float pressure;
float VOC;
float LPG;
float CO;
float NH3;
float NO2;
float TVOC;
float rawH2;
float rawEthanol;
float eCO2;
unsigned int readingId;
} struct_message;
// Create a struct_message called myData
struct_message myData;
// Callback function that will be executed when data is received
void OnDataRecv(uint8_t *mac, uint8_t *incomingData, uint8_t len)
{
memcpy(&myData, incomingData, sizeof(myData));
Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
Serial.printf("temperature: %4.2f \n", myData.temperature);
Serial.printf("humidity: %4.2f \n", myData.humidity);
Serial.printf("pressure: %4.2f \n", myData.pressure);
Serial.printf("VOC: %4.2f \n", myData.VOC);
Serial.printf("TVOC: %4.2f \n", myData.TVOC);
Serial.printf("LPG: %4.2f \n", myData.LPG);
Serial.printf("CO: %4.2f \n", myData.CO);
Serial.printf("eCO2: %4.2f \n", myData.eCO2);
Serial.printf("nh3: %4.2f \n", myData.NH3);
Serial.printf("no2: %4.2f \n", myData.NO2);
Serial.printf("readingID: %d \n", myData.readingId);
Serial.println();
}
void setup()
{
// Initialize Serial Monitor
Serial.begin(9600);
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
// Init ESP-NOW
if (esp_now_init() != 0)
{
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
esp_now_register_recv_cb(OnDataRecv);
}
void loop()
{
}
By the way, ESP Now is the poop. Do it. Do the poop.