I am trying to switch a led on using my adafruit I2C 16 channel 12 bit controller. I am having problems with writing the code for it. I have read the wire library and I still can’t get my I2C device working. My main issue is trying to find out the Adafruit address names. I assume addresses is the name of the adafruit pin outputs, am I right? I check the dataset and tried using various addresses from there, but nothing has worked yet. How do I find out the individual pin names? Here is my code
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
void loop()
{
byte x = 4000;
byte slave = 8;
Wire.beginTransmission(slave); // transmit to device #4
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
delay(500);
}
Any help would be greatly appreciated. Cheers, Ashvin.
I assume addresses is the name of the adafruit pin outputs, am I right?
No. Names (like your name) and addresses (like where you live) are completely different things.
There is an I2C scanner sketch that you should find and run. It will tell you the address of any I2C device properly connected. No addresses == hardware problem.
Alright so I have done the I2C scanner and have determine that my I2C device is - 0x40. But the PCA9685 has 16 channels, so how do i write to the individual channels ?
See the datasheet, section 9 http://www.nxp.com/documents/data_sheet/PCA9685.pdf
You will send at least 3 bytes out over the I2C bus - the chip's I2C address, the data register being accessed (to select a channel), and the data (ex brightness) to go into that register.
Look around, there is probably a library to do this for you.
Personally, I would just write the data explicitly, I like to know what my code is doing.
Yea, but the problem is I cant seem to find the names for the Individual outputs. I want to control 16 different Led lights. So I want to send them different messages. Also I want to learn this I2c method. Can someone just show me one example of sending some information to the first Channel ? I hope its not too much to ask. Cheers, Ashvin.
It has example programs that include dimming LEDs.
If you want to find out in detail how it works, then look in the .cpp file. There is a method called PCA9685::writeLED(int ledNumber, word LED_ON, word LED_OFF) which has the low-level I2C calls and shows how the individual output pins are addressed. If you look at that in conjunction with reading the PCA9865 datasheet, it will hopefully become clearer.