Procedure to implement existing WinAVR C coding....

Just getting started with Arduino, coming off some other micro experience. Before I get too far along, I'd like to get a little guidance...I have a super valuable coding example for a graphics lcd/touch screen I wish to convert for use with an Arduino MEGA. I have some asm and C experience, not a lot, am familiar with headers and such...but what is the general procedure to convert an existing WinAVR program, with all its headers and includes, into the Arduino IDE environment? Can I just call the main.c from within the loop structure and allow its called routines to pull all the necessary headers and includes in on their own or is there something particular I need to do to make the Arduino IDE happy? The example I am converting has about 20 header files, and 4 or 5 called "C" code files....

I understand Arduino generates WinAVR code as its output, so I believe most if not all the code should be transparent to Arduino if I get it arranged in the proper order? Or no???

Thanks in advance

Put all the headers and source files into a director in your sketch directory. The name of the new directory will be the name of the sketch. Rename the main file to the same name as the sketch and change the file extension to .ino (or .pde if using pre-1.0 Arduino).

Rename main() to setup() and add a "void loop() {}" somewhere.

Then try to compile and see what's still broken.

John, thanks for the notes, am in the process…next question…my lcd example compile is hanging up on a data file include, which contains the graphics for a picture…it is called “penguin.xpm”…even though I added it to the library, added it as an #include, the compiler for some reason doesn’t locate it…I did notice when I added this particular file to the project, it automatically placed it into a “data” subdirectory. But despite this, the compiler hangs, says the file doesn’t exist…I also tried copying the data file into the main sketch directory with all the other files. No luck.

So…is there a default naming convention I need to change the data file to…or is this some flash bug in the compiler? OR am I doing something else wrong ? :slight_smile:

Hmm...what a quagmire....the farther I get into compiling, the more includes get pulled in from WinAVR's libraries, the more errors are found. I think I fell into a swamp.

So, I either must start over with Arduino, using its own conventions slowly building up, reinventing the wheel so to speak, or jump over to WinAVR and stay there.

Has anybody else been in this predicament??

How was the penguin.xpm file included in the original program sources?

It was included in the standard way: #Include "penguin.xpm" or whatever its name was...the compiler threw an error that it couldn't find it. I renamed it with a dot h extension, that got me further past the error...but then ran into all kinds of bugs with printf, and other routines...became a spaghetti of indecipherable (at least to me) errors. I had to walk away from it for awhile. ugh.

Because a single syntax error can cause a cascade of error messages it is generally best to fix just the first message and then re-verify.

Right, that's what I corrected, along with a pile of previous problems, each correcting its own cascade of errors. Got past the above one, and once all the includes were fully found and read, all hell broke loose. Trying to implement GLCD's new lcd code package now, at least I will start with something that actually compiles.

Progress...

John, thanks for the posts, they did help. I progressed through the massive GLCD project to try and implement that, but it is so awfully complex with way too many headers and includes, with a thousand places to go wrong, I gave up on it. I went back to the first example we discussed above, and figured it was a small working example (https://github.com/vsergeev/embedded-drivers/tree/master/avr-lc7981) originated for avr C, I might as well go back and see what I can do. Given that I am unfamiliar with the Arduino's error messaging, and first attempts at compiling with the usual setup conventions were unsuccessful, I decided to try this....I copied and pasted every dang include file into the main ino file and deleted the originals...compiled the lumped file and that compiled successfully! Now I can proceed to adjust for my wiring, and soon try it out. I do wish the author would respond to requests for information, but I guess we can't have everything in this world.

Why do you programmers feel the need to make everything so spread out and complex? ;-)