Go Down

Topic: i2c, wire.h and digital pin problems (Read 2 times) previous topic - next topic

justfred

All,

I've got the Arduino working over i2c to the wii nunchuck and blinkm using wire.h as described by todbot.
http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
Analog pins 2,3,4,5

Separately, I have a 74HC595 working using the shiftout instructions.
http://www.arduino.cc/en/Tutorial/ShiftOut
5v, gnd, digital pins 8, 11, 12

I'd like to be able to send signals to the 595 based on values from the nunchuck.  Problem is, when I plug them both in together and run a program that includes the wire.h library, I get garbage out the pins for the 595, and I don't get readings from the nunchuck.  For this example, I'm not even connecting to the 595 pins from my program.

Any ideas why the wire.h or i2c code would be interfering with the analog pins?

etracer

The hardware I2C on the ATMEGA168 uses the same pins as Analog 4 & 5.  So when I2C mode is enabled, these pins get converted to digital signals for the I2C connection and you can no longer use them for analog.  Since this is how the ATMEGA168 is built, you can't use other pins for hardware I2C.

There were some people working on a software I2C that could use different pins.  Search the forums for this.

justfred

Quote
The hardware I2C on the ATMEGA168 uses the same pins as Analog 4 & 5.  So when I2C mode is enabled, these pins get converted to digital signals for the I2C connection and you can no longer use them for analog.  Since this is how the ATMEGA168 is built, you can't use other pins for hardware I2C.

There were some people working on a software I2C that could use different pins.  Search the forums for this.


Understood, but I don't think this is my problem; I'm using the standard i2c pins, analog 4 and 5; and somehow that's screwing up digital pins 8, 11, 12.  Does "i2c mode" disable/change other pins?

John_Ryan

Quote

Does "i2c mode" disable/change other pins?


No.

And I think the use of A2 & A3 to supply GND & +5v is a waste of two analog pins.

Did you read the comments section.

Quote

I was having trouble with todbot's example not properly doing pins 2&3 doing power and ground, but I found the missing parts in Laen's Freqin Wii, thanks for that.

// This sets up analog pins 2 and 3 to provide power and ground.
byte pwrpin = PC3;
byte gndpin = PC2;
DDRC |= _BV(pwrpin) | _BV(gndpin);
PORTC &=~ _BV(gndpin);
PORTC |= _BV(pwrpin);
delay(100); // wait for things to stabilize

I think I might end up getting the wiimote for interfacing with puredata or any OSC or midi app. But the wiichuck is great for standalone projects.

Left by C60 on March 5th, 2008


You might want to contact the author direct and explain the weirdness. The "hack" seems to be on a continuous journey of corrections so perhaps what your experiencing is something else he needs to be aware of.

There's no mention of pull-up resistors being used on A4 & A5 either, unless the Wii already has those,  it's something else worth checking.  

justfred

Posted this question on the todbot page.

I'm suspecting power/ground/pullup issues on the i2c (using analog 2+3 for ground does seem odd/lazy, you're right), so that's the route I'll check next.  Actually I have a standard 2d accellerometer I'll probably use instead of the nunchuck for the project I'm working on a the moment, but I'd like to know if i2c and digital pins can play well with each other, for future projects.

Go Up