Hello,
I am using the 16-Channel 12-bit PWM/Servo Shield to control 8 servos. I want my project to have one power input for the UNO and the Shield. Everything works perfectly when on separate power sources. When I try powering both by splitting one power supply (6v 2A) it works for a bit then I think the voltage drops too low for the UNO and it freezes up. Another solution I tried is using a 9v 2A power supply which I split, one goes to the UNO and one goes through this voltage dropper https://www.amazon.com/dp/B08L5VRBZS?re ... tails&th=1 I set the voltage going to the shield at 5.5 v but it isn't quick enough to respond to the servos and the voltage is dropping to 1-3 volts when the servos are activated. Does anyone have any ideas on powering the UNO and Shield with one power supply?
Thanks!
Peter
Powering 16-Channel 12-bit PWM/Servo Shield and UNO
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- peterboie
- Posts: 8
- Joined: Tue Jan 15, 2019 5:32 pm
- adafruit_support_bill
- Posts: 88136
- Joined: Sat Feb 07, 2009 10:11 am
Re: Powering 16-Channel 12-bit PWM/Servo Shield and UNO
With 8 servos, you probably need more than a 2A supply. Even micro servos can pull more than 1A when moving. You will need to estimate the idle and active current demands of the servos you are using, as well as how many of them you expect to be active at any given time.
- peterboie
- Posts: 8
- Joined: Tue Jan 15, 2019 5:32 pm
Re: Powering 16-Channel 12-bit PWM/Servo Shield and UNO
Thanks for the quick reply! I also tried a 5v 4a power supply but the voltage drops and the UNO stops working. I measured with my multimeter and it looks like the project was only pulling up to 1A at it's peak (if I measured correctly).I can definitely get a 9 volt 4 amp power supply but that still leaves the question, what is the best way to supply the 5-6 volts (and 2-4 amps) to the shield. Any ideas?
- adafruit_support_bill
- Posts: 88136
- Joined: Sat Feb 07, 2009 10:11 am
Re: Powering 16-Channel 12-bit PWM/Servo Shield and UNO
If the voltage is sagging with a 1A load on a 4A supply, that implies that the supply is defective. Either that or the measurement is suspect.I also tried a 5v 4a power supply but the voltage drops and the UNO stops working. I measured with my multimeter and it looks like the project was only pulling up to 1A at it's peak
Please post some photos showing how you have everything hooked up.
And also the code you are using and some specs on the servos you have.
- peterboie
- Posts: 8
- Joined: Tue Jan 15, 2019 5:32 pm
Re: Powering 16-Channel 12-bit PWM/Servo Shield and UNO
Thanks again for your help. Power comes in through a barrel jack, which gets split (wires aren't soldered in the pic) one side goes into the barrel jack of the uno and the other side goes to the shield. (at the split is where I was trying to lower the voltage for the shield to 5-6v). The servos are the blue micro servos I purchased from Adafruit.
here is the code:
here is the code:
Code: Select all
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <Adafruit_VCNL4040.h>
Adafruit_VCNL4040 vcnl4040 = Adafruit_VCNL4040();
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#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)
#define SERVOMID 375
#define USMIN 600 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150
#define USMAX 2400 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
#define SERVO_FREQ 50 // Analog servos run at ~50 Hz updates
//Servo variables
#define RIGHT_EYEBROW 0
#define LEFT_EYEBROW 1
#define RIGHT_EYE 2
#define LEFT_EYE 3
#define NOSE 4
#define UPPER_LIP 5
#define LOWER_LIP 6
#define HAND 7
//Button pins
#define YELLOW_HAPPY_LED 3
#define YELLOW_HAPPY_BUTTON 4
#define BLUE_SAD_LED 5
#define BLUE_SAD_BUTTON 6
#define RED_MAD_LED 7
#define RED_MAD_BUTTON 8
#define GREEN_SURPRISED_LED 9
#define GREEN_SURPRISED_BUTTON 10
#define CRAZY_SWITCH 11
#define HAND_IN 370
#define HAND_OUT 245
int ledTimeInterval = 400;
unsigned long prevLedTime = 0;
int yellowLedState = HIGH;
int blueLedState = LOW;
int redLedState = HIGH;
int greenLedState = LOW;
int switcher = 0;
int counter = 0;
int moveLowerLip = 0;
void setup() {
Serial.begin(115200);
// Wait until serial port is opened
while (!Serial) {
delay(1);
}
if (!vcnl4040.begin()) {
Serial.println("Couldn't find VCNL4040 chip");
while (1);
}
Serial.println("Found VCNL4040 chip");
Serial.print("Proximity LED current set to: ");
switch (vcnl4040.getProximityLEDCurrent()) {
case VCNL4040_LED_CURRENT_50MA: Serial.println("50 mA"); break;
case VCNL4040_LED_CURRENT_75MA: Serial.println("75 mA"); break;
case VCNL4040_LED_CURRENT_100MA: Serial.println("100 mA"); break;
case VCNL4040_LED_CURRENT_120MA: Serial.println("120 mA"); break;
case VCNL4040_LED_CURRENT_140MA: Serial.println("140 mA"); break;
case VCNL4040_LED_CURRENT_160MA: Serial.println("160 mA"); break;
case VCNL4040_LED_CURRENT_180MA: Serial.println("180 mA"); break;
case VCNL4040_LED_CURRENT_200MA: Serial.println("200 mA"); break;
}
//vcnl4040.setProximityLEDDutyCycle(VCNL4040_LED_DUTY_1_40);
Serial.print("Proximity LED duty cycle set to: ");
switch (vcnl4040.getProximityLEDDutyCycle()) {
case VCNL4040_LED_DUTY_1_40: Serial.println("1/40"); break;
case VCNL4040_LED_DUTY_1_80: Serial.println("1/80"); break;
case VCNL4040_LED_DUTY_1_160: Serial.println("1/160"); break;
case VCNL4040_LED_DUTY_1_320: Serial.println("1/320"); break;
}
//vcnl4040.setAmbientIntegrationTime(VCNL4040_AMBIENT_INTEGRATION_TIME_80MS);
Serial.print("Ambient light integration time set to: ");
switch (vcnl4040.getAmbientIntegrationTime()) {
case VCNL4040_AMBIENT_INTEGRATION_TIME_80MS: Serial.println("80 ms"); break;
case VCNL4040_AMBIENT_INTEGRATION_TIME_160MS: Serial.println("160 ms"); break;
case VCNL4040_AMBIENT_INTEGRATION_TIME_320MS: Serial.println("320 ms"); break;
case VCNL4040_AMBIENT_INTEGRATION_TIME_640MS: Serial.println("640 ms"); break;
}
//vcnl4040.setProximityIntegrationTime(VCNL4040_PROXIMITY_INTEGRATION_TIME_8T);
Serial.print("Proximity integration time set to: ");
switch (vcnl4040.getProximityIntegrationTime()) {
case VCNL4040_PROXIMITY_INTEGRATION_TIME_1T: Serial.println("1T"); break;
case VCNL4040_PROXIMITY_INTEGRATION_TIME_1_5T: Serial.println("1.5T"); break;
case VCNL4040_PROXIMITY_INTEGRATION_TIME_2T: Serial.println("2T"); break;
case VCNL4040_PROXIMITY_INTEGRATION_TIME_2_5T: Serial.println("2.5T"); break;
case VCNL4040_PROXIMITY_INTEGRATION_TIME_3T: Serial.println("3T"); break;
case VCNL4040_PROXIMITY_INTEGRATION_TIME_3_5T: Serial.println("3.5T"); break;
case VCNL4040_PROXIMITY_INTEGRATION_TIME_4T: Serial.println("4T"); break;
case VCNL4040_PROXIMITY_INTEGRATION_TIME_8T: Serial.println("8T"); break;
}
//vcnl4040.setProximityHighResolution(false);
Serial.print("Proximity measurement high resolution? ");
Serial.println(vcnl4040.getProximityHighResolution() ? "True" : "False");
Serial.println("");
pinMode(YELLOW_HAPPY_BUTTON, INPUT_PULLUP);
pinMode(YELLOW_HAPPY_LED, OUTPUT);
pinMode(BLUE_SAD_BUTTON, INPUT_PULLUP);
pinMode(BLUE_SAD_LED, OUTPUT);
pinMode(RED_MAD_BUTTON, INPUT_PULLUP);
pinMode(RED_MAD_LED, OUTPUT);
pinMode(GREEN_SURPRISED_BUTTON, INPUT_PULLUP);
pinMode(GREEN_SURPRISED_LED, OUTPUT);
pinMode(CRAZY_SWITCH, INPUT_PULLUP);
digitalWrite(YELLOW_HAPPY_LED, LOW);
digitalWrite(BLUE_SAD_LED, LOW);
digitalWrite(RED_MAD_LED, LOW);
digitalWrite(GREEN_SURPRISED_LED, LOW);
pwm.begin();
pwm.setOscillatorFrequency(27000000);
pwm.setPWMFreq(SERVO_FREQ); // Analog servos run at ~50 Hz updates
//nose is stuck to face
pwm.setPWM(NOSE, 0, 430);
}
void loop() {
//blinking led buttons in a row
unsigned long ledTime = millis();
if (ledTime - prevLedTime > ledTimeInterval) {
prevLedTime = ledTime;
counter ++;
switch (counter) {
case 1:
digitalWrite(YELLOW_HAPPY_LED, HIGH);
digitalWrite(BLUE_SAD_LED, LOW);
digitalWrite(RED_MAD_LED, LOW);
digitalWrite(GREEN_SURPRISED_LED, LOW);
break;
case 2:
digitalWrite(YELLOW_HAPPY_LED, LOW);
digitalWrite(BLUE_SAD_LED, HIGH);
digitalWrite(RED_MAD_LED, LOW);
digitalWrite(GREEN_SURPRISED_LED, LOW);
break;
case 3:
digitalWrite(YELLOW_HAPPY_LED, LOW);
digitalWrite(BLUE_SAD_LED, LOW);
digitalWrite(RED_MAD_LED, HIGH);
digitalWrite(GREEN_SURPRISED_LED, LOW);
break;
case 4:
digitalWrite(YELLOW_HAPPY_LED, LOW);
digitalWrite(BLUE_SAD_LED, LOW);
digitalWrite(RED_MAD_LED, LOW);
digitalWrite(GREEN_SURPRISED_LED, HIGH);
counter = 0;
break;
}
}
int yellowButtonState = digitalRead(YELLOW_HAPPY_BUTTON);
int blueButtonState = digitalRead(BLUE_SAD_BUTTON);
int redButtonState = digitalRead(RED_MAD_BUTTON);
int greenButtonState = digitalRead(GREEN_SURPRISED_BUTTON);
int crazySwitchState = digitalRead(CRAZY_SWITCH);
if (yellowButtonState == LOW) {
switcher = 1;
}
if (blueButtonState == LOW) {
switcher = 2;
}
if (redButtonState == LOW) {
switcher = 3;
}
if (greenButtonState == LOW) {
switcher = 4;
}
if (crazySwitchState == LOW) {
switcher = 5;
}
if (vcnl4040.getProximity() > 40) {
Serial.println("the nose fell off!!");
Serial.println("nose triggered");
noseFall();
}
switch (switcher) {
case 1:
happyFaceYellow();
break;
case 2:
sadFaceBlue();
break;
case 3:
madFaceRed();
break;
case 4:
surprisedFaceGreen();
break;
case 5:
crazyFaceSwitch();
break;
case 6:
noseFall();
break;
}
}
//eyes minimum is 120 ,left and max is 440, right
void happyFaceYellow() {
Serial.println("yellow");
//Hand out
pwm.setPWM(HAND, 0, HAND_OUT);
pwm.setPWM(RIGHT_EYEBROW, 0, 330);
pwm.setPWM(LEFT_EYEBROW, 0, 250);
//eyes looking left
pwm.setPWM(RIGHT_EYE, 0, 140);
pwm.setPWM(LEFT_EYE, 0, 140);
pwm.setPWM(UPPER_LIP, 0, 215);
pwm.setPWM(LOWER_LIP, 0, 215);
switcher = 0;
}
void sadFaceBlue() {
Serial.println("blue");
//hand in
pwm.setPWM(HAND, 0, HAND_IN);
//even eyebrows
pwm.setPWM(RIGHT_EYEBROW, 0, 380);
pwm.setPWM(LEFT_EYEBROW, 0, 200);
//eyes looking right
pwm.setPWM(RIGHT_EYE, 0, 430);
pwm.setPWM(LEFT_EYE, 0, 430 );
pwm.setPWM(UPPER_LIP, 0, 360);
pwm.setPWM(LOWER_LIP, 0, 360);
switcher = 0;
}
void madFaceRed() {
Serial.println("red");
//hand in
pwm.setPWM(HAND, 0, HAND_IN);
pwm.setPWM(RIGHT_EYEBROW, 0, 440);
pwm.setPWM(LEFT_EYEBROW, 0, 150);
//eyes looking down
pwm.setPWM(RIGHT_EYE, 0, 280);
pwm.setPWM(LEFT_EYE, 0, 280);
pwm.setPWM(UPPER_LIP, 0, 280);
pwm.setPWM(LOWER_LIP, 0, 280);
switcher = 0;
}
void surprisedFaceGreen() {
Serial.println("green");
//hand in
pwm.setPWM(HAND, 0, HAND_IN);
pwm.setPWM(RIGHT_EYE, 0, 340);
pwm.setPWM(LEFT_EYE, 0, 340);
pwm.setPWM(RIGHT_EYEBROW, 0, 330);
pwm.setPWM(LEFT_EYEBROW, 0, 140);
pwm.setPWM(UPPER_LIP, 0, 375);
pwm.setPWM(LOWER_LIP, 0, 215);
moveLowerLip = 1;
switcher = 0;
}
void crazyFaceSwitch() {
Serial.println("crazy switch");
//hand in
pwm.setPWM(HAND, 0, HAND_IN);
pwm.setPWM(RIGHT_EYE, 0, 430);
pwm.setPWM(LEFT_EYE, 0, 140);
pwm.setPWM(RIGHT_EYEBROW, 0, 330);
pwm.setPWM(LEFT_EYEBROW, 0, 150);
pwm.setPWM(UPPER_LIP, 0, 280);
pwm.setPWM(LOWER_LIP, 0, 215);
//nose falls
pwm.setPWM(NOSE, 0, 200);
delay(500);
pwm.setPWM(LOWER_LIP, 0, 280);
pwm.setPWM(LEFT_EYE, 0, 430);
pwm.setPWM(RIGHT_EYE, 0, 140);
pwm.setPWM(LEFT_EYEBROW, 0, 250);
pwm.setPWM(RIGHT_EYEBROW, 0, 440);
delay(500);
//Hand out
pwm.setPWM(HAND, 0, HAND_OUT);
pwm.setPWM(LOWER_LIP, 0, 215);
pwm.setPWM(RIGHT_EYE, 0, 430);
pwm.setPWM(LEFT_EYE, 0, 140);
pwm.setPWM(RIGHT_EYEBROW, 0, 330);
pwm.setPWM(LEFT_EYEBROW, 0, 150);
delay(500);
pwm.setPWM(LOWER_LIP, 0, 280);
pwm.setPWM(LEFT_EYE, 0, 430);
pwm.setPWM(RIGHT_EYE, 0, 140);
pwm.setPWM(LEFT_EYEBROW, 0, 250);
pwm.setPWM(RIGHT_EYEBROW, 0, 440);
//nose magnet back up
pwm.setPWM(NOSE, 0, 430);
delay(500);
//hand in
pwm.setPWM(HAND, 0, HAND_IN);
switcher = 0;
}
void noseFall() {
Serial.println("nose fall");
pwm.setPWM(NOSE, 0, 200);
digitalWrite(YELLOW_HAPPY_LED, HIGH);
digitalWrite(BLUE_SAD_LED, HIGH);
digitalWrite(RED_MAD_LED, HIGH);
digitalWrite(GREEN_SURPRISED_LED, HIGH);
delay(250);
digitalWrite(YELLOW_HAPPY_LED, LOW);
digitalWrite(BLUE_SAD_LED, LOW);
digitalWrite(RED_MAD_LED, LOW);
digitalWrite(GREEN_SURPRISED_LED, LOW);
delay(750);
pwm.setPWM(NOSE, 0, 430);
switcher = 0;
}
- Attachments
-
- IMG_6104.jpg (736.52 KiB) Viewed 227 times
Last edited by adafruit_support_bill on Tue Aug 02, 2022 3:43 pm, edited 1 time in total.
Reason: Please use [code] tags when posting code to the forums
Reason: Please use [code] tags when posting code to the forums
- adafruit_support_bill
- Posts: 88136
- Joined: Sat Feb 07, 2009 10:11 am
Re: Powering 16-Channel 12-bit PWM/Servo Shield and UNO
5v into the power jack of the UNO is a problem. The on-board regulator needs a couple volts of 'headroom' to properly regulate. I believe that Arduino specifies 7v as the minimum input. However, if you have a regulated 5v source, you can feed regulated 5v power to the Arduino via the 5v pin.Power comes in through a barrel jack, which gets split (wires aren't soldered in the pic) one side goes into the barrel jack of the uno
Those can draw several hundred mA each when moving under load.The servos are the blue micro servos I purchased from Adafruit.
You have a lot going on there - both in hardware and in the code. I'd start by simplifying things to the minimum subset that is causing your power problems.
I'd start by loading a super simple program like the 'blink' example code. If you still have power issues, it is probably a short circuit somewhere.
Otherwise, start enabling code for each of your components one-by-one: LEDs, Servos, VCNL4040 and see at which point the problems start.
- peterboie
- Posts: 8
- Joined: Tue Jan 15, 2019 5:32 pm
Re: Powering 16-Channel 12-bit PWM/Servo Shield and UNO
I think I narrowed it down to the power supply. When I plug them in to separate power supplies, the servo shield in to a 5v 2a or 4a power supply and the UNO into a 9v 2a power supply everything works great without issue. But I'd like to have one power source so I don't have two plugs coming out of the project. Any ideas to make that work?
- adafruit_support_bill
- Posts: 88136
- Joined: Sat Feb 07, 2009 10:11 am
Re: Powering 16-Channel 12-bit PWM/Servo Shield and UNO
As I said in my previous post. You need to simplify things to determine where the problem is.
The UNO will run fine with (regulated) 5 supplied to the 5v pin. So it should run with the same 5v you are supplying to the servos. If not, there is a problem with your wiring.
The UNO will run fine with (regulated) 5 supplied to the 5v pin. So it should run with the same 5v you are supplying to the servos. If not, there is a problem with your wiring.
- peterboie
- Posts: 8
- Joined: Tue Jan 15, 2019 5:32 pm
Re: Powering 16-Channel 12-bit PWM/Servo Shield and UNO
Thanks for clarifying, I understand now. I'll start. trying to narrow down where the wiring problem is. Thanks for your help!
- peterboie
- Posts: 8
- Joined: Tue Jan 15, 2019 5:32 pm
Re: Powering 16-Channel 12-bit PWM/Servo Shield and UNO
Just wanted to give you an update. I finally figured it out. powering the UNO through the power jack was what was causing the issue because it's regulated. So I just wired the power directly into the 5v pin because I am using a 5v power source and everything is working fine now off of the 5v 4 a power adapter. Thanks for all your help!
Peter
Peter
Please be positive and constructive with your questions and comments.