[Solved] SCL SDA communications ruins 12-bit PWM board?

Hi, I have a mege2560 with a Adafruit PCA9685 12-bit PWM board. That board and a RTC clock are hooked up to pins SCL and SDA. Today I wanted to communicated between 2 mega's so I hooked up SCL and SDA to each other with a common ground, loaded my new sketches and actually got the to arduinos communicating exactly how I want them.

While I was doing this my RTC and 12-bit chips were still hooked up. When I was finished I loaded my original sketch again and the RTC was reset and now the 12-bit PWM board doesn't dim the lights, they are locked on full power, 4095. I reset the time on my RTC clock and it still works but the PWM board does not.

Does this sound right? At not point were any wires shorted. I was under the impression I could hook up lots to the SCL and SDA pins.

You have two masters? Perhaps there's some contention when they are not trying
to talk to each other.

Have you got 4k7 pull ups at the moment? That's a good general default, but you
can lower the value if the bus is more heavily loaded (or long wires). 2k2 perhaps?

I'm not sure on the masters, I have 2 mega2560's.

How can I put this.

My regular sketch uses the 12-bit PWM and RTC clock. That sketch works great. The hardware is soldered directly to the mega with 2in wires. I'm in the process of adding communications between arduinos for other features. So I started 2 new sketches a receiving sketch and a sending sketch. The sending sketch sends a number to the receiving arduino. I got those 2 sketchings working together, those sketches were strictly for communicating, just to get it going. During my testing on the 2 new sketches those other boards were still soldered to the mega.

So I accomplished what I wanted to do so I loaded my regular sketch back up and now the PWM doesn't work. Nothing phsyically was changed, I just removed my TFT screen and then jumped the 2 units together for communicating and undid the same when I was finished.

So I don't understand the resistor idea. The PWM board still lights up but I have no control on where its set, it runs at max setting even if I say to run at 0 or off. It's as if the PWM board is ruined.

If it is how did that happen and how can I prevent that from happening, when I'm finished I need to have the communications and use that PWM board.

robsworld78:
I'm not sure on the masters, I have 2 mega2560's.

How can I put this.

My regular sketch uses the 12-bit PWM and RTC clock. That sketch works great. The hardware is soldered directly to the mega with 2in wires. I'm in the process of adding communications between arduinos for other features. So I started 2 new sketches a receiving sketch and a sending sketch. The sending sketch sends a number to the receiving arduino. I got those 2 sketchings working together, those sketches were strictly for communicating, just to get it going. During my testing on the 2 new sketches those other boards were still soldered to the mega.

So I accomplished what I wanted to do so I loaded my regular sketch back up and now the PWM doesn't work. Nothing phsyically was changed, I just removed my TFT screen and then jumped the 2 units together for communicating and undid the same when I was finished.

So I don't understand the resistor idea. The PWM board still lights up but I have no control on where its set, it runs at max setting even if I say to run at 0 or off. It's as if the PWM board is ruined.

If it is how did that happen and how can I prevent that from happening, when I'm finished I need to have the communications and use that PWM board.

I don't think a board can be ruined just by conecting it's SDA and SCL (and ground?) pins. When their adresses aren't called they won't do anything, I supposse when the 2 Arduino talked each other the slave had a different address.

I was thinking maybe a signal got into the PWM board when the arduinos were communicating as they both use the SCL and SDA pins? The test sketch for the board has this.

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

If I set the sketch with 0x41 it does nothing at all, when I leave it as default or type in the default the lights flicker like its trying to dim them. This is the full sketch.

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

void setup() {
  Serial.begin(9600);
  Serial.println("16 channel PWM test!");

  // if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
  // some i2c devices dont like this so much so if you're sharing the bus, watch
  // out for this!

  pwm.begin();
  pwm.setPWMFreq(1600);  // This is the maximum PWM frequency
    
  // save I2C bitrate
  uint8_t twbrbackup = TWBR;
  // must be changed after calling Wire.begin() (inside pwm.begin())
  TWBR = 12; // upgrade to 400KHz!
  pwm.setPWM(0, 0, 0);
    
}

void loop() {
  // Drive each PWM in a 'wave'
  for (uint16_t i=0; i<4096; i += 8) {
    for (uint8_t pwmnum=0; pwmnum < 16; pwmnum++) {
      pwm.setPWM(pwmnum, 0, (i + (4096/16)*pwmnum) % 4096 );
    }
  }
}

