Hot answers tagged

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 ...


5

Try this: asm volatile("lds r24, %0" : : "i" (&Driver.ISR_param)); The "i" constraint means you provide an integer constant. It can be any integer, unlike the uppercase "I" constraint which is limited to 6-bit positive integers. Addendum: The constraints supported by gcc are listed in the gcc documentation, section Constraints for asm Operands: The "...


4

It is quite right, using that kind of syntax is not allowed. It's a bit of a pain, but it's ok since there is an alternative method - kind of a "trick" if you will. That trick is to use a string, not an array. After all, a string is just an array, it's just handled slightly differently by the compiler. Instead of using {...} use "..." and use the ...


4

I'm used to this way from my desktop C++ programming practice: int array[100] = {0}; I couldn't find any info on whether or not this construct works on Arduino. The = {0} has no actual effect. It is the same as: int array[100]; Uninitialized static / global variables, and variables explicitly initialized to 0, are placed in the .bss section of ...


3

This construct does work in Arduino IDE. In fact, = { 0 } is one of the iconic idioms of C language. It can be used to zero-initialize an object of any type in C. In C++ things are a bit more complicated. It will work for an int [100] array, but in general case you might be better off with = {} initializer to achieve the same effect where applicable. It is ...


3

The GNU cross compilers for Arduino use C/C++ front-ends and meet the language specs. You can expect fully compliant output. "Arduino language" is a misnomer. The Arduino IDE will try to assist new programmers by, for example, automagically discovering library references and inserting the required #includes for you, but the resulting code is C++ and ...


3

Compiler flags are defined in the platform.txt of the board you have selected in the Tools > Board menu. You can also add compiler flags via a build.extra_flags property in the boards.txt entry for the selected board.


3

PIR sensors work fine and are probably easier to program for than ultrasonic sensors. For example, this tutorial on a PIR sensor sold by Adafruit has a datasheet at the bottom that says: Operating Conditions Operating Temperature -20 ˚C to +70 ˚C Storage Temperature -30 ˚C to +80 ˚C Operating Voltage 3 to 10 V at Rs = 47 kΩ You can try to find and check ...


2

Yes, it is possible in the 1.5.+ IDE. while not possible in the 1.0.+ and earlier. Hardware-specification refers to both the boards.txt and platform.txt files. in short the boards.txt file specifies... uno.build.f_cpu=16000000L and the platform.txt uses in the compile commands such as ... -DF_CPU={build.f_cpu} You can your own. There is already a "...


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

I can reproduce your message easily enough: #define max(a,b) ((a)>(b)?(a):(b)) void setup() { int b = 66; unsigned int c = 42; analogWrite (3, max (b, c)); } void loop() { } I get these warnings: /tmp/arduino_modified_sketch_857720/sketch_aug31a.ino: In function 'void setup()': /tmp/arduino_modified_sketch_857720/sketch_aug31a.ino:1:25: warning: ...


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 ...


2

As Majenko pointed out, I should have used a tarball from the official site instead of the repositories. Which makes me wonder why that package wasn't deprecated or something...


2

You could use pointers instead of references. With pointers, you have the separate notions of “constant pointer” and “pointer to constant”. A reference is a kind of pointer coated with syntactic sugar. However, whereas you can have a “constant reference” (equivalent to pointer to constant), I do not know how to declare a “reference with constant address” (...


1

The layout of that library is in a non-standard format with folders that UECIDE doesn't know to look for or how to deal with. The main culpret is the inclusion of big chunks of code in a "clib" directory (why on earth?!?!) which doesn't get included in the compilation. Then on top of that you have header files in there that are referenced both from inside ...


1

Note to the future: (My particular case was a function call with several parameters. One had the max(a,b), and another parameter had an error. It used a different macro, which may have pushed the compiler to flag every macro in the whole call). The message seems like a red herring, given that there is no problem with the max(a,b) macro definition. I ...


1

See Using array init list as temporary in C++11? You can solve it by using const. This compiles: char a[8]; void cpaddr(char target[], const byte *source) { int i; for (i=0; i<8; i++) target[i] = source[i]; } int main() { byte b[] = {0x00, 0x10, 0xFF, 0xCA, 0x00, 0x00, 0xA2, 0x7D}; cpaddr(a, b); cpaddr(a, (const byte[]) {...


1

One thing to be wary of with PIR sensors is that they only detect moving heat. That means that your light would turn on as you enter the toilet, but would turn off again when the sensor fails to detect movement. That will be once you're sat on the toilet and reading the newspaper. To keep the light on you would need to flail your arms around to keep the ...


1

The #line preprocessor directive is used to tell GCC both what the next line should be numbered as and what filename should be reported, and the plugin is not generating them properly. This is therefore a Stino bug.


1

Does #include <avr/somelibrary.h> mean that this is a standard library from either avr-g++ or avr-gcc? As opposed to a standard g++ or gcc compiler? No. It simply means that the compiler should check both its built-in include paths as well as any passed via the -I command line option (or its local equivalent) for a file called "avr/somelibrary.h". ...


1

The UNO is basically just an ATMega328(P). So you can run the same compiled code for the UNO just fine on a bare ATMega328. You don't have to worry about the P versus non-P version. They are basically the same except for some minor differences concerning low power settings. You can just select the Arduino UNO board as you target. Select the avrispmkii as ...


1

There's a couple of fundamental errors in your sketch. Mainly your construction of your class instances: SomeClass classA(); SomeClass classB(); Those are taken as functions that return a SomeClass object, not SomeClass constructors. Instead they should just read: SomeClass classA; SomeClass classB; As for the rest, you are much better off using ...


1

What I want to know is "how do I write a program such that it is considered valid both by the Arduino IDE and g++. See: How to avoid the quirks of the IDE sketch file pre-preprocessing. Disregarding for the moment what the Makefile will look like, the simple answer to your question, as discussed in the above link, is to put everything into .cpp and .h tabs ...


1

By gcc/g++ I think you're referring specifically to avr-gcc/avr-g++. Your arduino code probably won't be considered valid C/C++ code because gcc will try to compile with your PC as the target system. Many of the Macros in "WProgram.h" will refer to inaccessible memory on your target system. Providing you include the header file "WProgram.h" and you build ...


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