Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Hardware & Devices
  4. Arduino not looping???

Arduino not looping???

Scheduled Pinned Locked Moved Hardware & Devices
hardwarehelpquestionworkspace
10 Posts 6 Posters 17 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    glennPattonWork3
    wrote on last edited by
    #1

    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!

    pkfoxP J D H E 5 Replies Last reply
    0
    • G glennPattonWork3

      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!

      pkfoxP Offline
      pkfoxP Offline
      pkfox
      wrote on last edited by
      #2

      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

      G 1 Reply Last reply
      0
      • G glennPattonWork3

        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!

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        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?

        G 1 Reply Last reply
        0
        • G glennPattonWork3

          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!

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          G 1 Reply Last reply
          0
          • pkfoxP pkfox

            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

            G Offline
            G Offline
            glennPattonWork3
            wrote on last edited by
            #5

            Copied into two separate functions and swore... Basically rubber ducking it.

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              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

              G Offline
              G Offline
              glennPattonWork3
              wrote on last edited by
              #6

              That 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.

              1 Reply Last reply
              0
              • J jschell

                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?

                G Offline
                G Offline
                glennPattonWork3
                wrote on last edited by
                #7

                No the saved log in didn't work went back to manual list tried again same problem.

                1 Reply Last reply
                0
                • G glennPattonWork3

                  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!

                  H Offline
                  H Offline
                  honey the codewitch
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • G glennPattonWork3

                    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!

                    E Offline
                    E Offline
                    Ed Attfield
                    wrote on last edited by
                    #9

                    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"

                    G 1 Reply Last reply
                    0
                    • E Ed Attfield

                      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"

                      G Offline
                      G Offline
                      glennPattonWork3
                      wrote on last edited by
                      #10

                      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!)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups