Hi! This is my first post ,so I want to apologise in advance for any mistakes I might make. Thx!
I have a rover project that is based on an ESP8266 (a NodeMCU version). It also has a motor driver and other stuff,but I dont think that's too relevant.
I want to create or use an open-source app for windows that can communicate with the ESP via wifi (the laptop will give hotspot to the esp,so I guess its a LAN). A latency as low as possible is desired,of course! By using the WASD keys,I'd like to see the motors spin. And,obviously,I will add other controls,sensor feeds,etc.
Currently,I am using Blynk with my phone,it only has a joystick for now.
Here is my code,it might useful:
//Blynk stuff:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "baf980ee09964cfd8b2a7a3679d05adb";
char ssid[] = "AndroidAP";
char pass[] = "Password";
#define enA D3
#define in1 D4
#define in2 D5
#define in3 D6
#define in4 D7
#define enB D8
int x=0,y=0;
int motorSpeedA=0,motorSpeedB=0;
int maxSpeed=1023;
void setup() {
Blynk.begin(auth, ssid, pass);
pinMode(enA,OUTPUT);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
pinMode(enB,OUTPUT);
}
void loop() {
Blynk.run();
if ( ! Blynk.connected() )
{
analogWrite(enA, 0);
analogWrite(enB, 0);
}
getSpeeds();
}
BLYNK_WRITE(V0)
{
x = param.asInt();
}
BLYNK_WRITE(V1)
{
y = param.asInt();
}
void getSpeeds(){
if (y < 0) {
// Inapoi
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
motorSpeedA = y * -1;
}
else if (y > 0) {
// Inainte
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
motorSpeedA = y;
}
// Poz centrala
else {
motorSpeedA = 0;
}
// Stanga-dreapta
if (x < 0) {
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
motorSpeedB = x * -1;
}
else if (x > 0) {
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
motorSpeedB = x;
}
else {
motorSpeedB = 0;
}
motorSpeedA=map(motorSpeedA,0,1023,0,maxSpeed); //putem seta o maxima
motorSpeedB=map(motorSpeedB,0,1023,0,maxSpeed);
//Evitam stutter inutil
if (motorSpeedA < 400) {
motorSpeedA = 0;
}
if (motorSpeedB < 200) {
motorSpeedB = 0;
}
analogWrite(enA, motorSpeedA); // Send PWM signal
analogWrite(enB, motorSpeedB);
}
As a final note,basically the app must send some values for the x and y variables. My commentary is in Romanian,sorry. xD Thank you!