Jump to content

To clarify something that wasn 't pointed out on the show The programming language there is C;...


G+_Lee Crocker
 Share

Recommended Posts

To clarify something that wasn't pointed out on the show...The programming language there is C; nothing more, nothing less. In fact, under the hood, the Arduino IDE uses avr-gcc as its compiler and avrdude as its uploader, both of which you can use directly without the IDE if you choose.

 

An Arduino "sketch" is nothing but a C program, except that they've already written the "main" function for you, that looks something like:

 

    int main(int ac, char *av[]) {

        arduino_standard_setup();

 

        setup();

        while (1) {

             loop();

        }

    }

 

You are expected to fill in the setup() and loop() functions. But if you don't want to use the Arduino IDE, you can do your own main() instead if you want.  Likewise, the IDE links in its own libraries with things like digitalWrite(), which are written in terms of the Arduino hardware pins. If you use avr-gcc directly, you have to write in terms of the chip's registers, so turning on an LED might be more like:

 

    DDRB |= 0x20;

    PORTB |= 0x20;

 

(Pin 13 on the Arduino board is connected to pin "PB5" of the Atmel chip.) Avr-gcc also allows you to write interrupt service routines and use in-line assembly. Finally, the IDE shows you how much memory is being used by your program. This too is available outside the IDE with the program avr-size. On my latest work project, it looks like this:

 

    avr-size -C --mcu=atmega164p testcode.elf

    AVR Memory Usage

    ----------------

    Device: atmega164p

 

    Program:    9682 bytes (59.1% Full)

    (.text + .data + .bootloader)

 

    Data:        572 bytes (55.9% Full)

    (.data + .bss + .noinit)

 

All in all, sticking with Arduino IDE is a great place to start. But realize that you are in fact learning C at the same time, and you can take your code with you when you outgrow it.

 

 

Final note: A Radio Shack near me was having a big sale what with them going bankrupt and all, and I got an Uno and a Relay Shield for about $40. Thinking of making a sous vide rig with it.

Link to comment
Share on other sites

 Share

×
×
  • Create New...