Hacker News new | ask | show | jobs
by inportb 5348 days ago
I don't know, but I'd love to hack on an Arduino in C. Or Python, if people want to be noob-friendly.
6 comments

Arduino is C++. Plain and simple. Just like Processing is java.

the arduino GUI just adds some lines in front of your code, and passes it over to avr-g++ along with some flags.

It links the whole thing to what it calls "arduino cores" and of course the additional libraries. You can find all that stuff inside the Arduino folder (or on macosx inside the Arduino.app) in the Resources/Java/hardware/arduino/cores/arduino folder. After that, it just does:

int main(void) { init(); setup(); for (;;) loop(); return 0; }

The one thing that is slightly annoying with arduino is how terribly inefficient the libraries are. For example, digitalWrite is like half a gazillion cycles (I remember counting, it was well in the 3 digits), while it's one cycle if you use the normal approach (port |= _BV(bit)). Also, the initialization code snips one timer interrupt from you, which can be annoying as well. The way around that, because I actually like the fact that I can just reuse some library for whatever chip is around (something that is definitely not common in the embedded world) is to just remove the call to init() in the main.cpp file.

The rest is really just C++, with all the avr includes and co available. You also just need to dump whatever source you have available into your library folder as well.

A good guide for BSD users is here:

http://arduino.cc/playground/OpenBSD/CLI

Most of the non-IDE toolchains I've encountered were horrific monsters, including several TextMate bundles. I wonder how worthwhile it would be to create a simple wrapper a la dotcloud's deploy utility, or Rails' initial project build.

It's a well-obscured secret, but if you write C and feed it to Arduino, it will compile and run just fine. The Arduino language is just a nice C api and the IDE just calls avr-gcc in the background.
Well, there's nothing stopping you from using GCC to target the AVR chip directly. As for Python, what about this project: http://code.google.com/p/python-on-a-chip/
Though C++ is the "normal" language, typically you only use a C like subset. 1kB of RAM doesn't go too far in STL.

Likewise, Python isn't going to go far in 1kB of RAM.

But there is hope! The newer Arduinos have 2kB of RAM!

actually the STL can be quite useful sometimes, it definitely allows you tight control over the memory layout. I don't want to go too far into something I don't know that much about (the STL, which I actually avoid due to more mundane issues of often not being able to compile libstdc++ for my embedded targets :), but I found templating extremely useful when tackling embedded programming.
If you'd like something with more of an Electrical Engineering bent, nerdkits are pretty good, and they use the same chips. They still have a bootloader, but other than that it seems to be raw C, bitbanging, interrupts, all that sort of thing :)
gcc is used to program naked AVR chips directly. See avrdude.

But really, whatever language mutant they use for Arduino, it's very noob-friendly.