For the Arduino Uno "The ATmega328 has 32 KB flash memory (with 0.5 KB occupied by the bootloader). It also has 2 KB of SRAM and 1 KB of EEPROM (which can be read and written with the EEPROM library)." The flash memory is where programs are generally stored. The SRAM is the space used for stack and variable allocations. This isn't much! The largest current model in the Arduino series is the Mega 2560 with 256 KB of Flash Memory of which 8 KB is used by the bootloader, 8KB of SRAm and 4 KB of EEPROM. That would be comfortably enough to run a small O/S
From How is programming an Arduino different than standard C? Arduino is C, except that this is inserted into every program:
void main() {
setup();
for(;;) {
loop();
}
}
That means you can write standard C and it is okay. But you can't blindly use the standard C libraries! The Arduino uses the AVR version of libc. From http://www.nongnu.org/avr-libc/user-manual/index.html
In general, it has been the goal to stick as best as possible to established standards while implementing this library. Commonly, this refers to the C library as described by the ANSI X3.159-1989 and ISO/IEC 9899:1990 ("ANSI-C") standard, as well as parts of their successor ISO/IEC 9899:1999 ("C99"). Some additions have been inspired by other standards like IEEE Std 1003.1-1988 ("POSIX.1"), while other extensions are purely AVR-specific (like the entire program-space string interface).
Unless otherwise noted, functions of this library are not guaranteed to be reentrant. In particular, any functions that store local state are known to be non-reentrant, as well as functions that manipulate IO registers like the EEPROM access routines. If these functions are used within both standard and interrupt contexts undefined behaviour will result. See the FAQ for a more detailed discussion.
From Can I use C++ on the AVR?
Basically yes, C++ is supported (assuming your compiler has been configured and compiled to support it, of course). Source files ending in .cc, .cpp or .C will automatically cause the compiler frontend to invoke the C++ compiler. Alternatively, the C++ compiler could be explicitly called by the name avr-c++.
However, there's currently no support for libstdc++, the standard support library needed for a complete C++ implementation. This imposes a number of restrictions on the C++ programs that can be compiled. Among them are:
- Obviously, none of the C++ related standard functions, classes, and template classes are available.
- The operators new and delete are not implemented, attempting to use them will cause the linker to complain about undefined external references. (This could perhaps be fixed.)
- Some of the supplied include files are not C++ safe, i. e. they need to be wrapped into
extern "C" { . . . }
- Exceptions are not supported. Since exceptions are enabled by default in the C++ frontend, they explicitly need to be turned off using -fno-exceptions in the compiler options. Failing this, the linker will complain about an undefined external reference to __gxx_personality_sj0.
- Constructors and destructors are supported though, including global ones.
- When programming C++ in space- and runtime-sensitive environments like microcontrollers, extra care should be taken to avoid unwanted side effects of the C++ calling conventions like implied copy constructors that could be called upon function invocation etc. These things could easily add up into a considerable amount of time and program memory wasted. Thus, casual inspection of the generated assembler code (using the -S compiler option) seems to be warranted.
The 'standard' programming environment for creating, compiling and downloading programs to the Arduino is the Arduino IDE based on the Processing IDE. While this is fine for small projects, I am not a fan of IDEs and usually prefer to use emacs, especially for larger projects.
Using emacs (or any other editor such as vim) means you have to know what is going on at a more detailed level, and use a suitable toolchain. Sudar at Compiling Arduino sketches using Makefile has built Makefiles for various boards.
Any language can be used to program the Arduino as long as it compiles down to ATmega machine code. One language for which this has been done is Basic - that hoary old language from the 1980s! Apparently Basic has long been a favourite for programming microcontrollers, and well, the Arduino is just another microcontroller on a board. See BASIC programming on an Arduino by Brian Benchoff for more details.
The normal way of using the Arduino is to write, compile and download a sketch onto the Arduino. This will then run on the Arduino until another compiled sketch is downloaded. After a sketch has been downloaded, there is no more need for it to be connected to the PC it came from: it will just run on the Arduino.
An alternative scenario is to keep the PC connected to the Arduino and to run programs on the PC which interact with the Arduino. These programs can toggle switches, read inputs, write outputs and so on, depending on the hardware configuration on the Arduino.
For this to happen, there must be a general purpose program already running on the Arduino, and there must be some protocol for the PC to communicate with the program on the Arduino.
Firmata is both a program to run on the Arduino and a protocol to talk to it. The Firmata program is a standard sketch that you download and run on the Arduino.
There are several systems in which you can program on the PC, talking to Firmata on the Arduino
A larger list is at firmata/arduino and includes Perl, Java, Ruby, Clojure, ... client libraries
Copyright © Jan Newmarch, jan@newmarch.name
"The Internet of Things - a techie's viewpoint" by Jan Newmarch is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at https://jan.newmarch.name/IoT/.
If you like this book, please donate using PayPal