Simple code for Adafruit 16-channel PWM/Servo Shield

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Mihailo
 
Posts: 3
Joined: Mon Aug 02, 2021 12:41 pm

Simple code for Adafruit 16-channel PWM/Servo Shield

Post by Mihailo »

Hi guys,

I'm trying to find a simple arduino code for moving a servo attached to one of the 16 connectors left and right?

This shield is what I'm talking about - https://www.adafruit.com/product/1411.

The example 'servo' from the library is soooooo complicated.

I don't want to calculate the frequency and pulse length.

All I want is to move it left, then right :)

Do you know where I can find the simplest version of the code for moving the servo (cheap one - SG90), all the way to the right, then all the way to the left, for example.

I've tried the example servo sketch and I think it fried one of my servos (will confirm later).


Thanks, Mihailo :)

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Simple code for Adafruit 16-channel PWM/Servo Shield

Post by dastels »

Yes, you have to be careful about the limits of movement. Servos differ a bit from one to another about what pulse widths are at either end. Over drive it and there could be damage.

You fail to say what MCU/board/language you are using.

Dave

User avatar
Mihailo
 
Posts: 3
Joined: Mon Aug 02, 2021 12:41 pm

Re: Simple code for Adafruit 16-channel PWM/Servo Shield

Post by Mihailo »

Oh, sorry, thought I wrote it.

I'm using this with Arduino Uno, in Arduino IDE.

There is an example sketch 'servo' that comes with the library, but it's a bit of an overkill. Testing 8 servos simultaneously. Lots of variables,parameters and calculations...

All I want is one servo to move. Left. Then right.

?

Thanks :)

User avatar
Mihailo
 
Posts: 3
Joined: Mon Aug 02, 2021 12:41 pm

Re: Simple code for Adafruit 16-channel PWM/Servo Shield

Post by Mihailo »

Here, I've found a solution myself (combining what I've found online)

Why nobody wrote it simple like this ???

This is for Arduino IDE, using SG90 small blue cheap servo (parameters for all the way to the left, then wait 1 sec, then all the way to the right, wait 1 sec).

Servo is attached to the port 0 on the shield. For other ports just change first 0 in pwm.setPWM(0, 0,100) to the port you want.

Hope this helps someone! :)

Code: Select all

#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

void setup() {
  Serial.begin(9600);
  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
}

void loop() {
    pwm.setPWM(0, 0,100);
    delay(1000);
    pwm.setPWM(0, 0, 650);
    delay(1000);
}
Take care, everyone! :)

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”