clueless about i2c

Status
Not open for further replies.

Nick1802

Well-known member
hey all im so clueless about how to write for a i2c device.

this is what i have managed to work out from the data sheet
im using a pca9635 to get 16 move PWM pins

Code:
//#include <i2c_t3.h>
#include <Wire.h>

int led = 13;
void setup(){
//  Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, I2C_RATE_100); 
/*  Wire.begin(mode, address, pins, pullup, rate);
    mode = I2C_MASTER, I2C_SLAVE
    address = 7bit slave address when configured as Slave (ignored for Master mode)
    pins = (Wire) I2C_PINS_18_19, I2C_PINS_16_17 or (Wire1) I2C_PINS_29_30, I2C_PINS_26_31
    pullup = I2C_PULLUP_EXT, I2C_PULLUP_INT
    rate = I2C_RATE_100, I2C_RATE_200, I2C_RATE_300, I2C_RATE_400, I2C_RATE_600, I2C_RATE_800, I2C_RATE_1000, I2C_RATE_1200, I2C_RATE_1500, I2C_RATE_2000, I2C_RATE_2400
*/
Wire.begin();

  Serial.begin(115200);
  pinMode(led, OUTPUT);
  
  delay(2500);
  Wire.beginTransmission(0x01); 
  Wire.write(0x00);        
  Wire.write(0x00);
  Wire.endTransmission();    
  delay(500);
  Wire.beginTransmission(0x01);
  Wire.write(0x14);
  Wire.write(0xff);
  Wire.endTransmission();
  delay(500);
  Wire.beginTransmission(0x01);
  Wire.write(0x02);
  Wire.write(0xff);
  Wire.endTransmission();
  delay(500);
  Wire.beginTransmission(0x01);
  Wire.write(0x02);
  Wire.write(0x00);
  Wire.endTransmission();
  
  digitalWrite (led, HIGH);
  }

void loop(){
}

at the moment it does nothing but the led comes on at the end to indicates that its done sending i2c.

i have output 0 and 1 connected to a h-bridge

plz help!!!!
 
Adafruit sells this chip on as a 16 channel servo driver. They have a library to talk to this chip that I would recommend. Unless of course you enjoy reinventing the wheel for educational purposes. Nothing wrong with that either.

The page that I linked to has a link to the library on the bottom.
 
Just to ask the obvious questions, do you have 4.7K pull-up resistors hooked between the 3.3v power rail and each of the A4/A5 pins? Have you programmed any other i2c devices, to make sure your basic i2c setup is correct?

Is your i2c address correct? In the datasheets, the address is 8 bits including the read/write bits, but the Arduino library shifts the bits right one bit for the address to Wire.beginTransmission.

When putting an i2c device on my systems, I always run an i2c scanner to see what the actual i2c address is, and whether it shows up correctly. The i2c_t3 package contains an example scanner that uses the i2c_t3 package instead of the standard Wire functions.
 
Adafruit sells this chip on as a 16 channel servo driver. They have a library to talk to this chip that I would recommend. Unless of course you enjoy reinventing the wheel for educational purposes. Nothing wrong with that either.

The page that I linked to has a link to the library on the bottom.

Thanks headroom,

But I belive I need the PWM to be able to get over 20 kHz as to not make the motorzed fadera buzz.
This option only goes to 1.6 kHz.
But the lib should come in handy I hope.

Just to ask the obvious questions, do you have 4.7K pull-up resistors hooked between the 3.3v power rail and each of the A4/A5 pins? Have you programmed any other i2c devices, to make sure your basic i2c setup is correct?

Is your i2c address correct? In the datasheets, the address is 8 bits including the read/write bits, but the Arduino library shifts the bits right one bit for the address to Wire.beginTransmission.

When putting an i2c device on my systems, I always run an i2c scanner to see what the actual i2c address is, and whether it shows up correctly. The i2c_t3 package contains an example scanner that uses the i2c_t3 package instead of the standard Wire functions.

Thanks Michael,

I don't have 4.7k. But I had 10k so I tryed with the 10k and without. I have to go to the local store and get some. In the morning.

I did read somewhere that it may sometimes be alright if only 1 i2c devise to not have the pull ups.

No I haven't programmed any other i2c as this is the only 1 I have ever gotten.

I have a6-a1 pulled low and a1 pulled high. So I think in hex it is 0x01. I don't understand what the 0x stands for but have seen it on other examples for i2c.

I never noticed the scanner. I will have a look at it when I get home.

Thank you guys
:)
 
It has been my experience that on the Arduino Uno you do not need pull-ups, but on the Teensy 3.0/3.1 you do need them. This is due to hardware differences between the Uno and the Teensy (Uno has internal pull-ups that the library enables).

The 0x prefix is standard C/C++, and it says that numbers that follow are in base 16 (hexadecimal) instead of base 10. If there was a leading 0 but no X, then the number is interpreted in base 8 (octal). So 0x10 == 16.

Note, the resistors must be pull-ups (wired between A4/A5 and 3.3v), and you need separate resistors for each of A4 and A5. The SDA pin of the i2c device is hooked to A4, the SCL pin is hooked to A5, the ground pin is hooked to ground, and the 3.3v pin is hooked to the i2c VCC pin.
 
It has been my experience that on the Arduino Uno you do not need pull-ups, but on the Teensy 3.0/3.1 you do need them. This is due to hardware differences between the Uno and the Teensy (Uno has internal pull-ups that the library enables).

The 0x prefix is standard C/C++, and it says that numbers that follow are in base 16 (hexadecimal) instead of base 10. If there was a leading 0 but no X, then the number is interpreted in base 8 (octal). So 0x10 == 16.

Note, the resistors must be pull-ups (wired between A4/A5 and 3.3v), and you need separate resistors for each of A4 and A5. The SDA pin of the i2c device is hooked to A4, the SCL pin is hooked to A5, the ground pin is hooked to ground, and the 3.3v pin is hooked to the i2c VCC pin.

thanks for the fast reply,

ok so every thing i have wired is right. (expect for the wrong size pull-up's).

when i get the 4.7k pull ups i will post back if it works or not. but i think it is most likely somthing i have missed in the code and data sheet :(

and thanks for the lesson :)
 
1. You are correct that the pca9635 uses a higher PWM frequency but sacrifices in the PWM resolution area. It may still benefit you comparing spec sheets between the two and then see how the library for the pca9635 is written and what I2C commands it uses to write to the different register on the chip. I would not be too surprised if these two chips are very similar in that aspect.

2. Normal speed I2C bus (100KHz and 400KHz) pins can sink 3mA per I2C specificaton. You can simply apply Ohms law to calculate the minimum resistance for a pull-up resistor. For a 3.3 V system 3.3V/0.003A = 1.1K ohm. Below that " in theory" the pin cannot sink thaw 3mA anymore and may not be able to pull the line down to logical zero. 4.7 K is a practical value for 5V systems and should also work OK for 3.3V systems.
 
i think i may have busted the pca chip when soldering it on to a brake out board :(
as even the scaner isnt picking up anything!!! :( :(
 
Status
Not open for further replies.
Back
Top