Saturday, September 9, 2023

Movement programming - Part A

Got delivery on Friday of more Arduino Nano microcontrollers so I could try this out.  Amazed once again that this actually worked as advertised when I wired everything up and ran the code.  The only problem with this method is the programming only runs while the microcontroller is powered.  It is lost when powered off.  Another controller that is a bit more robust and some metal gear servos coming next Friday for the robotic arm project.  Until then I will try to figure out something clever to do with what I have.  99,103,65,0,B

3 comments:

  1. John try this code in your current setup. It should run a sequence of your servos on power up that you could modify to suit your needs.
    /*
    Test of servo sequencer
    for John at the Field Lab
    */

    // include the Servo library
    #include
    Servo servo_0;
    Servo servo_1;
    Servo servo_2;
    Servo servo_3;

    int spd; // variable to hold the speed of each movement
    int pos; //variable holds the position applied to each servo

    void setup() {
    servo_0.attach(3); // attaches the servo
    servo_1.attach(10);
    servo_2.attach(5);
    servo_3.attach(11);

    Serial.begin(115200); // open a serial connection to your computer
    Serial.println("mini robot ready...");
    }

    void loop() {
    //Step 1
    for (pos = 0; pos < 180; pos += 1) {
    servo_0.write(pos);
    delay(spd);//This controls the speed of the movements
    }
    delay(1000);//This is the delay after Step 1

    //Step 2
    for (pos = 0; pos < 180; pos += 1) {
    servo_2.write(pos);
    delay(spd);//This controls the speed of the movements
    }
    delay(1000);//This is the delay after Step 2

    //Step 3
    for (pos = 180; pos >= 0; pos -= 1) {
    servo_1.write(pos);
    delay(spd);//This controls the speed of the movements
    }
    delay(1000);//This is the delay after Step 3

    //Step 4
    for (pos = 180; pos >= 0; pos -= 1) {
    servo_3.write(pos);
    delay(spd);//This controls the speed of the movements
    }
    delay(1000);//This is the delay after Step 4

    //Step 5
    for (pos = 180; pos >= 0; pos -= 1) {
    servo_0.write(pos);
    delay(spd);//This controls the speed of the movements
    }
    delay(1000);//This is the delay after Step 5

    //Step 6
    for (pos = 180; pos >= 0; pos -= 1) {
    servo_2.write(pos);
    delay(spd);//This controls the speed of the movements
    }
    delay(1000);//This is the delay after Step 6

    //Step 7
    for (pos = 0; pos < 180; pos += 1) {
    servo_1.write(pos);
    delay(spd);//This controls the speed of the movements
    }
    delay(1000);//This is the delay after Step 7

    //Step 8
    for (pos = 0; pos < 180; pos += 1) {
    servo_3.write(pos);
    delay(spd);//This controls the speed of the movements
    }
    delay(1000);//This is the delay after Step 8

    //Now the loop will repeat from Step 1
    }

    ReplyDelete
  2. Thinking about this code I realize the line
    int spd; // variable to hold the speed of each movement
    Should have been:
    int spd =15; // variable - the ms delay between each degree of movement (smaller = faster move)

    ReplyDelete