In my project of an MIT/Arduino photo Focus Stacking machine, I need to enter a motor step value.
I then chose in MIT a "text box" to manually write what I need.
I managed to do what I want.
However, in testing, when I write/delete/rewrite several times quickly, I sometimes get unwanted values.
For example at some point I will write "975" , and the value received in Arduino serial monitor is 875... (afterwards when I type another value, it returns to normal.)
At another point, I will write for example "653", and the received value is "6A3" (or sometimes with weird sign).
What do you think?
I'm quite a beginner. There is probably some information missing, don't hesitate to ask me.
I post pictures of information that seems useful to me.
So you are sending numbers as text, but sometimes an incorrect value arrives at the Arduino. That sounds as though there is some sort of interference disrupting the data stream, an object between your Android device and the Arduino or the distance between the two being too far. It's also possible for your App to be disrupted by an Anti-Virus App.
So you send numbers as text, but sometimes an incorrect value comes to the Arduino.
Yes that's it. Inaccurate, and sometimes incomplete... (about 1 time out of 10). I use this method because I saw it somewhere as an example, but if there is an easier way, why not!
I read somewhere that with Arduino, using the "String" character string was not great (why?) and that it was better to use a "char" array. Do you have an opinion on that?
Could interference be possible from a phone, computer, Wi-Fi network?
Could an antivirus be the cause?
For distances:
My tablet is connected via wifi via a repeater (good connection)
Arduino in bluetooth to the tablet (less than a meter)
Wired computer at the internet box
Do you think an unsuitable baud rate could be the cause? Too slow, too fast, who?
Forgive me, but I don't think I understood very well.
Yes it is on this page that I took example 2A, I added a "$" at the beginning, so that Arduino knows when the value I send to it starts and when it stops. Ex: $684*
Thanks for that info (I didn't even know you could add more entries to the "join" block ).
But unfortunately, I still have numbers that sometimes come with unwanted signs...
Think it might be a baud rate issue?
I'm at 115200 baud on Bluetooth as well as the Arduino serial monitor. Too fast ? too slow ? synchronization problem? Or does it have nothing to do with it?
I had a doubt, maybe it was my Arduino program that modified the values ​​it received. So I displayed on the Ardunio serial monitor, directly what it received by Bluethoot. And I confirm that it sometimes receives unwanted characters (letters, signs).
So I think it's either a problem at MIT or a problem between MIT and Arduino... But what...
The Arduino library is based on 'C'. 'String' is from C++. It can work with C but you have to know what you are doing (C and C++ are not really close relations).
The values you are sending do not match-up with the Arduino Script snippet you have posted here, so first of all we need that .ino file (upload as a file).
You can experiment with that (try 9600)
You haven't given us basic details - Arduino model, Arduino Bluetooth version (is it built in or a module/shield?), Android version and Bluetooth version of the Tablet. We don't know how the send event is triggered nor the frequency (time interval between sends).
Have you ensured there isn't any interference that could corrupt the signal? A further consideration is the environment - temperature and humidity - an excess of either will make the Arduino fail. Also, depending on the model, the Arduino power supply may not be adequate.
Dear @Jon1,
in your .ino file it seems that you never re-initialize the variable boucleString.
I suppose that when the received string from AI2 is completed ("*" as ending character), you should reinitialize it to 0.
Or, do you that, elsewhere in your code ?
Apart of that, as @ChrisWard said, try to reduce the baudrate (of the BT side only, not the one to the serial monitor) to 9600. Provided that your BT on Arduino side is a HC05 or HC06. Which CPU board are you using (UNO, MEGA, NANO, ESP32,....) ? In any case, some details on your HW will help the community to understand a bit more your environment (as suggested by Chris).
Last, but not least, strings are really time (and memory) consuming on Arduino implementation. By using array of characters will avoid you (some) headaches due to unexpected behaviours.
Meilleures salutations,
Ugo.
I'm not very expert, but the re-initialize is done with this line of code right? (see picture) With each new reception that starts with a "$", my "stringBtPas" re-initialize, doesn't it? Or did I not understand?
In a few days I will post details of my hardware.
Do you advise me to use a "char" array instead of a "string"?
Je met aussi la traduction pour que tous le monde puisse suivre :
I also put the translation so that everyone can follow:
thank you for this info, I made the modification on my program as you advised me. Unfortunately, this didn't solve the problem, but maybe it makes more sense than before, so I keep the modification you advised me. Thanks !
I don't think I can use your way of doing it, because I have to (it seems to me) attach a "$" to the start and a "*" to the end, so Arduino knows when to start and when to end the value I want ( I send it quite a few other values).
In your Arduino code, "Bluetooth.setTimeout(100);" is very interesting! I didn't know that. I tried in my code, but the problem is still there. Thanks anyway, maybe I'll use it a day !
Yes I had also thought of using a button to send the text, that might have solved the problem. But the addition of this button did not suit me.
On the other hand, I would have liked very much that when I type the value, AI2 does not send anything, and when I click on the button of the Android keyboard "validated" it sends the value.
Because for example when I type 6584, there are 4 values sent (6-65-658-6584), and the same when I delete and when I retype a value.
Can AI2 detect hitting the "send/submit" button on Android keyboard?