Library Problem With IDE V1.5.1r2 And Due

hi,

From what I see here, io.h seems to be part of AVR toolchain and related to AVR devices peripheral registers.

So, don't expect this to be exactly the same for an ARM based device, read: not part of a generic ARM GCC distribution.

But, similar information is provided here: arduino-1.5.1r2\hardware\arduino\sam\system\CMSIS\Device\ATMEL\sam3xa

Going back to the issue:
C:\Users\xxxxx\Documents\Arduino\libraries\Wire\utility\twi.c:25: fatal error: avr/io.h: No such file or directory
compilation terminated.

This shows that the IDE is trying to compile the AVR dedicated library instead of the SAM one.
The main difference is that all peripheral drivers for the Due/SAM3X are contained into libsam (arduino-1.5.1r2\hardware\arduino\sam\system\libsam) so that they are available to any additional library/applicaiotn and thus don't need to be added into any local folder.

This should not happen regarding the fact you selected the Arduino Due board in the menu, I guess.

My feeling also in that selecting the Due board should aim the library search to the correct files. Since the IDE is an early release, r2, there are still bugs that have to be addressed. Until this task is complete, Due sketch development will be very frustrating. I've tried all my complex sketches in Due mode and none will compile. The error messages relate to library problems that I have no clue as to how to solve. As I said earlier, my Due is going back on the shelf until the situation improves.

Here's a thought. My first error involved a call from twi.c to avr/io.h. Since the board is not an avr then the call in twi.c might be to sam.pio.h. I'm just guessing on that one. Here's a possible solution. Wherever a call to avr.io.h exists, the following directive can be entered. This would have to be entered into the offending file so that it knew which board was being used. Searching for board types found that SAM3X8E is the name of the Due board. Does this idea have possibilities since the IDE encounters calls to some avr libraries.

#if defined(SAM3X8E)
#include <sam/pio.h> // For the Due
#else
#include <avr/io.h> // For anything else before the Due
#endif

I am having the exact same issue. It's clear the Arduino software is not ready for the Due, if you following my comments, you'll see the troubleshooting shows the same code will work with the Mega selected but not with the Due:

http://arduino.cc/forum/index.php/topic,140128.0.html

I hope someone can fix this as it heavily impacts my work withe Due.

My scheme shown above did not work entirely. It did prove that the Due board is named "SAM3X8E" as it looked for sam/pio.h. However, it did not find that file either so the solution will not work.

Arctic_Eddie:

The file avr/io.h contains definitions for registers that are available only on AVR architecture.
If your project needs that include it means that you're using some feature available only on AVR hardware (and should be rewritten to use an equivalent SAM3X feature if you want to make it run on the Due).

One check that you can do is:

remove the #include <avr/io.h> from your biggest project, try to compile it for Mega, and look where it fails: these are the places that needs to be ported.

C

The call to avr/io.h was shown in the compiler error statement as coming from line 25 in twi.c. I added my work-around using the SAM3X8E trick just assuming that sam/pio.h was the equivalent. However, the trick partially worked but sam/pio.h was not found. There are going to be a lot of hardware discrepancies where AVR calls don't work. Since I don't know what the Due equivalent will be, I'll just have to wait until someone else sorts this problem out satisfactorily. There is also a problem with paths in the IDE. When I supply the absolute path to a .H file, it still says it can't find it. Maybe a sketch won't work because it's AVR specific but it should at least find it. All of the #include errors are coming from within included libraries and not my sketch. Some of the substitute files for the Due haven't been created yet so I'm at a stand-still. I'll continue with the Mega and watch the forum for future progress.

Thanks for the help from all contributors.

I understand, but my point was that the avr/io.h equivalent for ARM doesn't exist and its not going to exist**. You'll never find a "sam/pio.h" that works as a drop-in replacement for avr/io.h, because it can't be done.**
> Arctic_Eddie:
> The call to avr/io.h was shown in the compiler error statement as coming from line 25 in twi.c.
This is strange because the Wire library is one of the first library that was ported to Due, and I saw many reports from users that used it successfully.
Are you using the Wire library found in arduino-1.5.1?

