Hot answers tagged

46 votes
Accepted

Warning when verifying sketch with VS code

Thanks to @Majenko I looked some place new: documented in the arduino plugin of VS Code Arduino Extension there is an option to set an output directory. Note though that according to this it should ...
Uwe Hafner's user avatar
31 votes

Warning when verifying sketch with VS code

To clarify the answer, for those new in arduino world +StudioCode (source: https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino ) The following settings are as per sketch ...
Mirosław Drdzeń's user avatar
30 votes

How to compile, upload and monitor via the Linux command line?

I use the command-line interface to the arduino command. I run it like this: arduino --upload sketch/sketch.ino --port /dev/ttyUSB* There is a page which describes other command-line tools, like ...
Metamorphic's user avatar
14 votes
Accepted

Will a .ino Arduino Sketch compile directly on GCC-AVR?

See my answer here: Classes and objects: how many and which file types do I actually need to use them? - specifically: How the IDE organizes things. I know that at a minimum you have to include the ...
Nick Gammon's user avatar
  • 38.1k
12 votes

Will a .ino Arduino Sketch compile directly on GCC-AVR?

I would just like to add a few points to Nick Gammon's answer: You do not need to rename a .ino file in order to compile it: if you explicitly tell the compiler it's C++ (option -x c++), it will ...
Edgar Bonet's user avatar
  • 42.8k
8 votes
Accepted

How can I have code in a project that won't compile for Arduino?

I would use conditional compilation, like this: #ifndef(ARDUINO) // Non-Arduino code. #endif
Edgar Bonet's user avatar
  • 42.8k
7 votes
Accepted

Is there a way to upload precompiled code to an arduino?

Is there a way to compile arduino code without automatically uploading it, so that I can put the pre-compiled binary up for download on a website? Yes, you can save the .hex file produced by the ...
Mikael Patel's user avatar
  • 7,969
7 votes
Accepted

Using Arduino as a standalone compiler

