Arduino Nano v3.0 - i2c problem

Hello,

I`m trying to make i2c working on my Arduino nano v3.0 (with a Gravitech.us text on it) bought from ebay (some cheap china clone).

The problem I have is that any call to the Wire.endTransmission() freezes the arduino. I know that this is a "common problem" of Wire library because there are no timeouts in the loops inside. Im using the latest IDE so the address shifting should be fixe din it. I have tried powering arduino from the USB and from +5V pin... But I cant even get i2c scanner working.. so it is trying to call the first address "1" and that is the last thing after which arduino is frozen and no other addresses were checked.

Am I right, that even with NO devices connected to i2c - I must get some response from i2c bus (without freezing arduino)?
Maybe this is a problem of that "clone" ? How can I check if i2c-bus is alive there (assuming that I don`t have an oscilloscope)?

Thanks for your response!

P.S.
I have a MPU-6050 (GY-521) which also do not want to work on nano`s i2c, but I have succesfully got "connected" state with it using the SoftI2CMaster library on regular digital pins. So I mean I have changed i2cscanner code to use softI2cMaster lib and it successfully replied that all addresses are free except 0x68 address (which is correct for mpu-6050).

Sounds like you might not be wiring your I2C clock and data lines to the correct pins for the nano package.
The Uno board uses the A4 and A5 pins, but the Nano appears to use the D4 and D5 pins. This is not documented anywhere I've seen in the wiring reference or the board product pages and while I own a couple of Nano boards I've never run any I2C off them.
The below pinout map for the Nano is the only place I've seen this documented, so if you are not using D4 and D5 give it a try with the scanner sketch and see if that gets you back in business.

PS: actually I'm very confused on this issue of I2C pins and nano boards. From the data sheets for the 328P I don't see how in can be other then the A4 and A5 pins. I guess I will have to test it out on my own nano board (3.1 version Asian clone) and see what i can find out.

Lefty

Here is documented that they are A4 and A5:
http://arduino.cc/en/Main/arduinoBoardNano

the SDA and SCL constants in the IDE have also the same values as A4 and A5..

probably I have found the problem.. A5 is shortened internally to the ground for some reason.. and does not respond to the LED control as I can do with A4.. so it is broken and this is the reason for all of this.

Delphir:
Here is documented that they are A4 and A5:
http://arduino.cc/en/Main/arduinoBoardNano

the SDA and SCL constants in the IDE have also the same values as A4 and A5..

probably I have found the problem.. A5 is shortened internally to the ground for some reason.. and does not respond to the LED control as I can do with A4.. so it is broken and this is the reason for all of this.

Glad you found the problem. Just for helping others that may come across this thread here is what I tested.

I loaded Nick Gammon's I2C scanner sketch:

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  // while (!Serial) 
  //  {
  //  }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

And if run with nothing wired to the Nano board I received this:

I2C scanner. Scanning ...
Done.
Found 0 device(s).

Then I wired a simple RTC modules to the ground, +5vdc, A4, and A5 pins and got this:

I2C scanner. Scanning ...
Found address: 104 (0x68)
Done.
Found 1 device(s).

Thanks a lot!

That means that even with no devices connected i2cscanner must finish it`s work without hanging up!

Delphir:
Thanks a lot!

That means that even with no devices connected i2cscanner must finish it`s work without hanging up!

Yes, but a grounded data and/or clock pin may indeed cause a stalled program.

Btw. Can you check please, if A6-A7 can be acted as an OUTPUT on your Nano ?

Delphir:
Btw. Can you check please, if A6-A7 can be acted as an OUTPUT on your Nano ?

No, the extra two analog input pins do not have a digital counterpart as does the other six analog input pins. It's a Atmel chip limitation not anything to do with the module hardware or arduino software, they are analog input only pins.

The ATmega328p as 3 digital ports : Port B, Port C and Port D.
Only pin connected to a digital PORT can be acted as an Output.
A0 to A5 can be connected either to PORTC0, PORTC1, PORTC2, PORTC3, PORTC4, PORTC5. or to the ADC multiplexer .
Pin A6 and A7 can not be connected to a digital PORT but only on the ADC multiplexer

Datasheet AtMega 328p :
See Block-diagram fig 2.1 page 5

Maybe you know any good library for creating software i2c bus on the digital pins?

An ideal lib can be used as a 1:1 replacement for the native Wire library so this will allow to use any existing device-libraries (e.g. gyroscopes, thermometers, etc.) without any modification.

68tjs:
The ATmega328p as 3 digital ports : Port B, Port C and Port D.
Only pin connected to a digital PORT can be acted as an Output.
A0 to A5 can be connected either to PORTC0, PORTC1, PORTC2, PORTC3, PORTC4, PORTC5. or to the ADC multiplexer .
Pin A6 and A7 can not be connected to a digital PORT but only on the ADC multiplexer

Datasheet AtMega 328p :
See Block-diagram fig 2.1 page 5

This a great answer I finally found. :slight_smile:

Can someone post a piece of code showing how the connection to a specified PORT is controlled?

Is there a version of Wire library where you can change for example I2C action to the pins you want?

I assume these pins can be used as input as well, or...?