My V1.5.1r2 has two copies in the unzipped folder. One is in avr/libraries and the other is in sam/libraries. Both are dated 11/23/12. There is also an original in Documents/Arduino/libraries. I assume the compiler knows which one to use since I've told it to compile for the Due. The same sketch works if I select the Mega board. When I use a more complete path to Wire.h it says file or folder not found.

#include <sam/libraries/Wire/Wire.h>

The compiler is looking for the old version.

C:\Users\xxxx\Documents\Arduino\libraries\Wire\utility\twi.c:25: fatal error: avr/io.h: No such file or directory

The Wire.h file in sam has this in the heading but the compiler is looking elsewhere. Sure seems like lots of users are seeing path errors in the IDE.

  • TwoWire.h - TWI/I2C library for Arduino Due
  • Copyright (c) 2011 Cristian Maglie .
  • All rights reserved.

Arctic_Eddie:
The compiler is looking for the old version.

C:\Users\xxxx\Documents\Arduino\libraries\Wire\utility\twi.c:25: fatal error: avr/io.h: No such file or directory

The IDE prioritize the libraries found in {sketchbook_folder}\libraries. Try to move the Wire folder in sketchbook elsewhere, and the IDE should find the correct library (the one inside sam/libraries).

If I eliminate the one in {sketchbook_folder}\libraries, will the compiler find the right one in sam or avr according to board selection. Will this damage my ability to use V1.0.3 for other boards.

Moving the Wire library from the sketch folder to some other place, eliminates the avr/io.h error. The sketch still compiles when selecting the Mega. However, now I get another error about a missing item, square. Including math.h does not solve the problem. There is still a path problem when selecting the Due.

C:\Users\xxxxx\Documents\Arduino\libraries\PlainFFT\PlainFFT.cpp:143: error: 'square' was not declared in this scope

Arctic_Eddie:
My scheme shown above did not work entirely. It did prove that the Due board is named "SAM3X8E" as it looked for sam/pio.h. However, it did not find that file either so the solution will not work.

Hope this thread is not dead yet....

pio.h is located in this folder:

~/arduino-1.5.4/hardware/arduino/sam/system/libsam/include/

I am also facing mentioned issue, where IDE not compling due to "missing" header files.

I tried also linking pio.h > /avr/io.h but without success....

I'm having the same problem. Is there no library that can be included for the Due that allows for IO pin manipulation?

I've also got this problem, using Arduino 1.5.6.r2 trying to use the wire library with a Due board
I get the
C:\Users\xxxx\Documents\Arduino\libraries\Wire\utility\twi.c:25: fatal error: avr/io.h: No such file or directory
error.

Yet, other people have reported that they can use the wire i2c protocol with a due board. I have noticed that those who resolved the problem were using Ubuntu or some flavor of linux i'm Windows user. Currently i am running this on my laptop running Windows 7.

I need to figure it out.

So far-using Windows 7-the Wire library for SAM runs OK in my DUE (both controllers TWI0 and TWI1). The twi.c file you mention belongs to AVR. That's why is linked with avr/io.h. I know it because the AVR TWI is located under a utility folder unlike the SAM TWI which is under \libsam\source. This happens after import the Wire library using IDE 1.0.X.
Solution: Close your IDE 1.5.X, delete the Wire folder from your ...\Arduino\libraries, open again yout IDE 1.5.X and run your sketch. Regards!

EDIT: If you need to use the AVR Wire library, just run your sketch (you don't need to import the library). This works for me with 1.04 and newer.

Palliser -
Thanks, I read to delete or move, the directory, which i did and it didn't find the wire.h at all. But, now i realize i had about 4-5 ide-sketches open, so closing one didn't release the library. Closed them all and reopened - finally it is now using the due library. You would think the arduino programmers would have taken care of this sometime back as i see this is an old and on-going issue with trying to work with the due (and now Gallileo - people report the same prob).