Hello there,
A friend and I are working on a project that involved using W-A-S-D keys on a computer transmitted through an ESP32 wifi module to an Arduino UNO and FunduMoto Keyes L298P motor shield that in turn control two LEGO servo motors to pilot a LEGO rover. We have been able to create a web server via HTML that transmits succesfully from the computer to the ESP32 via WiFi. However, we have trouble when it comes to ESP32 to Arduino Motor Shield transmission. We connected ESP TX to Arduino RX and ESP RX to Arduino TX, along with GND to GND. Power is being supplied by a 9V battery with adapter connected to the motor shield. However, while we are receiving indication of signal sent on the ESP, the lights indicating motor signals arent indicating any response on the Arduino motor shield. Some help would be appreciated if possible.
The code below is for the Arduino. Our original program (which I won't send here because it contains WiFi and IP information) sends info to the ESP directing it to release a serial signal of a letter that should be picked up by the motor shield.
Arduino code below:
#include <SoftwareSerial.h>
const int LMotorPwr = 10;
const int LMotorDir = 12;
const int RMotorPwr = 11;
const int RMotorDir = 13;
SoftwareSerial espSerial(2, 3); // RX, TX
void setup() {
pinMode(LMotorPwr, OUTPUT);
pinMode(LMotorDir, OUTPUT);
pinMode(RMotorPwr, OUTPUT);
pinMode(RMotorDir, OUTPUT);
Serial.begin(9600); // initialize serial communication with computer
espSerial.begin(9600); // initialize serial communication with ESP32
}
void loop() {
if (espSerial.available() > 0) { // if there is incoming data from ESP32
char command = espSerial.read(); // read the incoming command
if (command == 'f') { // if the command is 'f', move motors forward
digitalWrite(LMotorPwr, HIGH);
digitalWrite(RMotorPwr, HIGH);
digitalWrite(LMotorDir, HIGH);
digitalWrite(RMotorDir, LOW);
}
else if (command == 's') { // if the command is 's', stop motors
digitalWrite(LMotorPwr, LOW);
digitalWrite(LMotorDir, LOW);
digitalWrite(RMotorPwr, LOW);
digitalWrite(RMotorDir, LOW);
}
else if (command == 'b') { // if the command is 'b', move motors backward
digitalWrite(LMotorPwr, HIGH);
digitalWrite(RMotorPwr, HIGH);
digitalWrite(LMotorDir, LOW);
digitalWrite(RMotorDir, HIGH);
}
}
if (Serial.available() > 0) { // if there is incoming data from computer
char command = Serial.read(); // read the incoming command
espSerial.write(command); // send the command to ESP32
}
}