App Inventor issue receiving data from arduino nano through bluetooth

224 views
Skip to first unread message

Julio

unread,
Sep 10, 2016, 5:17:34 PM9/10/16
to MIT App Inventor Forum
I am creating a thermostat application , it will send to arduino nano the desired temperature (selected from slider) , turn on/off through 2 buttons) and receive every 1 second from arduino the status ( runing,off or off) and the meassured temperature.
Actually I tried to receive a fixed string sent by Arduino but it is receiving bad , example I sent from arduino "Hello" and at a text label a seeing "H" and after "ello".
If I change the IntervalTimer at clock event iI can see "elloH" or "elloHello" or any combination of that but never the correct word.
the arduino script is very simple:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 5); // RX, TX

void setup()
{
   // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() // run over and over
{
    mySerial.write("Hello");
    delay(1000);
}

I`ll appreciate any help!!
Regards
Julio
RX_data_from_nano.png

Abraham Getzler

unread,
Sep 10, 2016, 6:15:30 PM9/10/16
to MIT App Inventor Forum
On the Arduino side, println() works better than write() for sending delimited text messages.
It adds a LF (decimal 10 line feed) to the end of the message, that can be specified in the AI2 BT client  designer Delimiter attribute = 10.

When you  have btresAvailable > 0 and are connected,
specifying a byte count of -1 in the BT Read Text block will give a full line of text.

text ReceiveText(number numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.


ABG 

Julio

unread,
Sep 10, 2016, 11:36:46 PM9/10/16
to MIT App Inventor Forum
thanks a lot, now is working!!.
Regards
Julio
Reply all
Reply to author
Forward
0 new messages