A simple bluetooth remote controller for bluetooth car.
see app/release to download apk.
English translation is also available. This picture is in Chinese because the locale in my phone is set to Chinese.
The application has two big discs. Every time, the program read the x coordinate of the left disc and y coordinate of the right disc. Then concatenate them together, and send through bluetooth serial.
The message format looks like -23,45\r\n
. When controlling a car, you can convert it to the speed of two wheels simply.
If you are use Arduino, you can use this code to drive you bluetooth car:
void loop() {
if(Serial.available()) {
int x = Serial.parseInt();
int y = Serial.parseInt();
int left = x + y, right = y - x;
drive(left, right); // your car driving function
}
}
The command form, quantification, sending frequency, and control method can be customized is the Settings.
AT+CMODE=1 // enable connection by arbitrary device
AT+NAME=KEKE046 // set your bluetooth module name
AT+ROLE=0 // Android phone seems to be always Master Mode
AT+PSWD=123456 // set password
First pair with the Bluetooth module in the Android Bluetooth settings, and then connect in the software.
The L1, L2, R1, R2 buttons at the top can send predefined command conveniently. You can change the default command in the Settings.
Command generation is based on string format.
String cmd = String.format(format, x, y);
Special format may make programming quick:
"%+04d, %+04d"
completed the leading zeros, then you can use:100 * buf[0] + 10 * buf[1] + buf[2]
to convert string to integers.
"%2$d, %1$d"
can exchange x and y coordinate, sometimes helps.
"C%+04d%+04d"
can create a character 'C' in each coordinate message. You can distinguish coordinate message from other command easily.