Hi,
I've been working on an android controlled robot car. And been trying to get a joystick control to work.
My hardware used will be found at the bottom if needed.
But I'm having trouble to get a steady and working connection with android app joystick and arduino. I've been using wifi with passing simple http requests on other projects. And got it to sort of work with this. But both the arduino and the app crashes after a moment. I think the arduino can't keep up with the rate the app sends data. Where we come to the app intentor delay. Or another way to send the commands a little bit less frequently. To allow both sides to have time to handle every packet in time. Tried to add a delay into the 'when joystick .dragged' -event but didn't seem to do anything. Like this:
Is this the correct way to do this? Seemed to work when I tested it with a button. Found several different ways but this looked like the latest one. What I would like is to have a slower rate to send the data to the arduino. Even if the joystick is moved fast.
On the arduino side I read the data and pass it to serial monitor for troubleshooting for now. Like this:
void loop() {
server.handleClient();
delay(10); // tried changing this to different values and without
}
void HTTP_handleRoot(void) {
if( server.hasArg("X") ){
char commandx100 = server.arg("X")[0];
char commandx10 = server.arg("X")[1];
char commandx1 = server.arg("X")[2];
int x100 = commandx100 -'0';
int x10 = commandx10 -'0';
int x1 = commandx1 -'0';
int x = x100*100 + x10*10 + x1;
Serial.println(x);
}
if( server.hasArg("Y") ){
char commandy100 = server.arg("Y")[0];
char commandy10 = server.arg("Y")[1];
char commandy1 = server.arg("Y")[2];
int y100 = commandy100 -'0';
int y10 = commandy10 -'0';
int y1 = commandy1 -'0';
int y = y100*100 + y10*10 + y1;
Serial.println(y);
}
server.send ( 200, "text/html", "" );
}
This setup works for about half a minute and then the app inventor will start saying its not receiving feedback for the requests its sending. And also the arduino sometimes stopped.
Also played a bit with bluetooth and found an app by someone. In his version he is using a bluetooth module with arduino and passing x and y coordinates one after another with nothing to indicate which is which. But I couldn't get the arduino to keep track on which coordinate was which. Also have only 1 bluetooth capable arduino so would rather use wifi. But if theres a good bluetooth solution would be helpful also. This is what the bluetooth app side looked like. I think this is pretty much what I found on another project, but couldn't get it to work properly.

On arduino I tried reading the data as was done in the project I borrowed the app setup from. With changing the read formats to whats used on the board I use.
- // Code from the Arduino Robot Car
- // Read the incoming data from the Joystick, or the master Bluetooth device
- while (Serial.available() >= 2) {
- x = Serial.read();
- delay(10);
- y = Serial.read();
- }
To basically this:
if (ESP_BT.available()) //Check if we receive anything from Bluetooth
{
x = ESP_BT.read();
delay(10);
y = ESP_BT.read();
}
This pretty much crashed both the arduino and the app after a moment.
The car itself is built out of legos to allow nephew and niece to build stuff on it. And maybe later add some other robotic parts. Steering is done by a servo. And two motors running the back wheels controlled by a L298 board.
Any help with the app inventor coding would be much appreciated (if there's a way to reduce the rate at which the data is sent). Or a better way to communicate with the two devices.
Sorry for the long post. Don't have a picture of a potato right now. :(
-Otto