Good afternoon, I have a cart project controlled by cell phone and via wifi network.
Originally it was a project via bluetooth network, but I made changes to make it via wifi network.
Date: "???????" On the serial monitor when trying to move the cart with the app controllers.
I try to make sure that by clicking on the arrows in the application, the cart will move accordingly.
Physical board: Wemos D1 R2 Wifi Esp8266 Esp12 board
Arduino specified board: LOLIN (WEMOS) D1 R2 & mini.
Card Manager: http://arduino.esp8266.com/stable/package_esp8266com_index.json
Code:
int led = D3; //led
int outPin1 = D4; //motor1
int outPin2 = D5; //motor1
int outPin4 = D6; //motor2
int outPin3 = D7; //motor2
char bt = 0; //BT
/*------------------------------------------------------------------------------*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
String command; //String to store app command state.
int speedCar = 800; // 400 - 1023.
int speed_Coeff = 3;
const char* ssid = "Autobots";
const char* password = "12345678";
ESP8266WebServer server(80);
/*------------------------------------------------------------------------------*/
void setup()
{
Serial.begin(9600);
pinMode(outPin1,OUTPUT);
pinMode(outPin2,OUTPUT);
pinMode(outPin3,OUTPUT);
pinMode(outPin4,OUTPUT);
pinMode(led,OUTPUT);
Serial.begin(115200);
// Connecting WiFi
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
// Starting WEB-server
server.on ( "/", HTTP_handleRoot );
server.onNotFound ( HTTP_handleRoot );
server.begin();
}
void loop()
{
server.handleClient();
command = server.arg("State");
if (Serial.available() > 0)
{
bt = Serial.read();
digitalWrite(led, 1);
/*________________________________________________________________________*/
if(bt == 'F') //move forwards
{
digitalWrite(outPin1,HIGH);
digitalWrite(outPin2,LOW);
digitalWrite(outPin3,HIGH);
digitalWrite(outPin4,LOW);
}
else if (bt == 'B') //move backwards
{
digitalWrite(outPin1,LOW);
digitalWrite(outPin2,HIGH);
digitalWrite(outPin3,LOW);
digitalWrite(outPin4,HIGH);
}
else if (bt == 'S') //stop!!
{
digitalWrite(outPin1,LOW);
digitalWrite(outPin2,LOW);
digitalWrite(outPin3,LOW);
digitalWrite(outPin4,LOW);
}
else if (bt == 'R') //right
{
digitalWrite(outPin1,HIGH);
digitalWrite(outPin2,LOW);
digitalWrite(outPin3,LOW);
digitalWrite(outPin4,LOW);
}
else if (bt == 'L') //left
{
digitalWrite(outPin1,LOW);
digitalWrite(outPin2,LOW);
digitalWrite(outPin3,HIGH);
digitalWrite(outPin4,LOW);
}
else if (bt == 'I') //forward right
{
digitalWrite(outPin1,HIGH);
digitalWrite(outPin2,LOW);
digitalWrite(outPin3,LOW);
digitalWrite(outPin4,HIGH);
}
else if (bt == 'G') //forward left
{
digitalWrite(outPin1,LOW);
digitalWrite(outPin2,HIGH);
digitalWrite(outPin3,HIGH);
digitalWrite(outPin4,LOW);
}
}
}
void HTTP_handleRoot(void) {
if( server.hasArg("State") ){
Serial.println(server.arg("State"));
}
server.send ( 200, "text/html", "" );
delay(1);
}
What I've already tried:
Specify the NodeMCU 1.0 board (ESP-12E Module) on the arduino, but in this way the wifi network was not generated.
I thought it was a bluetooth conflict so I removed it but it didn't show any changes.
Important:
I patched the wifi code into the cart drive code.
Wifi code taken from the website and app: 11 Simple Steps to Make WiFi car Using NodeMCU
Cart code, a friend gave me, I didn't remove anything from his code and he doesn't know what the problem is either.
