Hi,
I'm confused with some things:
In arduino hardware page, says that i2c pins are 4 and 5.
In wire library, it says 0 and 1.
Witch one is right?
Are they from Analog, or digital port?
Ivan
On the ATMega328P based boards, they are analog pins 4 and 5. The Wire library, to my knowledge, doesn't mention pins anywhere - where'd you get 0 and 1 from?
Here:
"The port Wire is available on the Wiring digital pins 0(SCL) and 1(SDA)."
Wrong Wire library - the Wiring board is similar, but not equivalent to the Arduino board, and documentation (especially pin numbers) must be changed to match.
The correct reference page is here.
Yes...
So, the problem is in my communication :-/
I tested all possiblities, none worked.
I put the pullup resistors (10k) but nothing happend, i will try egain tomorrow.
Thanks!!!!!
Have you tried adding your own 4.7k pullups? The internal ones are sometimes not strong enough to get reliable I2C.
ivansg:
I tested all possiblities, none worked.
I put the pullup resistors (10k) but nothing happend, i will try egain tomorrow.
Perhaps your code is the problem? Perhaps the wiring? What are you connecting it to? There are too many variables to say.
I have some diagrams and code here:
Ciao,
also pay attention that if you use Arduino Mega or 2560 pins to be used are 20 for SDA and 21 for SCL.
Use this code to discover any I2C device connected (maybe You are not using the rigth device I2C address).
// Verifica indirizzi e accesso a device I2C
#include <Wire.h>
void setup(void)
{
Serial.begin(57600);
Serial.println("Verifica presenza dispositivi I2C");
Wire.begin();
delay(5);
for (uint8_t add = 0X0; add < 0X80; add++) {
Wire.requestFrom(add, (uint8_t)1);
if (Wire.available()) {
Serial.print("Found: ");
Serial.println(add, HEX);
}
}
Serial.println("Done");
}
void loop(void){
}
Ciao,
Marco.
Hi,
The arduino will be the Slave, not master, so i can't discovery from him...
The master uC will be the NXT from Mindstorms. I could connect the NXT with the PIC, but with the arduino isn't working!
What do i do?
I used my own 10k resistor for pull-up.
Is there any solutions?
Ivan
Yes but you could temporarily make it the master to find out the slave addresses. So you are making an Arduino "peripheral" to connect to the NXT is that correct? How do you know it isn't working? The NXT must be sending out some sort of requests to find what is connected. Did you try address 0? That is the broadcast address. It might be broadcasting to ask peripherals which address they are.
Hi,
I put some i²C sensors in the nxt with the arduino board. The NXT just can't find anything, but when i changed the arduino to MASTER, and runned the script to find slaves, he found sucessfuly!
With this test, i saw that the problem is in the NXT software, not in the hardware or even in the arduino.
I²C works, but NXT isn't connecting to arduino.
I saw that the arduino has some pullup pins, can i disable/enable them manualy in the program?
Thanks for helping me!
Hi!
To declare the Arduino as slave, have you declared
Wire.begin(0x04);
Wire.onRequest(requestEvent);
Wire.onReceive(receiveEvent);
0x04 being the I2C address of the Arduino slave, you may take another one.
OnRequest / OnReceived based on what you want.
There's a good tutorial Master Slave I2C by Nicholas Zambetti.
Hi,
With my osciloscope, i could check the i2c com voltage.
The "HIGH" signal is 4.00v, and the LOW signal is 1.8V.
Is that right?
Ivan
No it doesn't sound right. This is what I got with 4.7K pullups:
(The 2-> on the left is the zero-volt level).
There are more images on this page:
Even with 470 ohm pull-ups the low signal was only 0.5V.
The internal Arduino pull-ups (which you can disable by writing LOW to those two pins) are around 50K. They shouldn't be causing that.
I should mention that some documentation I have seen says that the NXT runs at 3.3V not 5V. This could explain your problems. You might need a logic-level converter/buffer for the logic pins (SDA and SCL). Or run the Arduino at 3.3V if that is possible.
What does that mean?
The suplly power of NXT is 5v, and i used it to connect to a PIC 16f877 with 1 pullup resistor of 10k.
The arduino i'm using is 5v too, so what do i have to do?
FUCKKKKKKKKKKKKKKKK
I did it.
I'm so dumb, that i didn't tried without external pullpup resistors...
FINALY!!!!!!!!!
Tanks every body... and sorry for this...
The result:
With the arduino you just don't need to externaly pullup SDA and SCL...
Ivan
Oh, good, you got it working! But you should be mindful of the logic level differences.
Note half-way down he used a Sparkfun logic-level converter to convert 5V logic levels to 3.3V logic levels. This wasn't a NXT I admit, but I would be cautious about pushing 5V logic into a 3.3V device. One day the NXT may burn out.
Maybe someone else can comment further about the NXT and the desirability of what you are doing.
I am guessing here the the pull-ups were pulling up to 5V (rather than 3.3V) which made the levels "too high" so it didn't see the 0V level any more.
Put it this way, your "low" level was 1.8V, right? Now if you add 3.3V to that you get 5.1V. So the NXT was trying to drive what it thought was 3.3V down to 0V, so it was trying to sink 3.3V. Which it did (almost), it sank 5V down to 1.8. This seems to me to demonstrate that it is using 3.3V logic.
This is a direct link to the Sparkfun logic level converter:
Thanks Nick!
Now i can start programming my driver... I removed the 10k resistors from my board and now i can go on.
You will see more in my blog: techlego.blogspot.com, it's in portuguese (because i'm from brasil) but google can translate it.
Thanks!
Hi You can see in my pst the source code for the NXT-arduino communication via I2C, it is working and tested
Also I have notive you use 10K pull-up resistors, you need to chenge this to 82K as it is recommended by Lego, check aso how you are connecting the resistors to the I2C pins
this also was an issue in my test,
please let me know how it works,
All the best