MIT app inventor, Arduino and bluetooth

228 views
Skip to first unread message

courbe Louise

unread,
Apr 16, 2017, 7:16:58 AM4/16/17
to MIT App Inventor Forum
  Hello,
 
  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 ? 

thank you in advance, 

Louise Courbe   
Sans titre.tiff
Sans titre2.tiff

Neil Kenyon

unread,
Apr 16, 2017, 7:58:06 AM4/16/17
to MIT App Inventor Forum
Hi @Louise

I think the problem is in the way you are trying to read the data in your Arduino sketch.


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

Neil

courbe Louise

unread,
Apr 16, 2017, 12:06:26 PM4/16/17
to MIT App Inventor Forum
thanks for the help but it doesn't work... When I use pins D0 and D1 my Arduino receives nothing. 

Ghica

unread,
Apr 16, 2017, 2:10:48 PM4/16/17
to MIT App Inventor Forum
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.
https://groups.google.com/forum/m/#!category-topic/mitappinventortest/2cd6Uz__xA0
Cheers, Ghica

Juan Antonio

unread,
Apr 16, 2017, 3:28:48 PM4/16/17
to MIT App Inventor Forum
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);} 
}







courbe Louise

unread,
Apr 17, 2017, 4:18:23 AM4/17/17
to MIT App Inventor Forum
I have try but I have the same problem... 
Sans titre4.tiff

Ghica

unread,
Apr 17, 2017, 4:06:09 PM4/17/17
to MIT App Inventor Forum
Could you please post a screenshot directly? I cannot read your doc.
Cheers, Ghica

courbe Louise

unread,
Apr 19, 2017, 8:16:49 AM4/19/17
to MIT App Inventor Forum



Ghica

unread,
Apr 19, 2017, 12:07:40 PM4/19/17
to MIT App Inventor Forum
Hi Louise,
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.

Cheers, Ghica.

Ghica

unread,
Apr 19, 2017, 12:27:49 PM4/19/17
to MIT App Inventor Forum
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;
...

Cheers, Ghica.

courbe Louise

unread,
Apr 19, 2017, 4:59:44 PM4/19/17
to MIT App Inventor Forum
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. 
It is all my blocks, I hope it could help you. 

I have try to char my text but it's doesn't work. My arduino doesn't receive anything but he goes in my void loop 


thank you in advance 


Louise 



Ghica

unread,
Apr 20, 2017, 4:33:05 AM4/20/17
to MIT App Inventor Forum
Hi Louise,
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.
Cheers, Ghica.

courbe Louise

unread,
Apr 21, 2017, 4:21:26 PM4/21/17
to MIT App Inventor Forum
Thank you very much for your help!! 
I will try. And also thanks for the example code. 

Louise

Pierre TESSIER

unread,
Apr 23, 2017, 6:03:39 PM4/23/17
to MIT App Inventor Forum
Hi Louise,
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.
Pierre


Example arduino.doc
Reply all
Reply to author
Forward
0 new messages