I have established a connexion between my app inventor and my arduino thanks to a bluetooth. But I have a problem. I send a number or a letter to my bluetooth but when I received my letter with my arduino I have the number 255. I have 254 when I put a negativ number. I have try to sand the number with 2 different way. The first one was : call bluetoothClient1.Send text and the second one : call BluetoothClient1.SendByteNumber.
Could you please help me ?
I think the problem is in the way you are trying to read the data in your Arduino sketch.
Have a look at my blog post here: https://www.element14.com/community/people/neilk/blog/2014/09/05/app-inventor-bluetooth-and-arduino-part-3-android-slider-controls-led-brightness
The main difference is that I connect the HC06 Bluetooth device to the Arduino using pins D0 and D1, so it effectively across the Serial Monitor.
The slider reading ends up as an unsigned 1 byte number - maximum value 255.
I hope this helps
thanks for the help but it doesn't work... When I use pins D0 and D1 my Arduino receives nothing.
--
Your problem suggests that your sketch is not right. There are other kinds of read like readInt etc.
please look at the FAQ in the Arduino and Bluetooth section for inspiration on how to do this. Q&A for Arduino and Bluetooth
--
please look at the FAQ in the Arduino and Bluetooth section for inspiration on how to do this. Q&A for Arduino and Bluetooth
--
Hi, try with text...
--
-------------------------------------------
// Juan Antonio Villalpando
// KIO4.COM
char val;
int LED0 = 0; //
int LED2 = 2; //
void setup() {
Serial.begin(9600); // Aqui establecemos la velocidad
pinMode(LED0, OUTPUT); //
pinMode(LED2, OUTPUT); //
}
void loop() {
if( Serial.available() )
val = Serial.read();
if( val == '0' ){ digitalWrite(LED0, LOW);}
if( val == '1' ){ digitalWrite(LED0, HIGH);}
if( val == '2' ){ digitalWrite(LED2, LOW);}
if( val == '3' ){ digitalWrite(LED2, HIGH);}
}
Could you please post a screenshot directly? I cannot read your doc.
--
--
There are 3 things you can do:
1. Download some BT app that allows you to send direct commands, and see what you have to send to make it work.
2. Tell us more about your connection and device. What Arduino board do you have, and what BT-shield
3. Show all your blocks, also the ones that establish the connection.
1. Download some BT app that allows you to send direct commands, and see what you have to send to make it work.
2. Tell us more about your connection and device. What Arduino board do you have, and what BT-shield
3. Show all your blocks, also the ones that establish the connection.
--
You said you were recieving values, but they were not the right ones. Therefore it may be as simple as casting your text to char, as I found in my own little robot sketch:
void loop()
{
//Receives commands from remote computer:
if (serial.available())
{
int inByte = serial.read();
serial.println((char)inByte);
switch ((char)inByte)
{
//Actions:
case 'f':
sparki.moveForward();
break;
case 'r':
sparki.moveRight();
break;
...
void loop()
{
//Receives commands from remote computer:
if (serial.available())
{
int inByte = serial.read();
serial.println((char)inByte);
switch ((char)inByte)
{
//Actions:
case 'f':
sparki.moveForward();
break;
case 'r':
sparki.moveRight();
break;
...
--
thank you for your help. My Arduino is a Arduino UNO and my BT-shield is from Sparkun and it is the model BlueSMiRF. I have check all my connection.
--
Your App Inventor code should work, therefor I think this is not the right forum to get help for your problem.
Just a few things though:
1. Before you send something to the Arduino, it is good to test if your Arduino is still connected and only send if true, but display an error if false.
2. In your sketch it strikes me as odd that you try to have two serial connections active, Serial and bluetooth. Then you try to read from the bluetooth connection, but maybe that is not the one which is active and I really doubt that this Smirf thing would allow you to have two connections.
I also Googled around a bit for you and found this thread, that maube can help you further. It has a link to example code that you may look at:
https://forum.arduino.cc/index.php?topic=62759.0
As a last resort, use a HC-05 or HC-06, I think they are much cheaper and a lot more people use it, it seems.
Just a few things though:
1. Before you send something to the Arduino, it is good to test if your Arduino is still connected and only send if true, but display an error if false.
2. In your sketch it strikes me as odd that you try to have two serial connections active, Serial and bluetooth. Then you try to read from the bluetooth connection, but maybe that is not the one which is active and I really doubt that this Smirf thing would allow you to have two connections.
I also Googled around a bit for you and found this thread, that maube can help you further. It has a link to example code that you may look at:
https://forum.arduino.cc/index.php?topic=62759.0
As a last resort, use a HC-05 or HC-06, I think they are much cheaper and a lot more people use it, it seems.
--
Thank you very much for your help!!
--
I will try. And also thanks for the example code.
I think it is necessary to use seral monitor from sketch arduino to see what is happening on arduino. You code one or many "Serial.print(data...);" to see if data ok before or after an action on arduino.
But the problem with UNO is that you have only one serial and if you use it with BT it's not possible to see serial monitor .
The solution, i think, for you is to buy an arduino MEGA (not expensive) because it has serial 0 (like uno) that you reserve for monitoring.
And, particularly, it has three additional serials (serial 1,2 and 3). So you can see what is happening on basic serial and you connect your BT on serial1.
I use an HC 06 like Ghica recommended you.
I join you an example to see what i mean.
String stringOne,
stringTwo, stringThree;
//Initialisation des E/S et communication
void setup() {
Serial.begin(9600); //vitesse de transmission
Serial1.begin(9600); // liaison BT vers
android
pinMode(LED_PIN13,OUTPUT)
;
pinMode(LED_PIN8,OUTPUT)
;
pinMode(LED_PIN9,OUTPUT)
;
stringOne =
String("You added ");
stringTwo =
String("this string");
stringThree =
String();
//setupmyBlueToothConnection(); // appel de la
fonction de configuration du module bluetooth si nécessaire
}
void loop() {
recevoir1();
// 1x = SMS pour carte BT // 2x = SMS pour carte Hangar // 3x = SMS pour carte DOMO
if
(w==11) { reponse=11;
delay (100); envoyer1();
digitalWrite(LED_PIN8,HIGH);
}
else {
digitalWrite(LED_PIN8,LOW); }
if
(w==12) { reponse=12; delay (100); envoyer1();
digitalWrite(LED_PIN9,HIGH);
}
if
(w==13) { reponse=13; delay (100); envoyer1(); digitalWrite(LED_PIN8,HIGH); }
stringOne =
"Sensor value: ";
stringTwo = " ";
//stringThree = stringOne + t1 + stringTwo + t2 + stringTwo + t3 +
stringTwo + t4;
}
//voids reception pour serial 1 2 et 3 de la
carte BT
void
recevoir1(){ if (Serial1.available()) { w=
Serial1.read(); Serial.print("recevoir1:"); Serial.println(w);
Serial1.flush(); } }
//voids envoi pour serial 1 2 et 3 de la carte
BT
void
envoyer1() { Serial1.print(stringThree);
Serial.print("envoi 1:"); Serial.println(stringThree); Serial1.flush(); }
void
setupmyBlueToothConnection() { // configuration du module bluetooth
Serial.begin(9600);
// set BluetoothBee BaudRate to default baud rate 38400
Serial.print("∖r∖n+STWMOD=0∖r∖n");
// set the bluetooth work in slave mode
Serial.print("∖r∖n+STNA=BTSlave_1∖r∖n");
// set the bluetooth name as "BTSlave_1"
Serial.print("∖r∖n+STOAUT=1∖r∖n");
// permit Paired device to connect me
Serial.print("∖r∖n+STAUTO=0∖r∖n");
// auto-connection should be forbidden here
delay(2000);
// this delay is required.
Serial.print("∖r∖n+INQ=1∖r∖n");
// make the slave bluetooth inquirable
Serial.println("Le module bluetooth est
interrogeable!"); // affichage dans le moniteur série
delay(2000);
// this delay is required.
Serial.flush();
}
//The end
--
댓글 없음:
댓글 쓰기