First of all: The Arduino IDE brings its own GCC compiler. It is a version, that can compile for the AVR platform (don't know, if the standard version is capable of that). When you activate verbose ...
chrisl's user avatar
  • 16.2k
7 votes

Program size optimization

Using the Serial object pulls HardwareSerial0.o into your program linkage. This file defines, among other things, the ISRs (interrupt service routines) associated with the serial port. ISRs are ...
Edgar Bonet's user avatar
  • 42.8k
6 votes

How to compile, upload and monitor via the Linux command line?

Official CLI tool The arduino team is developing a cli client https://github.com/arduino/arduino-cli Announcement: https://blog.arduino.cc/2018/08/24/announcing-the-arduino-command-line-interface-...
Madacol's user avatar
  • 161
6 votes

My Digispark board won't show up in Ports tab in Arduino IDE (OSX)

I don't think it is supposed to. The Digispark briefly connects in "bootloader" mode, which you spotted as "Vendor-Specific Device:". Then after 5 seconds it runs the loaded sketch. If your sketch ...
Nick Gammon's user avatar
  • 38.1k
5 votes

Basic makefile for avr-gcc

The accepted answer is great as it has given me a valuable lesson in all kinds of debugging tools (avr-objdump -D has become a close friend). Namely, the line: ${OBJCOPY} -O ihex -R .eeprom $< $@ ...
Robert Špendl's user avatar
5 votes

How to include <SPI.h> outside the .ino file

See my answer How the IDE organizes things. There is no easy way to avoid having to put an include in the main .ino file, unless you write your own build process (or perhaps use another toolchain). I ...
Nick Gammon's user avatar
  • 38.1k
5 votes
Accepted

How to properly understand verbose compiler error text? For beginner level

As @st2000 said, it's best to start with the first error shown as that error may be causing other errors that will go away once you fix the first one. You should be aware of the difference between ...
per1234's user avatar
  • 4,088
5 votes
Accepted

Project wont compile when I place functions below function calls

You need to declare your function before you use it. So either the whole function body needs to be before the usage, or you must add a function prototype declaration. void myfunction(); myfunction()...
David Jones's user avatar
4 votes
Accepted

fatal error: avr/io.h: No such file or directory

The Due is SAM architecture. avr/io.h is specific to the AVR architecture of the Uno's microcontroller. The compiler will not look in the avr tools folder for that file and even if it did it wouldn't ...
per1234's user avatar
  • 4,088
4 votes
Accepted

Conditional compilation depending on sizeof(double)

The double data type is almost universally 8-bytes long, so you could simply #if !__AVR__ # define HAS_64_BIT_DOUBLE #endif Gcc provides a more specific macro though: __SIZEOF_DOUBLE__, which has the ...
Edgar Bonet's user avatar
  • 42.8k
4 votes

Random "Compilation error: Error: 13 INTERNAL: exit status 1". No clue how to resolve or even what causes this error

The problem with that error message is that you are only reading the very last line. That line says "Oops, it didn't compile". The actual error message occurs before that. You need to read ...
Majenko's user avatar
  • 105k
4 votes
Accepted

How to cut down size of imported DigiKeyboard library

With input from @EdgarBonet, I looked into the functions used and it turned out that the String() function, I used once in my code, takes up about 3kB of space in the compiled program. I ended up ...
emma.makes's user avatar
4 votes

Break a big file into smaller files

This is not the right way to split a big .ino file. You should instead think in terms of functional units, i.e. software “modules” that address specific concerns. For example, if a subset of your code ...
Edgar Bonet's user avatar
  • 42.8k
4 votes

How to compile without adding the bootloader?

Seeing .bootloader section in size output doesn't mean it's really present. It just means the sum of all three is 4152 bytes. You can check the hex file if it contains large block of data at the ...
KIIV's user avatar
  • 4,742
3 votes

How can I make Arduino IDE use Atmel's provided toolchain? (Linux/Ubuntu)

In the directory for the new core create a new platform.txt and give the entry for compiler.path the location of the bin/ directory containing the Atmel toolchain. compiler.path=/path/to/bin/
Ignacio Vazquez-Abrams's user avatar
3 votes

Compiling is slow

I had the same problem until today. Like many answers around the web, the problem seems to come from the anti-virus. My setup is Windows 10 x64 with a SSD and I use Windows Defender as the AV. I ...
NickB's user avatar
  • 131
3 votes
Accepted

How to include <SPI.h> outside the .ino file

It seems that I am obliged to include SPI.h only from the ino file. But why? And how can I do what I want here? do I have to change IDE? The background is how the Arduino IDE pre-processor works ...
Mikael Patel's user avatar
  • 7,969
3 votes

No power_usi_disable() on Arduino Uno

The Arduino Uno does not have a USI peripheral. Thus, you cannot disable the power of the (non-existent) USI, and there is no power_usi_disable() function. Solution: remove the call to ...
Edgar Bonet's user avatar
  • 42.8k
3 votes

How to change Arduino Nano MODEL_ID

Finally find the solution =) You don't have to change the ID vendor or ID product: it is possible to attribute a permanent name with devpath (where the device is plugged) The only downside of using ...
lestage laurent's user avatar
3 votes

Referencing local libraries from higher dir levels

The problem with a relative path for an include is that it has to be relative to one of the predefined list of existing include directories. This includes: Compiler include locations The Arduino core ...
Majenko's user avatar
  • 105k
3 votes

Why can't my .cpp file have a class of the same name?

#define XYZ class XYZ { }; The first line tells the "C preprocessor" (called before C and C++ compilers) to replace XYZ with nothing everywhere it happens, hence after preprocessing, and before ...
jfpoilpret's user avatar
  • 9,122
3 votes

Efficiency of a cast vs a shift

If you look at the assembly code the compiler produces, you can see it compiles to the exact same thing - when using a constant.: void setup() { .... digitalWrite(_S1, (chan & 2)>>1); ...
001's user avatar
  • 943
3 votes
Accepted

Efficiency of a cast vs a shift

I tried compiling your three snippets with avr-gcc 4.9.2 at the -Os optimization level (standard with Arduino) but without -flto. The results were: The first snippet generated inefficient code: the ...
Edgar Bonet's user avatar
  • 42.8k

Only top scored, non community-wiki answers of a minimum length are eligible