I have an Arduino UNO and the Adafruit PMW 16 channel shield with a servo hooked up on servo pin #2 (powered externally). I wanted to add the RTC DS3231 clock that should communitace via I2C, so I plugged the SDA and SCL into the 4 and 5 pins. However, when the RTC is connected, the servo won't move, it starts to move as soon as I remove the two pins. As far as I know, there shouldnt be a conflict of adresses between the shield and the RTC. Any ideas? Chanign the adress to 0x41 doesn't seem to help, the servo won't move even with the RTC pins out.
Below is an example code (don't ask why I have a project wtih a servo and RTC connected haha)
Thanks a lot.
Code: Select all
#include "RTClib.h" //https://github.com/adafruit/RTClib
#include <AccelStepper.h> //http://www.airspayce.com/mikem/arduino/AccelStepper/
RTC_DS1307 rtc;
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41); /chanign the address like this doestn seem to help, the servo wont move at 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)
// our servo # counter
uint8_t servonum = 0;
void setup() {
Serial.begin(9600);
Serial.println("8 channel Servo test!");
Serial.println("before");
pwm.begin();
Serial.println("began");
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
Serial.println("delay");
delay(10);
}
void setServoPulse(uint8_t n, double pulse) {
long pulselength;
pulselength = 1000000; // 1,000,000 us per second
pulselength /= 60; // 60 Hz
Serial.print(pulselength); Serial.println(" us per period");
pulselength /= 4096; // 12 bits of resolution
Serial.print(pulselength); Serial.println(" us per bit");
pulse *= 1000000; // convert to us
pulse /= pulselength;
Serial.println(pulse);
pwm.setPWM(n, 0, pulse);
}
void loop() {
// Drive each servo one at a time
Serial.println(servonum);
for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
pwm.setPWM(2, 0, pulselen);
}
delay(500);
for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
pwm.setPWM(2, 0, pulselen);
}
delay(500);
}