As of May 31, 2023, we have updated our Code of Conduct.

Hot answers tagged

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
  • 36.4k
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
  • 40.2k
7 votes
Accepted

Weird behavior (Couldn't pull the pin LOW)

You are creating a pointer variable, not a normal variable. That pointer variable is, until told otherwise, pointing at address 0x00. It covers 4 bytes. Addresses 0x00 to 0x1F are the internal CPU ...
Majenko's user avatar
  • 104k
6 votes
Accepted

Where in datasheet is the warning about unreliability of reading PINxn?

did somebody come across such case, or I'm the first in the world? You are not the first. I recently got bitten by the very same issue. However, unless you are close to an unusually strong radio ...
Edgar Bonet's user avatar
  • 40.2k
6 votes
Accepted

Own type definition using a struct does not name a type

This is a bug in the Arduino IDE: when converting your .ino file to a .cpp file, it added a declaration for the function ledFactory() before the declaration of the type led_t. As it appears to be ...
Edgar Bonet's user avatar
  • 40.2k
6 votes

Why do I have to burn the code to make it run?

On a Unix shell, separating commands with the pipe character (|) means “run these commands in parallel, feeding the standard output of each one to the standard input of next one”. In this context, it ...
Edgar Bonet's user avatar
  • 40.2k
4 votes

Trouble with Timer 0

Returning from main does not reset the device (it would start up again and do it all over in that case). It calls exit which turns interrupts off and loops indefinitely. 00000068 <__ctors_end>: ...
Nick Gammon's user avatar
  • 36.4k
4 votes
Accepted

Trouble with Timer 0

return 0 resets the device. Use while(1); instead, to make it wait indefinitely.
Gerben's user avatar
  • 11.2k
3 votes

Where in datasheet is the warning about unreliability of reading PINxn?

A test with an Arduino Uno. I used the usb connector to power-on the arduino uno. The led is at PB5, so I have exchanged PB0 and PB5. My test is therefor not the same. #define LED_PB PB5 // pin ...
Jot's user avatar
  • 3,208
3 votes
Accepted

AVR-GCC can't call function located on fixed address

I've tried this code with arduino and it worked (i taught, of course, i can't add the "-Wl,--section-start=.app_start=0xFA0" flag to the compilation process so the function not gonna be moved to other ...
Dankó Dávid's user avatar
3 votes
Accepted

Interleave disassembly + source with avr-objdump

The .stabs section contains debugging info, not actual code. There is no point in trying to “disassemble” it. The -D option of avr-objdump means “disassemble everything, whether or not you believe it'...
Edgar Bonet's user avatar
  • 40.2k
3 votes
Accepted

slower clock frequency than expected on attiny202

Just as a complement to chrisl's answer, if you disassemble the compiled program, you should see that your infinite loop looks like this: 1: sts 0x0407, r24 ; write to PORTA_OUTTGL rjmp 1b ...
Edgar Bonet's user avatar
  • 40.2k
2 votes
Accepted

Using an Arduino board to program an AVR

Do I have to use all the stuff from arduino? A = No! Can I use my own compiler for an arduino board? (GNU-GCC / AVR) Can I use my own IDE for an arduino board? (Eclipse / Atmel Studio) Can I still ...
Avelino's user avatar
  • 242
2 votes
Accepted

Running C for arduino

Perhaps you should look into here https://github.com/arduino/Arduino/wiki/Build-Process Arduino uses avr-gcc compiler. Basically, it is a C compiler. There is an step by step on how to customize ...
Octanic's user avatar
  • 36
2 votes

Since double and float represent the same data type (usually), which is preferable?

See avr-gcc Deviations from the Standard double double is only 32 bits wide and implemented in the same way as float when writing code for ATMega based boards ... They are the same, ...
Nick Gammon's user avatar
  • 36.4k
2 votes
Accepted

Compilation error using arduino-mk on arch Linux (undefined reference to __dso_handle)

I can't say I fully understand what is going on, but it seems that if you add: void * __dso_handle; You may be able to eliminate one of the problems. You might try the same trick with __cxa_atexit ...
dlu's user avatar
  • 1,651
2 votes
Accepted

avr-gcc -D is ignored

You are using $(CPPFLAGS) for *.cpp files but only $(CXXFLAGS) are defined. This should be obvious from command line (if you enable showing executed commands for make) And also: CC = using $(CPP) ...
KIIV's user avatar
  • 4,447
2 votes
Accepted

Volatile variable not updating from timer ISR

You want CTC mode for that to work. As in: #include <avr/io.h> #include <avr/interrupt.h> volatile uint8_t count; void init_100us_tick(void) { TCCR0A = _BV(WGM01); // CTC mode ...
Nick Gammon's user avatar
  • 36.4k
2 votes

Compiling code via terminal

Check out platformio.org it's the best solution out there for command line compiling.
Andre Courchesne's user avatar
2 votes
Accepted

programming arduino in pure c

In file included from led.c:3:0: /usr/lib/avr/include/util/delay.h:95:3: warning: #warning "Compiler optimizations disabled; functions from won't work as designed" You should start by fixing this....
Edgar Bonet's user avatar
  • 40.2k
2 votes

Error compiling code for Arduino/Genuino Uno

The problem is just what the error message says it is. c:\users\hp\desktop\arduino-nightly\hardware\tools\avr\bin../lib/gcc/avr/4.9.2/../../../../avr/bin/ar.exe: unable to rename 'core\core.a'; ...
Code Gorilla's user avatar
  • 5,617
2 votes
Accepted

How does the build process in Arduino IDE work for ESP8266

Does it uses same for compiling programs for esp8266 ?. No. It uses xtensa-lx106-elf-gcc. The compiler has to match the architecture. Most of the build "process" (as in the actions that are taken) ...
Majenko's user avatar
  • 104k
2 votes

How would I include Arduino libraries using AVR-gcc without the IDE?

Since you will end up using a significant portion of the Arduino core library, the easiest path is to accept the idea that you are now writing “Arduino sketches” rather than plain C++ code. Don't ...
Edgar Bonet's user avatar
  • 40.2k
2 votes

Where in datasheet is the warning about unreliability of reading PINxn?

You have made an antenna with the 10cm wire and are receiving radio waves which is translating to voltages on your input pin. This is why you don't have the same trouble when the wire is not connected....
sa_leinad's user avatar
  • 3,128
2 votes
Accepted

Error Compiling sketch for Arduino Uno(ld return 1)

This is a bug in the compiler (linker) used by the Arduino AVR Core. It's not because of a bug in your code, and there's not much you can do about it except using a different version of the AVR Core. ...
tttapa's user avatar
  • 1,300
2 votes
Accepted

C++ State Machine / Wpmf-convesion

A pointer to a member function is not allowed in C++. GCC can allow it, but moans at you because it's non-standard. In C++ the normal way of dealing with the kind of thing you want is through class ...
Majenko's user avatar
  • 104k
2 votes
Accepted

AVRdude does not read the FUSE byte values correctly

A couple of things. That you can't change fuses from the bootloader and that optiboot can't report fuse values correctly, even if you change them. No self-programming of fuses A bootloader can't ...
timemage's user avatar
  • 4,729
2 votes
Accepted

Why my arduino board does not blink properly?

There are a couple of issues here. One of them has already been raised in a comment: int main() { - ddrB = (port_type) 0x20; + *ddrB = (int8_t) 0x20; while(true) { The more ...
Edgar Bonet's user avatar
  • 40.2k
2 votes

How to pass non-static class member to callback on avr platforms?

You can't. On the AVR platform, PubSubClient::setCallback() expects a raw function pointer as a callback, and that is what you have to provide. A static method is equivalent to a raw function, a non-...
Edgar Bonet's user avatar
  • 40.2k
2 votes
Accepted

Do I need to use resisters and ICes for specific sensors.What if I dont use it,Will it impact my arduino board some how like making it useless &faulty

Both images, that you included, show breakout boards. They are circuit boards (PCB - Printed Circuit Board), which contain all the components, that are needed to connect the corresponding part (in ...
chrisl's user avatar
  • 15.3k

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