Pages: [1]   Go Down
Author Topic: MIT app inventor and Arduino  (Read 1302 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im working on a project for myself that will allow me to change some variables stored on an arduino through bluetooth and my andoid phone.  I have the arduino side working perfectly when I use the app BlueTerm on my phone.  I can connect over bluetooth and send a string such as <3,200> and my arduino code looks for a start of frame "<" and end of frame ">" and split the data up into 2 variables.  Now onto the issue...

Im using MIT app inventor to create a custom app to send the data to my arduino, I have bluetooth also working with app inventor for the most part but im having trouble sending the data in the proper format.  I only have a couple options in the MIT software as to how I send the data, I can "SendText" or I can "Send1ByteNumber"

The closest I have gotten to having this work is by using the following code:

Code:
BluetoothClient1.SendText(<)
BluetoothClient1.Send1ByteNumber(3)
BluetoothClient1.SendText(,)
BluetoothClient1.SendSend1ByteNumber(200)
BluetoothClient1.SendText(>)

On the Arduino side my code recognizes the <, > and , but not the numbers.  This is what I am getting in the SerialMonitor

Code:
à,È

Im pretty sure this is just an issue with the numbers being sent in one format and recived / processed in another but I have no idea where to go from here. 
Logged

Offline Offline
Edison Member
*
Karma: 31
Posts: 1417
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Send1ByteNumber is probably sending the binary value which isn't what you want.
Since you can already send a string such as "<3,200>", all you need is BluetoothClient1.SendText(<3,200>)

Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Should have mentioned that in my first post...I have tried SendText(<2,300>)

The code on my arduino does not even see the start of frame "<" or end of frame ">" when I send data like that from the MIT app inventor
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the Arduino code that I put together with a couple guys on this forum that works with Blueterm but not MIT app inventor.

Code:

#define SOP '<'            //packet markers for bluetooth comms
#define EOP '>'

while(bluetooth.available() > 0)           
  {
    char inChar = bluetooth.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }

  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet
    Serial.println(inData);
    bluetooth.println(inData);
   
    char *token = strtok(inData, ",");      //proccess inData into variables
    if(token)
    {
      command = atoi(token);
      token = strtok(NULL, ",");
    }
    if(token)
    {
      value1 = atoi(token);
    }
  }
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is getting to the Arduino? If it is not recognizable data, then the if conditions will never be true. Print each character that arrives. Is it what you expect?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

starting from scratch with a blank sketch using following code
Code:
while(bluetooth.available() > 0)
  {
    Serial.println(bluetooth.read());
  }

And the following command in App Inventor
Code:
BluetoothClient1.SendText(<3,200>)

Displays this in the serial monitor
Code:
60
38
73
130
193
249
255

60 is ascii for < but the rest is garbage to me.

I get a better response sending data like this
 
Code:
BluetoothClient1.SendText(<)
BluetoothClient1.Send1ByteNumber(3)
BluetoothClient1.SendText(,)
BluetoothClient1.SendSend1ByteNumber(200)
BluetoothClient1.SendText(>)

Serial monitor
Code:
60
224
44
200
62

60, 44, and 62 are the < , and > characters but  the 224 is throwing me off.  Most of the time the serial monitor will display the 2nd number correctly but not always and more often the first number changes.  just changed my App Inventor code to send 10 and 2 and got two different outputs from the serial monitor.
Code:
60
133
44
2
62

60
133
44
129
62

The only setup options I have for the bluetooth in App inventor is "Character Encoding" and "DelimiterByte" those are set to UTF-8 and 0

Im thinking I need to drop this App Inventor stuff and just learn the android SDK w/ eclipse
Logged

Pages: [1]   Go Up
Jump to: