PMW 16 channel Shield with RTC DS3231 problem

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
BMarter
 
Posts: 2
Joined: Sun Oct 21, 2018 1:39 pm

PMW 16 channel Shield with RTC DS3231 problem

Post by BMarter »

Greetings,

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);
}

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: PMW 16 channel Shield with RTC DS3231 problem

Post by Franklin97355 »

Try moving the RTC_DS1307 rtc; code below the #include <wire.h> line.

User avatar
BMarter
 
Posts: 2
Joined: Sun Oct 21, 2018 1:39 pm

Re: PMW 16 channel Shield with RTC DS3231 problem

Post by BMarter »

Hi, thanks for the reply,
I tried that but it's still the same. The servo moves only when the 4 and 5 pins have nothing attached to them.

EDIT: Sorry, reuploaded the sketch again and it seems to be working now! Didn't think it would be something so simple

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

Return to “Arduino Shields from Adafruit”