Hello,
my current project is to build a robot that I can controll via the Blynk app.
Therefore I bought an "WeMOS Mega + WiFi R3 ATmega2560 + ESP8266"-board
(WeMOS Mega + WiFi R3 ATmega2560 + ESP8266 USB-TTL Arduino Mega NodeMCU US | eBay)
Setting up the Blynk app and reading the data with the onboard-ESP8266 was no issue.
But transfering the data to the Mega is a huge problem.
I never used serial communication between two boards. In my opinion the problem is somewhere on the Mega-side as I can read the data sent by the esp8266 with the serial monitor in the Arduino IDE.
I want to send the X and Y values of the joystick in the blynk app (and later on some other values).
Right now I'm testing if the mega recieves the data with two LEDs.
Could someone please have a look on my codes?
On the ESP side:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <SPI.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "TOKEN";
char ssid[] = "SSID";
char pass[] = "PASSWORT";
String ESP2Arduino;
int x=0; //Ausgelesener x-Wert von Joystick
int y=0; //Ausgelesener y-Wert von Joystick
int maeh=0;
//Joystick X-Achse auslesen
BLYNK_WRITE(V0) {
x = param[0].asInt();
}
//Joystick Y-Achse auslesen
BLYNK_WRITE(V1) {
y = param[0].asInt();
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
send2Arduino();
}
void send2Arduino()
{
ESP2Arduino = ESP2Arduino + x + "," + y + "," + maeh;
Serial.println(ESP2Arduino);
delay(10);
ESP2Arduino= "";
}
On the Mega side:
#include <SoftwareSerial.h>
#include <Adafruit_GFX.h> // Include core graphics library for the display
#include <Adafruit_SSD1306.h> // Include Adafruit_SSD1306 library to drive the display
int Variable1;
Adafruit_SSD1306 display(128, 64); // Create display
String FromESP;
int SteuerX=0;
int SteuerY=0;
int Maehwerk=0;
int empfangen=0;
int led_pinblau=2; //PWM pin 2 for testing
int led_pingruen=3; //PWM pin 3 for testing
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
delay(100); // This delay is needed to let the display to initialize
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize display with the I2C address of 0x3C
display.clearDisplay(); // Clear the buffer
display.setTextColor(WHITE); // Set color of the text
display.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
// To override this behavior (so text will run off the right side of the display - useful for
// scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
// with setTextWrap(true).
pinMode(led_pinblau, OUTPUT);
pinMode(led_pingruen, OUTPUT);
}
void loop() {
//testing if data recieved
analogWrite(led_pinblau,SteuerX);
analogWrite(led_pingruen,SteuerY);
display.clearDisplay(); // Clear the display so we can refresh
// Print text:
display.setCursor(0, 10); // (x,y)
display.println(FromESP); // Text or value to print
display.println("Test"); // Text or value to print
display.display(); // Print everything we set previously
}
void ReadFromESP(){
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int SteuerX = Serial.parseInt();
// do it again:
int SteuerY = Serial.parseInt();
// do it again:
int Maehwerk = Serial.parseInt();
}
}
I am very grateful for any advise/ help.
Thanks, Max