Arduino not looping???
-
Hi All, Using an Arduino to drive a servo motor (well trying).
#include Servo myServo;
int servoPin = 2;
uint16_t i = 0;void setup() {
// put your setup code here, to run once:
myServo.attach(servoPin);
pinMode(LED_BUILTIN, OUTPUT);
}void loop() {
// put your main code here, to run repeatedly:
HERE:
i = 0;
for(i = 1; i <= 180; i++)
{
myServo.write(i);
delay(15);
}
for(i = 180; i >= 1; i--)
{
myServo.write(i);
delay(15);
}
goto HERE;
}Now what I believe Should happen is digital Pin 2 which is being used as the servo pin goes high and the due to the loop the pulse is 'stretched' from 1 to 180 which is taken by Servo and magiced it into a value and sent via pin 2, once this is done the value get counted down from 180 back to 1 by the second loop. What happens is by scoping the pin the pulse is one get to 180 counts back and does not loop. This started as a 'Hmmm' problem and has slowly been upgraded. I have put the loops in separate functions to see if that helps, no. Google has been a no and I can't log on to Arduino board as my Pass word was rejected ands the sent pass word link doesn't. Going fully bananas here. Glenn PANIC OVER THE CODE NOW WORKS!
-
Hi All, Using an Arduino to drive a servo motor (well trying).
#include Servo myServo;
int servoPin = 2;
uint16_t i = 0;void setup() {
// put your setup code here, to run once:
myServo.attach(servoPin);
pinMode(LED_BUILTIN, OUTPUT);
}void loop() {
// put your main code here, to run repeatedly:
HERE:
i = 0;
for(i = 1; i <= 180; i++)
{
myServo.write(i);
delay(15);
}
for(i = 180; i >= 1; i--)
{
myServo.write(i);
delay(15);
}
goto HERE;
}Now what I believe Should happen is digital Pin 2 which is being used as the servo pin goes high and the due to the loop the pulse is 'stretched' from 1 to 180 which is taken by Servo and magiced it into a value and sent via pin 2, once this is done the value get counted down from 180 back to 1 by the second loop. What happens is by scoping the pin the pulse is one get to 180 counts back and does not loop. This started as a 'Hmmm' problem and has slowly been upgraded. I have put the loops in separate functions to see if that helps, no. Google has been a no and I can't log on to Arduino board as my Pass word was rejected ands the sent pass word link doesn't. Going fully bananas here. Glenn PANIC OVER THE CODE NOW WORKS!
-
Hi All, Using an Arduino to drive a servo motor (well trying).
#include Servo myServo;
int servoPin = 2;
uint16_t i = 0;void setup() {
// put your setup code here, to run once:
myServo.attach(servoPin);
pinMode(LED_BUILTIN, OUTPUT);
}void loop() {
// put your main code here, to run repeatedly:
HERE:
i = 0;
for(i = 1; i <= 180; i++)
{
myServo.write(i);
delay(15);
}
for(i = 180; i >= 1; i--)
{
myServo.write(i);
delay(15);
}
goto HERE;
}Now what I believe Should happen is digital Pin 2 which is being used as the servo pin goes high and the due to the loop the pulse is 'stretched' from 1 to 180 which is taken by Servo and magiced it into a value and sent via pin 2, once this is done the value get counted down from 180 back to 1 by the second loop. What happens is by scoping the pin the pulse is one get to 180 counts back and does not loop. This started as a 'Hmmm' problem and has slowly been upgraded. I have put the loops in separate functions to see if that helps, no. Google has been a no and I can't log on to Arduino board as my Pass word was rejected ands the sent pass word link doesn't. Going fully bananas here. Glenn PANIC OVER THE CODE NOW WORKS!
glennPattonWork3 wrote:
ands the sent pass word link doesn't
You might want to spend some more time on that. Did you try manually copying and then inspecting (versus just clicking)? Sometimes something (either sender or email client) can end up adding stuff where it shouldn't to the url. Or create a new account?
-
Hi All, Using an Arduino to drive a servo motor (well trying).
#include Servo myServo;
int servoPin = 2;
uint16_t i = 0;void setup() {
// put your setup code here, to run once:
myServo.attach(servoPin);
pinMode(LED_BUILTIN, OUTPUT);
}void loop() {
// put your main code here, to run repeatedly:
HERE:
i = 0;
for(i = 1; i <= 180; i++)
{
myServo.write(i);
delay(15);
}
for(i = 180; i >= 1; i--)
{
myServo.write(i);
delay(15);
}
goto HERE;
}Now what I believe Should happen is digital Pin 2 which is being used as the servo pin goes high and the due to the loop the pulse is 'stretched' from 1 to 180 which is taken by Servo and magiced it into a value and sent via pin 2, once this is done the value get counted down from 180 back to 1 by the second loop. What happens is by scoping the pin the pulse is one get to 180 counts back and does not loop. This started as a 'Hmmm' problem and has slowly been upgraded. I have put the loops in separate functions to see if that helps, no. Google has been a no and I can't log on to Arduino board as my Pass word was rejected ands the sent pass word link doesn't. Going fully bananas here. Glenn PANIC OVER THE CODE NOW WORKS!
Why would you put the HERE label and goto statement in there when the Arduino constantly executes the loop function for you automatically?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
What did you do to get it working ?
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
Copied into two separate functions and swore... Basically rubber ducking it.
-
Why would you put the HERE label and goto statement in there when the Arduino constantly executes the loop function for you automatically?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakThat was part of the problem it was hitting the bottom of the second for loop and not looping (or seeming too), Oh man I hate the fact the Arduino servo library means you have to bit bang to change the frequency.
-
glennPattonWork3 wrote:
ands the sent pass word link doesn't
You might want to spend some more time on that. Did you try manually copying and then inspecting (versus just clicking)? Sometimes something (either sender or email client) can end up adding stuff where it shouldn't to the url. Or create a new account?
No the saved log in didn't work went back to manual list tried again same problem.
-
Hi All, Using an Arduino to drive a servo motor (well trying).
#include Servo myServo;
int servoPin = 2;
uint16_t i = 0;void setup() {
// put your setup code here, to run once:
myServo.attach(servoPin);
pinMode(LED_BUILTIN, OUTPUT);
}void loop() {
// put your main code here, to run repeatedly:
HERE:
i = 0;
for(i = 1; i <= 180; i++)
{
myServo.write(i);
delay(15);
}
for(i = 180; i >= 1; i--)
{
myServo.write(i);
delay(15);
}
goto HERE;
}Now what I believe Should happen is digital Pin 2 which is being used as the servo pin goes high and the due to the loop the pulse is 'stretched' from 1 to 180 which is taken by Servo and magiced it into a value and sent via pin 2, once this is done the value get counted down from 180 back to 1 by the second loop. What happens is by scoping the pin the pulse is one get to 180 counts back and does not loop. This started as a 'Hmmm' problem and has slowly been upgraded. I have put the loops in separate functions to see if that helps, no. Google has been a no and I can't log on to Arduino board as my Pass word was rejected ands the sent pass word link doesn't. Going fully bananas here. Glenn PANIC OVER THE CODE NOW WORKS!
It's not Arduino, but there are Arduino compatible, cheaper, more powerful boards made by a company called Espressif out of China. They make good SoCs and used by many people, including me professionally. I recommend the ESP32 based devices. You can get like an M5 Stack Core2 which is pretty neat, or like a Lilygo TTGO T-Display T1 (i have several), or my favorite - one of the Makerfabs ESP Display lines like the Parallel, the 4" or the 4.3" You can also get them as raw devkits, but they don't use the arduino form factor (although a 3rd party makes arduino form factor ESP32 devkits I can't recommend them) If you do go that route, reddit's /r/esp32 is a really good resource (when they get around to being finished with their reddit protest)
Check out my IoT graphics library here: https://honeythecodewitch/gfx
-
Hi All, Using an Arduino to drive a servo motor (well trying).
#include Servo myServo;
int servoPin = 2;
uint16_t i = 0;void setup() {
// put your setup code here, to run once:
myServo.attach(servoPin);
pinMode(LED_BUILTIN, OUTPUT);
}void loop() {
// put your main code here, to run repeatedly:
HERE:
i = 0;
for(i = 1; i <= 180; i++)
{
myServo.write(i);
delay(15);
}
for(i = 180; i >= 1; i--)
{
myServo.write(i);
delay(15);
}
goto HERE;
}Now what I believe Should happen is digital Pin 2 which is being used as the servo pin goes high and the due to the loop the pulse is 'stretched' from 1 to 180 which is taken by Servo and magiced it into a value and sent via pin 2, once this is done the value get counted down from 180 back to 1 by the second loop. What happens is by scoping the pin the pulse is one get to 180 counts back and does not loop. This started as a 'Hmmm' problem and has slowly been upgraded. I have put the loops in separate functions to see if that helps, no. Google has been a no and I can't log on to Arduino board as my Pass word was rejected ands the sent pass word link doesn't. Going fully bananas here. Glenn PANIC OVER THE CODE NOW WORKS!
While programming an Arduino device from my Linux desktop, I've found it quite helpful to fill my code with progress output to the serial port e.g.
Serial.println(" CONNECTED");
and then watch the progress from another window with tail -f
tail -f /dev/ttyX
where ttyX is the serial port of the Arduino device. (On USB it can change every time you plug it in.) You need to run the tail command as root or have added yourself to the "dialout" group. p.s. you don't need the "goto HERE"
-
While programming an Arduino device from my Linux desktop, I've found it quite helpful to fill my code with progress output to the serial port e.g.
Serial.println(" CONNECTED");
and then watch the progress from another window with tail -f
tail -f /dev/ttyX
where ttyX is the serial port of the Arduino device. (On USB it can change every time you plug it in.) You need to run the tail command as root or have added yourself to the "dialout" group. p.s. you don't need the "goto HERE"
Hi, I know I don't need goto HERE that was left over from a previous hack to prove to myself it was looping (in the past I have used HELL as a label there's something oddly satisfying about type goto HELL!)