Servo Shield and RC Transmitter via Arduino Uno

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
headbyte
 
Posts: 12
Joined: Wed Oct 20, 2021 12:22 pm

Re: Servo Shield and RC Transmitter via Arduino Uno

Post by headbyte »

I have some "hardware" chops. I've been an electronic & computer tech for over 20 yrs. But my coding sucks. :/

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Shield and RC Transmitter via Arduino Uno

Post by adafruit_support_bill »

Nice looking tank!
So how do I get this code . . . To work with the Servo Shield?
First, you need to include the library and declare your shield. Since you altered the default address, you will need to specify that in the constructor.

Code: Select all

#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver servos = Adafruit_PWMServoDriver(0x41);
And you can declare some handy constants for use in the code:

Code: Select all

#define SERVOMIN  150 // This is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // This is the 'maximum' pulse length count (out of 4096)

You can eliminate your include of the Servo.h and your declarations of the Servo objects and the servo attach statements, since they are no longer needed.

In your setup, you will need to add the following lines to initialize the shield.

Code: Select all

  servos.begin();
  servos.setOscillatorFrequency(27000000);
  servos.setPWMFreq(50);  // Analog servos run at ~50 Hz updates
And this code:

Code: Select all

        servo1.write(map(ch4, -100, 100, 0, 180));
        servo2.write(map(ch3, -100, 100, 0, 180));
can be replaced by:

Code: Select all

        servos.setPWM(0, 0, map(ch4, -100, 100, SERVOMIN , SERVOMAX));  // for servo connected to shield channel 0
        servos.setPWM(1, 0, map(ch3, -100, 100, SERVOMIN , SERVOMAX));  // for servo connected to shield channel 1

User avatar
headbyte
 
Posts: 12
Joined: Wed Oct 20, 2021 12:22 pm

Re: Servo Shield and RC Transmitter via Arduino Uno

Post by headbyte »

Thank you so much for your reply! This is great! I truly appreciate it.

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

Return to “Other Arduino products from Adafruit”