Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 9 months ago.
bluetooth in frdm kl25z
Hi, I'm doing a controlled bluetooth in kl25z platform car, in my Android application, I say that whenever rotate clockwise send a letter r, it is assumed that the letter r is received by the microcontroller, so you know you have turn right, but I can not read do to make the r read that kl25z receiving bluetooth, does anyone know I have to do ?, thanks for the help. i'm using bluetooth hc-08
hola, estoy haciendo un carro controlado por bluetooth en la plataforma kl25z, en mi aplicacion de android, le digo que cuando quiera girar hacia la derecha envia una letra r, se supone que esta letra r la recibe el microcontrolador, para que sepa que tiene que girar hacia la derecha, pero no logro leer hacer para que el kl25z lea esa r que recibe del bluetooth, ¿alguien sabe que tengo que hacer?, gracias por la ayuda. uso el bluetooth hc-06
this is the code
car with bluetooth
#include "mbed.h" PwmOut motor1a(D7); PwmOut motor1b(D6); PwmOut motor2a(D5); PwmOut motor2b(D4); Serial blue(D0,D1); int vel=255; //ENGINE SPEED int main() { char estado='f'; blue.baud(9600); if(blue.readable()>0) { estado=blue.read(); //<- HOW TO READ THE CHARACTER THAT SENT WITH THE APPLICATION if(estado=='s') { // Go straight motor1b.write(0); motor2b.write(0); motor1a.write(vel); motor2a.write(vel); } if(estado=='i') { // TURN LEFT motor1b.write(0); motor2b.write(0); motor1a.write(0); motor2a.write(vel); } if(estado=='d') { // STOP motor1b.write(0); motor2b.write(0); motor1a.write(0); motor2a.write(0); } if(estado=='r') { // TURN RIGHT motor1b.write(0); motor2b.write(0); motor1a.write(vel); motor2a.write(0); } if(estado=='b') { // BACK motor1a.write(0); motor2a.write(0); motor1b.write(vel); motor2b.write(vel); } if (estado =='o') { // ON REMOTE SENSING } if (estado=='f') { // OFF REMOTE SENSING } } }
1 Answer
9 years, 9 months ago.
Buenas Andrés,
1 - Did you forget the while(1) loop in your code?
2 - If you transmit specific byte is better to use getc() function instead of read().
3 - Try with other UART port for the bluetooth connection (One that is not used for the USB port). Check D14 & D15.
Code:
#include "mbed.h" PwmOut motor1a(D7); PwmOut motor1b(D6); PwmOut motor2a(D5); PwmOut motor2b(D4); Serial blue(D14,D15); int vel=255; //ENGINE SPEED int main() { char estado='f'; blue.baud(9600); while(1){ if(blue.readable()>0) { estado=blue.getc(); //<- HOW TO READ THE CHARACTER THAT SENT WITH THE APPLICATION if(estado=='s') { // Go straight motor1b.write(0); motor2b.write(0); motor1a.write(vel); motor2a.write(vel); } if(estado=='i') { // TURN LEFT motor1b.write(0); motor2b.write(0); motor1a.write(0); motor2a.write(vel); } if(estado=='d') { // STOP motor1b.write(0); motor2b.write(0); motor1a.write(0); motor2a.write(0); } if(estado=='r') { // TURN RIGHT motor1b.write(0); motor2b.write(0); motor1a.write(vel); motor2a.write(0); } if(estado=='b') { // BACK motor1a.write(0); motor2a.write(0); motor1b.write(vel); motor2b.write(vel); } if (estado =='o') { // ON REMOTE SENSING } if (estado=='f') { // OFF REMOTE SENSING } } } }