I developed a small app that imports data from Arduinothrough bluetooth,
the part of Arduino is working.
When I install the application I have a problem:
After I choose the bluethoot module from the phone,
the application stops responding on a black screen....
I am attaching my screen of blocks,
Is anything wrong?
--
Here is something to try.
Perhaps have the Clock1.Timer Enabled to false initially in the Designer.
Below the BlueToothConnect.Address procedure you can enable the timer.
--
Before this project worked great,
Now it is not working on three different phones,
I have replaced the bluetooth module, Arduino twotimes,
because I thought that the problem was in this,
but then I tried it with a PC and it works Arduino,
everything hangs when I choose the phone the bluetoothmodule.
I attach the set clock of my program,
some idea?has anything changed in the app inventor ofbluetooth data management?
--
sometimes it helps to look around a little bit...
before using the ReceiveText block make sure, there is something to receive
--
Your timer settings seem pretty fast. How fast is the Arduino sending data? Indeed, if you get the next timer event before you are finished waiting for the previous one, the app will choke. It will help in any case to experiment with longer wait times of the clock.
If your message received from the Arduino is short, then Taifun's method will work. If you are receiving long messages, you must use the number of bytes to receive block, collect them in a global variable as buffer and check whether you found the end of message and only then dissect what you have.
--
I have done many tests,I write the results:A) Arduino UNO, HC-S04 sensor and bluetooth module are new and they work fine with the Serial Port of PC
B) I have always done more tests with the same simple sketc arduino, this:
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
int maximumRange = 200;
int minimumRange = 0;
long duration, distance;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(10);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration/58.2;
if (distance >= maximumRange || distance <= minimumRange){
Serial.println(" ");
}
else {
Serial.println(distance);
}
delay(100);
C) I have always used in the test, the clock setting the TimeInterval is 1000, with check of TimerAlwaysFires and TimerEnabled
D) I have set Bluetooth client in all tests as picture attached Bluetooth.pngTest 1 (blocks, picture Test 1.png)-Once You have selected the Bluetooth module is rare that continues;-The rare times (once out of 20 times) I had
1) turn off the phone
2) turn off Arduino
3) Turn off bluetooth- That one time worked, the numbers were not in real time, is blocked and then gave a series of about 10 seconds before numbers
Test 2 (blocks, picture Test 2.png)
- As soon as I open the application appears to me"Error 505: Not connected to a Bluetooth device"- I continue and I click on the bluetooth module is connected but no data appears(Immage attached Error.png)- It never stops, but never gives the data.What do you advise me to do?The part Arduino works, it would seem that app inventor(or I) has problem in connexin bluetooth data.Can you send some of your example?
--
Test 2 (blocks, picture Test 2.png)
- As soon as I open the application appears to me"Error 505: Not connected to a Bluetooth device"- As soon as I open the application appears to me"Error 505: Not connected to a Bluetooth device"
most probably, this is, because your clock is enabled from the beginning
you should disable your clock end enable it after the connection has been successful
Taifun
--
I have not selected Timer Enabled and active afterblutooth connection,
Now tests have improved. The phones now are connected to bluetooth modulebut there are no incoming data (numbers in centimetersfrom Arduino)
is just the Bluetooth setting which I am attaching?
What I can fix?
Someone can show an example .aia?
--
Thee are many examples of people successfully connection Arduino's to AI2 using Bluetooth, so somewhere there must be a bug in your setup.
What you can do to find out is to use another app like Ardudroid, to find out what your Arduino is really sending.
Also, show your relevant blocks as they are now, or attach an .aia
--
Something else: you assume that the text you receive will contain a ?
What if there is no ? I do not see it written in your sketch.
So, you will not see anything.
What you should do, is create a new label, called debugLabel or similar, and show all received text in it. You can see then what your Arduino sends and adapt your app as needed (or the sketch, if needed)
--
I tried to make a sketch for my Sparky robot car (which has also a proximity sensor), similar to yours. The main difference is that my sensor sends out integers instead of floating point numbers, but I think that this does not differ too much.
Here are my blocks:
This should work for you too. Because the Arduino is much faster than the AI App, you will usually get two values, which are displayed on two lines in the label. You could make the timer interval shorter, or you could chop the second value off (look at the text blocks, for example "split at", use /n as at value. You would get a list, of which take the first element and display that.
I made the text of the listpicker "connected" when the connection succeeds, that is nicer. Actually, you should have a disconnect button and disable the listpicker when connected.
--