I am using 4 motors and L298N with Vietduino Esp32 to control. I use lipo battery to power L298N. Esp32 is used to connect to the network and is controlled via the network on the phone. But when I connect, I cannot control the motor. I need it urgently, please help me.
English is not my native language so I have some mistakes in communication, I hope you will forgive me
This is code!
#define DEFAULT_MQTT_HOST "mqtt1.eoh.io"
// You should get Auth Token in the ERa App or ERa Dashboard
#define ERA_AUTH_TOKEN "f76f573b-54b5-4412-b02c-78c5d6beea5b"
#include <Arduino.h>
#include <ERa.hpp>
#include <ERa/ERaTimer.hpp>
const char ssid[] = "Brian";
const char pass[] = "12092010";
ERaTimer timer; // setup timer
ERA_WRITE(V0){
int value = param.getInt();
if(value){
digitalWrite(2, 1);
digitalWrite(13,0);
digitalWrite(5, 0);
digitalWrite(23, 1);
}else{
digitalWrite(2, 0);
digitalWrite(13,0);
digitalWrite(5, 0);
digitalWrite(23, 0);
}
}
ERA_WRITE(V1){
int value = param.getInt();
if(value){
digitalWrite(2, 0);
digitalWrite(13,1);
digitalWrite(5, 1);
digitalWrite(23, 0);
}else{
digitalWrite(2, 0);
digitalWrite(13,0);
digitalWrite(5, 0);
digitalWrite(23, 0);
}
}
ERA_WRITE(V2){
int value = param.getInt();
if(value){
digitalWrite(2, 0);
digitalWrite(13,1);
digitalWrite(5, 0);
digitalWrite(23, 1);
}else{
digitalWrite(2, 0);
digitalWrite(13,0);
digitalWrite(5, 0);
digitalWrite(23, 0);
}
}
ERA_WRITE(V3){
int value = param.getInt();
if(value){
digitalWrite(2, 1);
digitalWrite(13,0);
digitalWrite(5, 1);
digitalWrite(23, 0);
}else{
digitalWrite(2, 0);
digitalWrite(13,0);
digitalWrite(5, 0);
digitalWrite(23, 0);
}
}
/* This function print uptime every second */
void timerEvent() { //Khai báo hàm timer set thời gian cập nhật dữ liệu lên sever
ERA_LOG("Timer", "Uptime: %d", ERaMillis() / 1000L);
}
void setup() { //setup mạch
/* Setup debug console */
Serial.begin(115200); //Mở Serial monitor với baud rate là 115200
ERa.begin(ssid, pass); //setup mạng cho mạch esp32
pinMode(2, OUTPUT);
pinMode(13,OUTPUT);
pinMode(5, OUTPUT);
pinMode(23, OUTPUT);
/* Setup timer called function every second */
timer.setInterval(1000L, timerEvent);
}
void loop() { //Vòng lặp liên tục
ERa.run();//khởi chạy Era
timer.run();//khởi chạy timer
}