I have had the Galaxy Mars Robot running some time ago but when I tried to compile the sketch I get the error statement.
/Users/anthonypiner/Documents/Arduino/libraries/libraries/SoftPWM/SoftPWM.cpp:41:10: fatal error: avr/io.h: No such file or directory
#include <avr/io.h>
^~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: exit status 1
SoftPWM has been included in the libraries. This is running on an iMac with Arduino 2.3.6.
Could you please specify:
- Which sample code are you running?
- Your detailed operation steps?
The error suggests required libraries may be missing. Please:
- Reinstall these libraries:
- For best results:
- Download the complete code package (Source Code ZIP)
- Open/upload files from the downloaded folder (don’t copy-paste from tutorial)
Please try these steps and share your results.
Hi
Thanks for your response.
I have downloaded the complete package again and re-installed the two libraries required with the same result. (See screen shot). I assumed that it was a missing something from a library but have not found any reference to an avr/io.h: call or file.
Many thanks
Kind regards
Tony Piner
Apartment 7 The Point
Pierhead
Exmouth
EX8 1FE
01395 265025
07860 705022
///balloons.hometown.sparkles
Hi
Gemini gave me a clue as to what the problem was. See below
This error message, “fatal error: avr/io.h: No such file or directory #include <avr/io.h>”, indicates that the compiler cannot find the header file avr/io.h
. This almost always means you’re trying to compile code written for an AVR microcontroller (like those found in Arduino boards) in an environment that isn’t set up for AVR development.
Here’s a breakdown of why you’re getting this error and how to fix it:
Why you’re getting this error:
-
Missing AVR Toolchain: The avr/io.h
file is part of the AVR-GCC toolchain. This toolchain includes the compiler (GCC), avr-libc (which provides standard libraries and header files like avr/io.h
), and other utilities specifically designed for compiling code for AVR microcontrollers. If you don’t have this toolchain installed, or if your development environment isn’t configured to use it, the compiler won’t know where to find avr/io.h
.
-
Incorrect Compiler/IDE Setup:
- Using a standard C/C++ compiler: If you’re trying to compile this code with a generic C/C++ compiler (like GCC for your computer’s operating system, Visual Studio, Xcode, etc.), it won’t have the AVR-specific header files.
- Incorrect include paths: Even if you have the AVR toolchain installed, your Integrated Development Environment (IDE) or build system might not be configured to look in the correct directories for the AVR header files.
-
Not targeting an AVR device: This code is specifically for AVR microcontrollers. If you’re trying to compile it for a different architecture (e.g., ARM, x86), then avr/io.h
is irrelevant and won’t be found.
How to fix it:
The solution depends on what you’re trying to do:
1. If you’re developing for an AVR Microcontroller (e.g., Arduino):
2. If you’re NOT developing for an AVR Microcontroller (and just found this code):
- Recognize that the code is AVR-specific: The
#include <avr/io.h>
line is a strong indicator that the code you’re trying to compile is designed for AVR microcontrollers.
- Don’t try to compile it with a standard C/C++ compiler: It won’t work without significant modification or porting.
- Find an alternative: If you’re trying to achieve a similar functionality on a different platform (e.g., a Raspberry Pi, a PC), you’ll need to find or write code that uses the I/O mechanisms of that specific platform.
In summary, the core issue is that your development environment is not set up to compile code for AVR microcontrollers. You need the AVR-GCC toolchain and your build system (IDE or Makefile) needs to be configured to use it and find its associated header files.
Essentially Arduino was still trying to compile for a previous board why I had been using (Arduino UNO R4) rather than an Arduino Uno AVR wifi board.
Once I had changed this the sketch now compiles.
Many thanks for your help.
Kind regards
Tony Piner
Apartment 7 The Point
Pierhead
Exmouth
EX8 1FE
01395 265025
07860 705022
///balloons.hometown.sparkles
Yes. Before uploading the code, you need to select the correct development board and the correct port number.
Our Mars rover is configured with an UNO R3 board, so please ensure you select the correct board and port. Refer to the screenshot.