To answer your questions:
1 - the app sends a 1-byte number to the Arduino while one of the movement arrows is being held down, once the button is released 0 is sent to the Arduino as seen in the pasted picture.
For the Arduino code it looks like this:
while (m == 16) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo01.write(servo1PPos);
servo1PPos++;
delay(speedDelay);
}
// Move servo 1 in the negative direction
while (m == 17) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo01.write(servo1PPos);
servo1PPos--;
delay(speedDelay);
}
this is what is used to control one servo motor, while the button is still being held down the servo motor moves in increments of 1 with a delay, depending on which arrow you press it will move in the positive or negative direction. Therefore the app does not send the positions to the code, but, instead tells the code to slowly increment the position, this is why the code has to send the positions back, this part has been working well.
50 positions is the maximum amount I've allowed to save but typically it won't exceed 10. In the code i have already made it capable of saving positions and repeating them in the same session you created them. Now I am trying to use Tinydb to save the desired positions (movement sequence) so you can simply open the app and run the positions you saved during your last session. As mentioned in the original post this is where im having problems trying to send multiple numbers to the arduino and reliably receive and order them.
I appreciate the helpful information on fixing some of the formatting and optimising things, I will definitely come back to do that once I get the entire program working!
In terms of the sending multiple 1-byte number problem, do you have any advice on how to approach the task? Would it be better to somehow convert the list into a string and send just one string that can be decoded in the Arduino code?
Also when I'm sending data to the app, I cannot filter the information incoming so it only goes to certain variables (see pasted image)
no matter what I tried, the logic statements just do not work in the clock and numbers greater than 95 still get stored in the global Saved_Positions list.
Would there be an easier way to contact you such as an audio call so everything can be explained clearly on both ends? There is a lot of information in terms of trying to understand the entire app and code and if that is what you need to do before being able to help with the data sending and receiving issues it will be hard to convey like this.
The way the servo motors are controlled is different to the example you sent earlier, the app does not know what position is being sent to the servo motors. The app only sends a signal (a fixed 1 byte number) to the code which will then increase or decrease the servo positions in increments of 1 with a set delay speed in the code. Refer to the first section of my previous reply to see the blocks and code I am talking about.
Yes, I have the code and app blocks to do that without any issues. All the positions saved are stored in a list which is then stored in Tinydb (each save has 6 servo positions for reference).
In terms of saving positions,the app sends a signal to the arduino, the arduino then sends the servo positions to the app, the app then stores those sent positions to a list.
That is why you need to store what the App sends, so it can re-send to the board and the board receives the data in the same way as it would if the data was input manually - now do you get it?
Okay, I understand what you mean in suggesting that, but, in order to do that I would need to re-do almost everything as currently, the app does not have any positional data until it's received from the Arduino due to how its coded.
In saying that, what I have for receiving the positions from the Arduino works well and I accurately get the data and store it into the app which puts me in the same position using both methods. I have the position data, but, the problem is now sending it to the board from here.
Are you able to help me identify some of the problems in my MIT app inventor blocks? if not completely understandable, ill try something else, but, what you are suggesting in terms of redoing everything like the app sent above isn't an option due to time constraints.
I can't help you to fix what you have but I don't think it's less work to try to fix the current method than it is to replace it, in my opinion the method is flawed. I have my own time constraints and when I'm on the forum, others to help too - we are a small team serving a lot of people.
@Ryley
I have verified that the TinyDB correctly obtains the SAVE positions, for example (90 70 32 32 54 64 34 43 53 43 54 65 65 32 67 65 34 98), a list that is a multiple of 6 since they are saved 6 by 6 servos.
Send the data using a for loop, I don't think it's a good option with App Inventor, since AI2 has a particular way with events. A Clock would be better and send the data every so often.
In the runSteps function I see many delays, in such a way that a servo must wait for another one to finish to start its movement, if during this time the application sends a data, the Bluetooth may not receive it.
I think it would be a good idea to do a simple debug, for example to have a TinyDB with a simple AllPositions = (40 50 60 70 80 90)
. Click a button and send those values to make the servos move.
You can send the 6 values at the same time and try to move the servos at the same time, this would be more complicated, since if you use "delay" one servo must wait for the other.
Or better to send one by one the position of each servo, when a servo ends it returns a position of "I_posicioned", and start the movement of the next servo.
To debug, simplify the runSteps code, eliminate the RUN, PAUSE, RESET.
Anyway another way to do it would be by angle, in a servo you can indicate the angle and the axis will move to that angle, it is not necessary to do an j++
Look at the first example, in the Serial Monitor I write 45 and the servo will move to the angle 45 of its axis. http://kio4.com/arduino/28servo.htm