So I'm using bluetooth on serialport 9600 and sending signals to alter the position of the servo. The code seems to be running well and the bluetooth connection is strong. Every time I send a signal trying to move the servo, it seems like the servo is literally trying to go the that directed position and immediately turn back to it's original spot. Like it seems like it needs like half a second to fully go to 180 degree from 90, but I feel like there is something in my code that makes the servo go straight back to 90 after one iteration behind the signal received iteration. Please read my code and let me know!
SoftwareSerial mySerial(RxD, TxD); // RX, TX for Bluetooth
That's like naming your dog myDog. Stupid, in other words.
Name the instance based on what it is reading data from.
Servo myServo;
Servo myServo1;
More stupid names. Name the instances based on what the servo does, not the fact that it is a servo.
do {
Shit-can the do-while. It is almost never the right statement to use. Use a while statement. Make your code read the serial data when there is data to read, rather than doing nothing 99.9% of the time.
Your title says "Servo testing using bluetooth. Servo won't turn all the way". Does that mean that it does go all the way when you are NOT using bluetooth?
If you don't know the answer then IMHO the first thing to do is to get your servo moving the way you want on its own. When that is working properly write a separate short program to receive Bluetooth data reliably. When both work separately then you can develop a program that combines the feaures.
For receiving data have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
Robin2:
Your title says "Servo testing using bluetooth. Servo won't turn all the way". Does that mean that it does go all the way when you are NOT using bluetooth?
If you don't know the answer then IMHO the first thing to do is to get your servo moving the way you want on its own. When that is working properly write a separate short program to receive Bluetooth data reliably. When both work separately then you can develop a program that combines the feaures.
For receiving data have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
...R
Thank for the guided link! I'll check it out and update you!
PaulS:
Shit-can the do-while. It is almost never the right statement to use. Use a while statement. Make your code read the serial data when there is data to read, rather than doing nothing 99.9% of the time.
And, finally, how ARE the servos powered?
The servos are powered with an external power source that supplies up to 2A @ 5V.
I'll go ahead and clean up the code!
Could you possibly elaborate on the do-while and while statement? How do they differ in this case and why do you say that do-while is doing nothing 99.9% of the time? What would you recommend is the best way to make this current code efficient? This is my first time trying Bluetooth and serial ports, so I'm a little short handed. Thank you for your remarks though!!!
boolean is true/false. boolean is NOT 'a'. 'a' is a char.
boolean isValidInput; do {
Of all the messed up confusing formatting screw ups you could possibly imagine, I think starting a do while on a line with other code takes the cake.
Please use Control-T to format code before you post it. We don't format code the way we do just to make it pretty. There's a real good purpose for doing it the way we do.
And please clean up the comments while you are editing code. The only thing worse than no comments is wrong comments.
byte c; // get the next character from the bluetooth serial port
No it doesn't.
c = mySerial.read(); // Execute the option based on the character recieved
I think this comment was supposed to go with that last one instead.
IF you're not going to have the comment where they make any sense, then just delete them. Don't add to your own confusion by getting them all messed up. Remember, you're asking someone else to kindly read your code and check it for you, try not to make that unnecessarily hard on them.
Thank you for the remarks! This code is not entirely mine. Most of it is actually from an instructable online because I've never dealt with Bluetooth and serial ports before. Could you possibly guide me to the best Bluetooth communications tutorial? I'm kinda lost. Also, the Boolean part was a dumb mistake that I made because I was thinking of multiple things at once. Sorry! But thank you!!!