New person here....

I have programmed for AVRs extensivly in the past on the stk500 dev board but have been checking out the arduino since it can be mounted and I need that for my projects. From looking at user code it seems that normal C code can be used. Is this true? I assumed it was only functions as I a assumed it was a "scripting" language. If C code is able to be written, do you need to use the setup and main loop routine or can it just be coded in a main program with include files? Can you use #define? How different is it from programming in AVR studio in terms of compiler specific syntax.

Thanks,
John

I think it is basically no difference.

You can #include avr-libc files/classes, but you have to use the setup and loop functions.

Arduino is c++ :slight_smile:

Welcome!

Because the arduino is C++ you can use pretty much all of the core C language although some of the more verbose library functions (such as the printf family) are not supported.

Redirecting has more technical details on the build process

The Arduino documentation does not go into a lot of the gory details because its audience includes non programmers, but you can find more if you need it with some google serchaes.

Oooo....Ahhhhh..... :slight_smile: You win. That hacking page seems a little out there. I tried looking at some of the user code for stuff and I know how to setup the registers and code and all that blah blah blah. I just need something that says hey, this is what the "correct" way is and this is the "arduino" way. Not to bash the arduino, but having those routines seem to mess some stuff up for people used to plain barebones coding style. I just can't find anything that says like where the preprocessor directives would go, or like what the best thing to go in the setup() is. Because looking at user code, they declare and define variables before the setup() and then declare and define variables within the set up. Is anything before setup() still a procedural flow?

I did see something about the loop function about making it loop or run once. Thats nice and easy. What are the functions that are to be used for interrupts? For example when a interrupt is triggered what is the function name for the ISR?

Lemme know if you don't understand anything, I just have so many questions to have answered before I order one. I already have 2 stk500s but you can't mount those on a robot! >_<

-John

You can just use the arduino board with your stk500 and AVR studio if you don't want to spend the time learning something different. I don't believe that there is any tutorials for anyone coming from AVR studio to Arduino as that is not the average user.

john, the arduino hides main(), under the cover is this code:

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

The user is expected to provide the setup and loop functions. The implimentation for the init function can be found in wiring.c This along with the other Arduino core source code files are in the directory: hardware/cores/arduino

mem, that makes a little bit more sense, but then how would one write functions if your scope is only within main? Also where would pre processor directives go? Can someone quickly write up a piece of code as how I would be writing it? Like if you can have preprocessor directives in there then put those in where they would go. And maybe write a dumb function and then call that function.

Since this is C++ how far into the OOB realm can I reach? Am I allowed to make classes? Like maybe an LCD Class, where the pins that the control and data lines are connected be params for the constructor.

Just to give you guys a bit of background, I have been working with AVRs for around 5 years now, I am a junior in college for Computer Engineering, and know more then a handfull of programming languages, C, C++, java, x86 asm, BASIC, PBASIC, etc....So I know what I am doing with this sort of stuff, I am just trying to learn the structure of the code for the Arduino.

Also how would I download code using the stk500? is there an ISP Header on the Arduino or must I remove it from the carrier?

Thanks,
John

EDIT:

Looked at the Duemilanove board, and I see the ISP or "ICSP" 6 pin header. The usb connection looks like an FTDI USB>RS232 chip, does this mean it can be used as a COM port? Are the drivers built into XP?

Or are these all questions better suited for the freaks forum? ::slight_smile:

http://arduino.cc/en/Hacking/HomePage

The usb connection looks like an FTDI USB>RS232 chip, does this mean it can be used as a COM port? Are the drivers built into XP?

Yes, it is a COM port, a virtual one. You'll need to download FTDI drivers. Found here: http://www.ftdichip.com/Drivers/VCP.htm

Lots of code examples for C++ classes (and preprocessor directives) in the library code. Look in the directory hardware/libraries

Preprocessor directives work as expected in external C++ files like those libraries, but are a little different in a sketch because the build process does some auto-prototypeing and include core arduino headers – this sometimes does some unexpected things to code that goes beyond the standard arduino constructs.

The build process is documented in a page linked in my earlier post. You can look at the resultant code by using a utility call avr-objdump (its in the hardware\tools\avr\bin directory) google should yield more info on how to use it.