Hi, the problem is it connects sometimes and sometimes just gives 908 error for fine location right after I open app and sometimes 507 error
I removed rest of the blocks and now I'm just trying to keep connection and send data over bt and it was successful (when it connects) I used teraterm to check if I'm actually sending data and I'm sending it but not expected values I tried decimal / number but I receive different things on TeraTerm for example for 250 value I get 4 of this character= ْ or for 10 it goes next line...
I just want to send a value 1-255 as 1byte
I tried on two device: android10 and 12
also I made list just in case if I need to add any other permissions I want to make this app work with older androids as well but don't know how .... developer.android says:
<For your legacy Bluetooth-related permission declarations, set android:maxSdkVersion
to 30
. This app compatibility step helps the system grant your app only the Bluetooth permissions that it needs when installed on devices that run Android 12 or higher>
not sure how I can do this on mit app inventor (is it even possible?)
Dear @saeed_badali,
as a general hint instead of sending bytes, try to use the Send Text block:
Then you can convert on the receiver device.
Please also bear in mind that decimal 10 (i.e. 0x0A) is the Line Feed character in the ASCII table, therefore it is correct that TeraTerm issues a newline in its terminal screen.
Please also be aware that TeraTerm always shows characters, unless you set it in "debug" mode by editing its teraterm.ini file.
Some hints here:
http://ttssh2.osdn.jp/manual/4/en/setup/teraterm-term.html
Cheers.
I have such a code on arduino
while (Serial.available() >= 2) {
x = Serial.read();
delay(10);
y = Serial.read();
}
delay(10);
// Convert back the 0 - 255 range to 0 - 1023, suitable for motor control code below
xAxis = x*4;
yAxis = y*4;
can you please explain more how should I change it? is there anyway to do this without change on arduino side?
This is slighly different to what you said in your previous post:
- your receiving device is then an Arduino: supposing fitted with a BT interface, like HC05 or HC06 or other BT shields or integrated stuff, but NOT BLE ?
- The Serial.available refers to the supposed BT communication line ?
- Never use the delay() function while using the Serial communication (in a lot of other posts in the Community is already stated). Use the millis() function instead, like the following
unsigned long timeout = mills(); // set the initial time
while ((millis()-timeout) < 10); // waits here untill 10 ms timeout is reached, but leaves the CPU free - your while shall be reversed in your code, or the flow should be changed as follows:
if(Serial.available() == 2)
{
unsigned long timeout = mills(); // set the initial time
x = Serial.read();
while ((millis()-timeout) < 1); // waits here untill 1 ms, but leaves the CPU free
y = Serial.Read();
// Convert back the 0 - 255 range to 0 - 1023, suitable for motor control code below
xAxis = 4 * x;
yAxis = 4 * y;
}
else
{
}
Anyway I suggest you to change the way you transmit from the App to the Arduino. In other words, you should send from the App more complete messages like:
"x=valuex" and "y=valuey" so the Arduino can fetch these messages and decode them knowing that in the message in which the header is "x=" you will be sure that the related valuex is effectively what you expect for the x axis . The same for the y axis. By relying only on the fact that the two bytes received are always in the correct order (i.e. valuex, first, and valuey, second) is highly risky. If, for some reason, the sequence is missed by Arduino, you will cross the x and y values and your control will crash.
Another hint is to take a look the web site of @Juan_Antonio ( http://kio4.com) or the web site of @ChrisWard ( https://www.professorcad.co.uk/). Both have written tons of Arduino code explaining in deep detail what to do to successfully make a BT communication (both standard and BLE) between AI2 and Arduino. I'm pretty sure that by using their examples you will succeed in making your system working.
I like the way you queue up the permission requests and ask for them one at a time.
Completion of the permission requests would be a good time to enable the Clock Timer, which should be left disabled in the Designer.
(Unless you want unauthorized BT requests)
1.yes I'm using hc-05
2.not sure I use codes from https://howtomechatronics.com/tutorials/arduino/arduino-robot-car-wireless-control-using-hc-05-bluetooth-nrf24l01-and-hc-12-transceiver-modules/
3.I will
4.I will try it
what about 908 ?
more complete messages like this?
Hello Saeed
We need to see the full picture in order to help you sort this out, given that you have more than one issue. I myself am not available today, but hopefully someone else has the time to look at your files.
-
What is the model name of your Arduino
-
What is the Make, Model, Android Version of your Smartphone
-
Upload your App Inventor Project file here
-
Upload your Sketch (.ino) here - we need to see the file
-
Take a photograph that clearly shows how the HC-05 is wired to the Arduino
While you are waiting for a response, have a large coffee and read my list of reasons why Bluetooth (Classic and BLE) can fail:
ProfessorCad: Tips & Tricks Bluetooth Tips
ProfessorCad: Tips & Tricks Bluetooth Failure
Dear @saeed_badali,
ok, so let's assume also that your HC05 is correctly connected to the Arduino CPU board.
For example, like here below (this is a NANO with a HC06, but it's just to show you the principle):
As per @Chris question, please post your Arduino code, because there are some doubts that have to be clarified before (i,.e. which serial line is used for the BT and which one, if any, for the Serial Monitor).
What is 908 ?
Complete message: yes, by sending "x" and "y" lets your Arduino code to know without risk of error which axis shall be driven.
In attachment you can find the Arduino chunk of code that does the message receiver and parser.
Please give it a look (i've tested it on a UNO). It does not feature timeouts yet, but it can give you an idea. It can be tested alone with the serial monitor instead of a BT.
Best wishes.
receive_and_compose.ino (5.1 KB)
EDIT:
looking to the site you posted, now it's clear why the receiving code was (in my previous interpretation) reversed.
In the original Arduino code, the robot is waiting for characters and , when it has received some of them, it starts to fetch them, one at a time, and the serial.read() is decreasing the serial.available() by one each time. So when the number of bytes contained into the receiving buffer becomes less than 2 (i.e.=1), it stops reading. this approach, though probably working, has two cons.
First: it remains in the buffer always one byte, and this means that a couple of X&Y remains always splitted. This can cause a mis-alignment in the motor driving, since at time Tn it always uses X(Tn-1) and Y(Tn) and so on.
Second: if for some reason Arduino synchronizes itself with a Y-X-Y sequence, instead of a X-Y-X sequence, the two axes are crossed, and it will never recover.
As @ChrisWard said: a strong (italian ) coffe is now required...
Thanks a lot @Chris,
Sometimes (to be read: very often ) my eyes can't see farer than my nose...
is arduino model relevant if I get 908 error ?
I'm using arduino nano
I tried two android device: honor 8x(android 10) tab s6 lite (android 13) and can use older ones too (like android 4.0)
btdata.aia (242.1 KB)
this is what I have but no resistors (hc-05+nano rx to rx tx to tx ) my hc-05 says 3.3v-6v so I skipped resistors atleast for now
ino file
hc-05.ino (2.2 KB)
I'm currently working on parser (I'm really lost)
to parse strings like x123y231 x28y95 .... which in ino file I recieve them as t on serial.read
what I'm trying to make is based on bellow link he didn't use any parser or send data as text but my code is just getting more and more complicated with suggestions..... I will understand it less and less it seems... don't know how he sends number and get number on other side with no problem
howtomechatronics.com
his aia file doesnt exist in his site (wrong link) otherwise I would gladly use it
funny thing is when I use mit companion app it gives no 908 error and it even asks for permision but when I build and install apk it gives 908
Dear @saeed_badali,
I hope is only a typo but you shall connect Tx to Rx and not Tx to Tx between Nano and HC.
Please verify.
Cheers.
PS there is a really huge quantitty of tutorials on @Juan_Antonio's web site regarding how to send commands to Arduino from AI2. please give it a look and do a step-by-step approach, by starting from the very basic simple communication between phone and Arduino, then when you're done with that, you can add the motor driving.:
http://kio4.com/appinventor/9A1_bluetooth_appinventor_basico2.htm
Although they are in spanish, I believe you can easily understand them because they are plenty of images.
Cheers.
EDIT: ...sorry !!! I didn't want to drop you into troubles with the parser algorithm..... As I said, I tested it, so it works, but once you will got familiar with @Juan_Antonio tutorials maybe you will not need the parser and you will use your algorithm instead.
May the force be with you
EDIT again: I had a look to the ino file you posted. Honestly it is really far from a working condition: for example the receiviing section overwrites always the same variable "t" so how the motors can be driven ? For this reason I said above to become familiar with the mentioned tutorials, before trying a more difficult code.
It wasn't a type and I'm happy u noticed it maybe it was the problem all this time. I will test it tomorrow and it may just fix it
about variable t it was x and y before I change it I just changed it so I can use it to generate x y from it after I add parser to it .... it was like bellow
while (Serial.available() >= 2) {
x = Serial.read();
delay(10);
y = Serial.read();
}
ok then cross your fingers about the wires
It's relevant to the Android version of your Smartphone.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.