"fopen" function help!

Hi,

I have been having trouble verifying code in Arduino, code which works perfectly well as a purely C Eclipse 3-7 program, which uses the "fopen" function to open a text file from the PC's hard drive and then to print the file's contained string to console. The string is simply azimuth information (0-360 degrees) for controlling a moveable signpost. The idea is to use this information to eventually control a servo, through an Arduino Uno.

"fopen" is meant to be included in the stdio library, however the error I get when verifying code is "'fopen' was not declared in this scope".

I have no Uno connected up as of yet, and was hoping to simply test my file-opening-and-printing code before modifying it to be a servo control. It could be that it just isn't possible to print to console like one would with another C development environment.

I am a complete beginner with Arduino, and not much more experienced with C itself, as you can perhaps tell.

Any help would be appreciated greatly.

Thanks

which uses the "fopen" function to open a text file from the PC's hard drive

I have no Uno connected up as of yet

When you do get one, look carefully for the hard-drive. Real carefully.

What PaulS is trying to tell you, :) is that there is no way for Arduino code to open a file on your PC, and there is no where to store a file on an Ardunio board without something like and SD card shield.

If you want Arduino to read a file on your PC GoBetwino can probably do it for you, as long as your Arduino and your PC are connected. If you want the file to be "on your Arduino" you need some kind of storage device attaced to your Arduino, like an SD card.

You should not expect to take C code from other environments like Eclipse and run it directly on Arduino, remember that Arduino has no disk, no screen, no keyboard, and very limited memory.

This is one of the toughest hurdles to embedded systems programming, for those who are used to coding on a desktop computer. There is no operating system, no unlimited virtual memory, and no massive set of libraries available for the asking.

You don't get the stdio library, and you don't get a kernel underneath to support it, and as PaulS indicates, you can't hook a hard drive to it anyway.

Try writing your code with nothing more than getc() and putc() (or read() and write()). stdin and stdout on your computer is replaced by a bidirectional serial port on the arduino. If you need data, get it from the serial port or stick it in memory. Memory will run out quickly, so you may have to store things in PROGMEM or flash...

-j

arnum91: Hi,

I have been having trouble verifying code in Arduino, code which works perfectly well as a purely C Eclipse 3-7 program, which uses the "fopen" function to open a text file from the PC's hard drive and then to print the file's contained string to console. The string is simply azimuth information (0-360 degrees) for controlling a moveable signpost. The idea is to use this information to eventually control a servo, through an Arduino Uno.

"fopen" is meant to be included in the stdio library, however the error I get when verifying code is "'fopen' was not declared in this scope".

I have no Uno connected up as of yet, and was hoping to simply test my file-opening-and-printing code before modifying it to be a servo control. It could be that it just isn't possible to print to console like one would with another C development environment.

I am a complete beginner with Arduino, and not much more experienced with C itself, as you can perhaps tell.

Any help would be appreciated greatly.

Thanks

The idea is to use this information to eventually control a servo, through an Arduino Uno.

The idea is okay but you're going about it wrong is all.

Getting to data on the PC hard drive needs to be done on the PC and there's a million ways to do that. Your Arduino is connected to your PC through a serial com port. You can code to read and write to that port.

If you know the simple basics of Linux then you can probably get your data using only shell commands and utilities though to tell the truth I haven't worked with those in a long time and would probably use a couple lines of Perl.

If you prepare your data properly you won't need any special code to stream a file out through a com port whether you run Linux or M$-Windoze. Your Arduino sketch can feed file names and more to your command line, you have a lot of flexibility there and your Arduino sketch can use or ignore any data that comes back.

Over 20 years ago, Micro$oft started their campaign to get everyone away from command line and turn them into idiots but it didn't start working until there were people 'born' into GUI-dependence. The only thing easier than knowing the few things it takes to run a system from command line is to click-click-click while knowing next to nothing at all while living in fear and awe of "power users". What a freaking joke! You don't have to be a zen-geek master to be computer literate!