Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Servo Shield and RC Transmitter via Arduino Uno
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Servo Shield and RC Transmitter via Arduino Uno

by headbyte on Thu Oct 21, 2021 10:05 pm

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

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

Re: Servo Shield and RC Transmitter via Arduino Uno

by adafruit_support_bill on Fri Oct 22, 2021 8:13 am

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 | TOGGLE FULL SIZE
#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 | TOGGLE FULL SIZE
#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 | TOGGLE FULL SIZE
  servos.begin();
  servos.setOscillatorFrequency(27000000);
  servos.setPWMFreq(50);  // Analog servos run at ~50 Hz updates


And this code:
Code: Select all | TOGGLE FULL SIZE
        servo1.write(map(ch4, -100, 100, 0, 180));
        servo2.write(map(ch3, -100, 100, 0, 180));

can be replaced by:
Code: Select all | TOGGLE FULL SIZE
        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

adafruit_support_bill
 
Posts: 82440
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Shield and RC Transmitter via Arduino Uno

by headbyte on Sat Oct 23, 2021 9:42 am

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

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

Please be positive and constructive with your questions and comments.