Hot answers tagged

18

The part of the code on an ATmega core that does setup() and loop() is at follows: #include <Arduino.h> int main(void) { init(); #if defined(USBCON) USBDevice.attach(); #endif setup(); for (;;) { loop(); if (serialEventRun) serialEventRun(); } return 0; } Pretty ...


14

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 Arduino header file Yes you would need to do that. but beyond that, what would cause a compilation error if compiling said .ino to .cpp file using, say, ...


13

If you want an exact duplication of what the IDE does but want it driven from the command line, that's what Ino is for. The full Arduino build process involves copying a lot of files from a lot of places, and is generally not trivial to duplicate. If you're ready to let go of .ino files and the Arduino libraries, you get a much simpler toolset. avr-gcc ...


11

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 ignore the unusual file extension and compile it as C++. You do not need to add #include <Arduino.h> in the .ino file: you can tell the compiler to do that ...


10

Find the io__.h file for your microcontroller, on Linux it is located in /usr/lib/avr/include/avr, on Windows it will be in a somewhat similar location. Scroll down to the part that says /* Constants */. There are couple interesting macros defined there, FLASHEND being the one you should be interested in. You can use it for example as follows: #if FLASHEND ...


7

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 registers R0 to R31. Your pointer variable points to R0 plus three more addresses above it (a long is 4 bytes in total). So when you write to your pointer you ...


6

Cybergibbons's answer describes quite nicely the assembly code generation and the differences amongst the two techniques. This is intended to be a complementary answer looking at the issue in terms of practical differences, i.e. how much of a difference either approach will make in terms of execution time. Code Variations I did an analysis involving the ...


6

The ATmegaXX8 does not support JTAG, but the ATmegaXX0, 'XX1, and 'XX4 do. The 'XX8 (as well as other AVR families) supports debugWIRE, which allows debugging over ISP. You will need one of Atmel's debuggers such as the AVR ONE! or the Atmel-ICE as well as Atmel Studio in order to use it.


6

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 source, I do not think it has anything to do with electromagnetic interference. In my experience, the internal pullup is perfectly reliable for reading switches ...


6

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 makes no sense to use pipes, as both avr-objcopy and avrdude read their data from files, not from stdin. Furthermore, running these in parallel means that ...


4

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>: 68: 11 24 eor r1, r1 6a: 1f be out 0x3f, r1 ; 63 6c: cf ef ldi r28, 0xFF ; 255 6e: d8 e0 ldi r29, ...


4

return 0 resets the device. Use while(1); instead, to make it wait indefinitely.


4

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 adding those declarations right before the first function of your sketch, a simple workaround is to put all your type definitions before your functions.


3

I can see no specific drawback in using static class members instead of global variables on Arduino. They will be managed the same in the end program. The only difference I can see may arise based on how you design your classes (if design is correct, then no special problem shall arise): Let's suppose you decale a class A: class A { public: void f(...


3

Unfortunately, The Servo library reserves output compare A (OCR*A) on timers 1,3,4, and 5 when loaded on an arduino mega. Each can only have one ISR, so you will not be able to define your own TIMER*_COMPA_vect while you use Servo without modifying the library. However, each hardware timer is equipped with 2 output compare registers. Servo does not claim ...


3

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 13, onboard led #define INP_PB PB0 // pin 8, antenna void setup(void) { noInterrupts(); PORTB |= 1 << INP_PB; /* pullup */ DDRB |= 1 << ...


3

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 section) So i set the arudino IDE to show every command from the compilation to the end of the upload process. The problem lies in the usage of avr-objdump, ...


2

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 program through serial then? (Does the bootloader care which Of Course! I use Eclipse IDE and I programming boards with Arduino bootloader directly in C/C++ ...


2

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, therefore. (Edited to add) When writing code, is it then preferable to using one over the other? I don't really understand your question. You asked about ...


2

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 as well. I found the idea by searching on: arduino __dso_handle This is the webpage that I found that suggested the void * hack.


2

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 this process using an avr-gcc compiler of your own here http://www.wikihow.com/Write-Arduino-Software-in-C But I best recommend you downloading the arduino IDE on ...


2

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) again only $(CXX) is defined And don't forget Makefile needs tabs for indenting target commands (here you have four spaces, but it might be just replaced by SE)


2

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 2 with OCRA as top TCCR0B = _BV(CS01); // CLK / 8 prescaler TIMSK0 = _BV(OCIE0B) | _BV(TOIE0); // Interrupt enabled on OCR0B OCR0A = ...


2

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. Simply add -Os to the compiler command line. This means “optimize for size”, and is the standard optimization option used with Arduinos. avr-objcopy -j ....


2

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'; reason: Permission denied When you are compiling your code the compilation process is trying to rename a file called core.a (.a means a library). I'm guessing it ...


2

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) is the same, but executables specific to the EXP8266's XTensa core are used. There's also a few extra things in there, like building the (optional) SPIFFS image, ...


2

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 resist, be assimilated, fire the IDE and write setup() and loop(). ;-) Once you have something working, the next step is to get rid of the IDE, which is admittedly ...


2

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. According to www.csgnetwork.com/freqwavelengthcalc.html your 10cm wire is picking up frequencies of 750 MHz based on a quarter wavelength calculation. The ...


2

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. See this forum post: Here's the traditional workaround: Tools > Board > Boards Manager Wait for downloads to finish. When you move the mouse ...


2

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 inheritance. Typically you would create your base Fsm class that implements the basic functionality of your state machine control, then overlay over the top of ...


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