I don't understand why I would need to change any addresses when this sketch use to work?

I2C

I2C TUTORIAL

Masters and Slaves
The devices on the I2C bus are either masters or slaves. The master is always the device that drives the SCL clock line. The slaves are the devices that respond to the master. A slave cannot initiate a transfer over the I2C bus, only a master can do that. There can be, and usually are, multiple slaves on the I2C bus, however there is normally only one master. It is possible to have multiple masters, but it is unusual and not covered here. On your robot, the master will be your controller and the slaves will be our modules such as the SRF08 or CMPS03. Slaves will never initiate a transfer. Both master and slave can transfer data over the I2C bus, but that transfer is always controlled by the master.

6 address select pins so you can wire up to 62 of these on a single i2c bus, a total of 992 outputs - that's a lot of servos or LEDs

Post an Address memory map for your I2C devices.
Without that it is doubtful you will get anywhere . (the code would help too)

So I don't understand the resistor idea. The PWM board still lights up but I have no control on where its set, it runs at max setting even if I say to run at 0 or off. It's as if the PWM board is ruined.

Have you tested the PWM bd as a standalone (just arduino and pwm bd) after the problem appeared ?

How do I get an address memory map? I've never had to play with addresses, just hooked them up and they worked. I have tried the PWM board on its own and it doesn't work properly.

Here's an image of my setup. This was never touched during the process, no soldiering was required, I simply removed the screen and used dupont jumpers to connect the arduinos. After I was finished playing with the communications, I removed the jumpers, plugged my screen back in and here I am.

Double check all connections - you've probably done that though.

Is there a chance of static electricity damaging something? You did rewire
everything with the power down? You did connect grounds tegether first?
You wore no nylon clothing and avoided rooms with nylon carpets?

In order to use I2C you need to at least know the addresses. Many devices have a default address. I2C is
address based. Are you saying you are using multiple masters and slaves and have no idea what their addresses are ? Please explain because I'm not understanding how you can be using multiple masters without know the addresses of the masters and slaves.

How do I get an address memory map? I've never had to play with addresses, just hooked them up and they worked. I have tried the PWM board on its own and it doesn't work properly.

4 software programmable I2C-bus addresses (one LED All Call address and three LED
Sub Call addresses) allow groups of devices to be addressed at the same time in any
combination (for example, one register used for ‘All Call’ so that all the PCA9685s on
the I2C-bus can be addressed at the same time and the second register used for three
different addresses so that 1⁄ 3 of all devices on the bus can be addressed at the same
time in a group). Software enable and disable for these I2C-bus address.

So, in other words, you are telling us you didn't read the datasheets ? (or you wouldn't be asking)
PCA9685

That board and a RTC clock are hooked up to pins SCL and SDA.

And what address is the RTC clock using ?
Do you understand what "Address based bus communication" means ?
This isn't a bus you can just jump on and go. You need a ticket to a specific destination .

I have tripled check connections, I never changed anything on the arduino. Soldering iron hasn't been on for a week. I've had my board soldered like that for a month now. I have hardwood floors and a leather couch so no chance of static, my place is not dry as I have 2 aquariums 125g and 40g. I did have grounds connected between arduino before turning them on, all connections were made during power down.

I understand this is an address based bus however what I don't understand is why I need a ticket now when I've been riding this bus for over a month now with out one? I haven't added any more i2c devices, the RTC clock and PWM board have always worked as is. I have no idea what address the RTC clock is using, just the default I take it.

My setup is exactly as the image, no other arduinos, no other boards involved, no breadboard for bad connections, nothing and it worked until the communicating.

I didn't read the datasheet because it was working out of the box and I didn't need anymore out of it. Like I say I'm having a real hard time understanding why it worked for a month and now it doesn't. I could understand if I added another i2c device but I'm not, at least not at this moment.

the RTC clock and PWM board have always worked as is.

Are you using 4.7 k or 2.2 k ohm pullup resistors for SDA & SCL ?

