Wire library use on NANO board

I was looking for I2C support hoping to not have to write one from scratch linking devices to my NANO boards, and I ran across the WIRE library. However, looking at library description in my help files, I notice my NANO boards aren't mentioned, and since the only pins adjacent to my analog reference are A0 and A1 (analog I/O I assume), this doesn't sound right (I'd expect to see digital I/O pins used). So does this mean I need to modify the existing library or scratch build my own I2D support? If so, I probably should ask for an article explaining the proper way to compile my own source (scratch or modified) into a new linkable library, and install it for my own use. I had hoped to make considerable use of I2C communication.Thanks for any tips. :slight_smile:

Description of my WIRE library in the doc files...

This library allows you to communicate with I2C / TWI devices. On the Arduino boards with the R3 layout (1.0 pinout), the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. The Arduino Due has two I2C / TWI interfaces SDA1 and SCL1 are near to the AREF pin and the additional one is on pins 20 and 21.

As a reference the table below shows where TWI pins are located on various Arduino boards.
Board I2C / TWI pins
Uno, Ethernet A4 (SDA), A5 (SCL)
Mega2560 20 (SDA), 21 (SCL)
Leonardo 2 (SDA), 3 (SCL)
Due 20 (SDA), 21 (SCL), SDA1, SCL1

The Arduino Nano uses the same ATmega328 that is on the Arduino Uno, so it should work. Just like the Uno, SCL is pin A5 and SDA is pin A4 on the Nano.

1 Like

I'd expect to see digital I/O pins used

The analog pins share space with digital pins. The pins ARE being used in a digital mode.

The Nano page, on the documentation tab says:

I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library (documentation on the Wiring website).

1 Like

androidfanboy:
The Arduino Nano uses the same ATmega328 that is on the Arduino Uno, so it should work. Just like the Uno, SCL is pin A5 and SDA is pin A4 on the Nano.

OK! Good info. I note that on my board, AREF is closest to A0 and A1, so I guess the description falls short there.

PaulS:
The analog pins share space with digital pins. The pins ARE being used in a digital mode.

The Nano page, on the documentation tab says:

geeze thanks. I still haven't found that statement, at least not picking through the IDE help tab options. It would be nice if there was some easy way to just load in the library or header file to read its comments. But apparently the IDE can only open "ino" or "pde" files? Seems you have to bring up another environment just to read a "readme.txt. file. Oh well... no sense ranting. :slight_smile: At least I have you guys to show me where things are hidden. :slight_smile:

Speaking of the wire library, (or any library but I guess this is as good a time as any to ask), why in the world can't I pull the wire.h and/or wire.cpp files into the IDE? And the better question maybe, if I can't open these files, what if I wanted to change the way the library worked or make a mod? I guess I could load it all (.H and .CPP) into notepad, start a new blank sketch and paste it all in. But it seems there should be a more organized way to work on a library?

Technically you can put the .cpp and .h files in the same folder as your .ino, then when you open the .ino Arduino will automatically open the .cpp and .h files as well. However, it's much better to have the .cpp and .h files in the Arduino libraries directory, by default under C/Documents/Arduino/libraries/{libraries folder}.

If you go into a library folder you will see the .cpp and .h, and you can open them in a text editor and change them, and if you save it, you can recompile your .ino in Arduino IDE and it will use that edited library.

I note that on my board, AREF is closest to A0 and A1, so I guess the description falls short there.

Why should it fall short there? That's the case on all Nano boards. The SDA/SCL pins stay on A4/A5 because that depends only on the MCU used.

tart a new blank sketch and paste it all in.

From an Arduino (IDE) point of view you're not expected to edit imported libraries. Anyone experienced enough to know how to change libraries is also expected to have a suitable text editor to handle such files installed. For such people the IDE has the option in the preferences to use an external editor. All other people are happy that the IDE doesn't offer to open any file that it doesn't know what to do if you push the compile button.

androidfanboy:
Technically you can put the .cpp and .h files in the same folder as your .ino, then when you open the .ino Arduino will automatically open the .cpp and .h files as well. However, it's much better to have the .cpp and .h files in the Arduino libraries directory, by default under C/Documents/Arduino/libraries/{libraries folder}.

If you go into a library folder you will see the .cpp and .h, and you can open them in a text editor and change them, and if you save it, you can recompile your .ino in Arduino IDE and it will use that edited library.

Really! Thats very good to know! So The IDE re-compiles even library changes automatically? There's no separate "librarian" or "Export" file to tell it what new methods or overloads to export? If so, thats great news to me.

Well I note that under windows, the IDE installed itself completely in my C:\program Files\Arduino\ directory, all as a Read Only tree. Is it possible to copy everything that is not a permanent runtime part of the IDE over to a non "Read Only" folder in, say "My Documents", and TELL it to use that from now on? That way I preserve my reference I in the inevitable event I much something up too badly), and have an area where I'm free to modify things at will.

pylon:
Why should it fall short there? That's the case on all Nano boards. The SDA/SCL pins stay on A4/A5 because that depends only on the MCU used.

I just said the docs fall short there because the docs I found say "the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin". A4/A5 are not mentioned in that sentence, and they are not the closest to AREF pin.

pylon:
From an Arduino (IDE) point of view you're not expected to edit imported libraries. Anyone experienced enough to know how to change libraries is also expected to have a suitable text editor to handle such files installed. For such people the IDE has the option in the preferences to use an external editor. All other people are happy that the IDE doesn't offer to open any file that it doesn't know what to do if you push the compile button.

Please tell me more about this. I see the checkbox to "use external editor", but I don't see how to select or integrate one. I'm thinking of trying that Eclipse plugin anyway, but still want to learn to get the most out of the existing IDE. Thanks!

PeterPan321:
I just said the docs fall short there because the docs I found say "the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin". A4/A5 are not mentioned in that sentence, and they are not the closest to AREF pin.

That is correct for the "R3" layout of the Arduino UNO. Other Arduinos with similar pin layouts (Due, Mega) have the I2C pins in the same place.

On any board with the 328P processor, A4 and A5 are shared with I2C. On the UNO PCB, the extra I2C pins are just paralleled. (You could use them as analog inputs if you like.) But on other processors, the I2C pins are not A4 and A5, so the wiring is different.

On the NANO PCB, the I2C pins are not paralleled. There's no other processor used on that nano-size layout, so I2C is always going to be on A4 and A5.

Well I note that under windows, the IDE installed itself completely in my C:\program Files\Arduino\ directory, all as a Read Only tree. Is it possible to copy everything that is not a permanent runtime part of the IDE over to a non "Read Only" folder in, say "My Documents", and TELL it to use that from now on? That way I preserve my reference I in the inevitable event I much something up too badly), and have an area where I'm free to modify things at will.

That whole tree isn't expected to be changed. If you need to change one of the libraries in there copy it to the libraries subfolder of your sketchfolder and rename it! I don't think you'll see any situation where you have to change the libraries the IDE includes by default.

Please tell me more about this. I see the checkbox to "use external editor", but I don't see how to select or integrate one.

You cannot integrate it more than this. Just open your favorite text editor and change your source code. At the moment you hit the compile or upload buttons in the IDE it will re-read the changed source files and compile them. The Arduino IDE is a very simple IDE meant for the novices in the world of microcontroller programming. If you're an experienced programmer used to other microcontroller IDEs you might get happier with Atmel Studio.