MIT App Inventor and Arduino Part 2 - send data from Arduino to Android and display
I found numerous links via Google for this example; unfortunately a lot of them were the same tutorial posted in different places by the same person. None of them included the Arduino sketch! However, the sketch tuned out to be entirely trivial
I won't bother giving any of the links, because the the whole thing is unbelievably simple!
Here is the Design screen for the App:
The screen is very similar to the previous app, except the On and Off buttons are replaced by 2 Labels: Label2 has the default text of "Data from Arduino" and Label3 is given the default text of "0", in Red with a larger font.
As in the previous App, there is a Bluetooth Client and we also need to add a Clock component to act as a timer. These are both non-visible on the display and are shown below the bottom of the Android device screen.
In the Blocks screen we retain the 2 Blocks relating to selecting and connecting to Bluetooth and the Block responsible for disconnecting from Bluetooth. We dispense with the Button Blocks.
We then add the following new Block to receive and display the data:
In the Design screen, I left the default timer interval on the Clock at 1000mS because we want to have time to actually read the Android display.
The Arduino Sketch turned out to be very simple:
/* Demonstration sketch to send data to an Android App via Bluetooth - essentially simple; this is just serial output of integer data.
The Bluetooth module is connected across the Arduino Rx and Tx lines as before.
A 10k pot is connected across +5v and ground; the slider is connected to analog input 0, to supply varying data.
15 July 2014
int potPin = 0; // Define the Analog input
int value = analogRead(potPin); // read the value of the Analog Input
Serial.println(value); // Print the value; can also be seen on Serial Monitor
delay(1000); // Don't send too fast or the Android buffer will flood - this worked for me
This seems to work well enough to demonstrate the ease with which we can send data from the Arduino to the Android App.
Edited on 10 August 2015........problems can arise if the Arduino Transmission and Android Receive delay times are set identically. This wasn't a problem for my set up, but seems to be for others. If you leave the Arduino delay at 1000mS, then reduce the clock/timer delay in App Inventor to 950mS, it should be good
There are two attachments; the second one - Data_from_Arduino_A.zip does some extra error checking which some Android devices seem to need more than others.