If you say that every device you have mentioned was working with all the other devices for a month and
you have changed nothing, (and I am assuming you reloaded the sketch more than once as well), then
if we rule out static, then the question remains as to whether or not the PWM bd is damaged. Unfortunately, the only way we can answer that question is if you UNDO some of what you have done and
remove all the wires to uC except the PWM board. If you had a DIFFERENT arduino you could simply remove the wires connecting the PWM bd to the uC it is currently connected to and connect it to an UNO or
some other arduino and test it in standalone mode. There is nothing we can do to help you until you have
done that. It would also help if you post a SITREP consisting of simple lines stating the status of this or that circuit/device at the present time so people don't have to read the entire thread to know where you are at
now.
(ie:
SITREP
RTC: WORKING
uC : WORKING (runs everything but PWM bd correctly)
PWM bd: NOT WORKING
etc.etc.etc.

I still believe you have wasted too much time hoping for a miracle and could have better spent the time
tearing your entire circuit apart and rebuilding it one block at a time to test everything in standalone mode. I know how hard it is to undo a lot of hard work building a circuit but the general rule is you
have to work to keep your job. If something isn't working it doesn't belong on your breadboard until it
can prove it can do the job.

I was under the impression I could hook up lots to the SCL and SDA pins.

You can, but not with the power on.

Did you change the wiring at any time with the power connected up?
That is a good way to kill a chip.

Agreed. Hot-swapping jumper connections is courting disaster.

No I'm not using any resistors, I followed these instructions from adafruit to set it up. They don't mention resistors only a capacitor.

I would never solder with a board powered up or make any types of connections without disconnecting power. I'm not new to soldering, I've probably soldered 100,000 joints but I know nothing about the electronics. I owned a two-way radio shop for years but it was simple like replace RF output or an audio amp.

I have redone everything, my circuit can be put together in 5 minutes, there is nothing to it. Just now I removed the RTC board again but this time set an address to 0x41 as per these instructions.

When I load adafruits test sketch with my address it still does the same thing, the LED's just flicker slightly. If I change the address to something else in the sketch the LED's don't respond at all so it is communicating with the board.

I've been reading the datasheet for this board however its over my head for the most part. It does talk about reseting the PWM board but the diagram doesn't make sense. It says

Software Reset I2C-bus address
The address shown in Figure 5 is used when a reset of the PCA9685 needs to be
performed by the master. The Software Reset address (SWRST Call) must be used with
R/W = logic 0. If R/W = logic 1, the PCA9685 does not acknowledge the SWRST. See
Section 7.6 “Software reset” for more detail.
Remark: The Software Reset I2C-bus address is a reserved address and cannot be used
as a regular I2C-bus slave address or as an LED All Call or LED Sub Call address.

However the address in the datasheet diagram (page 8, section 7.1.4) has 8 blocks but my board only has 6 like the image in the chaining instruction show.
datasheet

This is more detail on the reset but I don't know what it says, can anyone break it down in simple terms as in do this do that.

Software reset.
The Software Reset Call (SWRST Call) allows all the devices in the I2C-bus to be reset to
the power-up state value through a specific formatted I2C-bus command. To be performed
correctly, it implies that the I2C-bus is functional and that there is no device hanging the
bus.
The SWRST Call function is defined as the following:

  1. A START command is sent by the I2C-bus master.
  2. The reserved SWRST I2C-bus address ‘0000 000’ with the R/W bit set to ‘0’ (write) is
    sent by the I2C-bus master.
  3. The PCA9685 device(s) acknowledge(s) after seeing the General Call address
    ‘0000 0000’ (00h) only. If the R/W bit is set to ‘1’ (read), no acknowledge is returned to
    the I2C-bus master.
  4. Once the General Call address has been sent and acknowledged, the master sends
    1 byte with 1 specific value (SWRST data byte 1):
    a. Byte 1 = 06h: the PCA9685 acknowledges this value only. If byte 1 is not equal to
    06h, the PCA9685 does not acknowledge it.
    If more than 1 byte of data is sent, the PCA9685 does not acknowledge any more.
  5. Once the correct byte (SWRST data byte 1) has been sent and correctly
    acknowledged, the master sends a STOP command to end the SWRST Call: the
    PCA9685 then resets to the default value (power-up value) and is ready to be
    addressed again within the specified bus free time (tBUF).
    The I2C-bus master must interpret a non-acknowledge from the PCA9685 (at any time) as
    a ‘SWRST Call Abort’. The PCA9685 does not initiate a reset of its registers. This
    happens only when the format of the SWRST Call sequence is not correct.

I should also mention when I was working on getting the 2 arduinos communicating there was no need for me to remove the jumpers between the 2 boards. I had two instances of the IDE running and was able to upload to each board without disconnecting anything. One IDE pointed to port 11 the other 12 and both arduinos were plugged into the computer with USB. So I changed one sketch hit upload and it uploaded to the proper board. Did that about 5 times to get it working the way I wanted. Then I powered down, removed jumpers and loaded up my original sketch.

The Software Reset Call (SWRST Call) allows all the devices in the I2C-bus to be reset to
the power-up state value through a specific formatted I2C-bus command. To be performed
correctly, it implies that the I2C-bus is functional and that there is no device hanging the
bus.

I don't know anything about the software reset but I can read.

The Software Reset Call (SWRST Call) allows all the devices in the I2C-bus to be reset to
the power-up state value through a specific formatted I2C-bus command.

See page 8 of the datasheet I linked previously. As much as you don't want to , you need to force yourself
to read the entire datasheet. Most likely what happened is that one of the registers got trashed or modified
and the regular sketch you load doesn't modify that register. I can't find anything that suggest the registers are EEPROM so turning off the power should erase the ram inside. If it is EEPROM I can't find any evidence of it.

Take a look at page 27 of the datasheet. Think of it this way. If you had bought two of them, you would
have one spare to use for diagnostic tests to troubleshoot the other one. Since you didn't , you can either
post on the Adafruit Tech Support forum (they do respond to posts but it takes several days) or read the datasheet. If you are really lucky someone here can help you find the problem. Never assume a chip is dead until you can prove it.

I've looked over the datasheet, didn't read every word yet but definitely read on the resetting and addresses. I don't understand much of it so its not easy. I don't want to believe this board is ruined because I can't see what would have ruined it and the fact the RTC still works. Now I'm thinking it is address related and this board probably just needs resetting, the fact it can be done has to mean something. I searched the net and found a sketch for resetting addresses or something but the library it rely's on is for a PI. Can this be used in anyway for the arduino?

// * PCA9685 reset
// * Simply turns off all output.#include "pca9685.h"
#include <wiringPi.h>


#define PIN_BASE 300


int main(void)
{
	int fd = pca9685Setup(PIN_BASE, 0x40, 0);

	// If valid, turn off
	if (fd >= 0)
		pca9685PWMReset(fd);

	return fd;
}

I do have another board but I'm hesitant to use it till I was able to figure out what put this board in the state it is. I can't be doing this to another board. Any suggestions on addresses before I hook up another one? I'm not worried about my current setup but I'm worried when I start playing with the communications again. Sure I can remove the PWM board while I do what I need to but in the end I need that board, the communications and RTC.

Why don't you simply connect the PWM bd to your arduino by itself and run the I2C SCANNER sketch ?
I2C SCANNER

If the bd is still working it should return it's address. You should do that with all your I2C devices individually to see if you get two devices returning the SAME address. FYI, if the scanner doesn't seem to
work try changing the serial monitor setting to NEWLINE instead of NO LINE ENDING.)

That should tell you more than you know now.

I do have another board but I'm hesitant to use it till I was able to figure out what put this board in the state it is.

I would start by running the I2C SCANNER with your other bd and then running it with SUSPECT bd. I would also power the pwm bd with 5V from the arduino instead of the 12 V you are using.

When you looked at the datasheet did you see this ?

Operating power supply voltage range of 2.3 V to 5.5 V

Are you running it off 5V ?

The PWM board is being powered with 5v from the arduino, just like the image. I have the mega being powered by high current USB port.

I've been looking for something like that scanner, without the proper keywords its hard to find stuff.

This is tell me a lot, its finding 2 devices? Yet I only have the PWM board hooked up, the RTC and light sensor (irrelevant) has been removed.

Scanning...
I2C device found at address 0x41 ! // this is the PWM board
I2C device found at address 0x70 ! // ?? ??
done

Is there a sketch to reset the arduino bus or whatever it is?

EDIT: If I change the address to 0x40 and run the sketch it says 0x40, so its communicating ok?

EDIT: sorry for the edits, ran the sketch with nothing and it says no devices found so the PWM board is putting out 2 addresses?