Arduino IDE IO

Hello there im new to arduino and to c i personally prefer java. For c im learning hot to do file IO but i have noticed that the arduino ide lack librarys which are something im not familiar with. So my question is is there a way to do file IO with this IDE. what im doing is trying to receive a bit stream from and engine control unit to gauge the rpm of a car, right now im trying to interface with the ECU and i believe i know how but when i finsih the interface im not sure of the data i will receive hence why i want to output to a file so that i may analyze the data i see. Any help would be great. By the way to receive this data i plan on using both an analog read pin and a digital read pin as im not sure which i need so far.

But how can you do file IO if you dont have a file system in the Arduino?
You cant do fopen, fclose and all those things, at least directly, but you can do that through serial, or to a SD-card.

you mean i could save the data on an sd card? How would i do that?

File I/O kind of implies an operating system, which the Arduino doesn't have. You can capture I/O to a file on your computer from the serial connection. The serial monitor is the usual way of getting information from a running sketch on the Arduino.

Also, when dumping data from the sensor to the SD card, you'll most likely run into speed constraints that may seriuosly affect the operation of your logger.

But, looking at how the Serial library is written, you'll have a hard time getting a big amount of data being sent over the wire. Have you considered going below the Arduino language into real C with AVR-GCC and do it from scratch?

Thank you for all your quick replies but i have a new question. The signal im reading in is a square wave a series of highs and lows so if im correct based on the engines rpm the highs and lows will be sent more frequently. Is there a way with the digital inputs to detect how often the signal is changing? Or am i completely wrong? The ecu sends out a bit stream. Do you guys know do i have to convert the bit stream or do i work with the frequency of the highs and lows?

Is there a way with the digital inputs to detect how often the signal is changing?

the pulseIn() function will give you the duration of a HIGH or LOW state. Assuming that the HIGH and LOW pulses are the same length, you can use the duration of one to get the frequency.

If the durations are not the same length, you'll need to know which varies, to compute the frequency from the non-constant one.

lets say they are of same length then could you take the series of highs and lows and divide them into bytes for binary processing? If so this ties into my previous question of wanting to actually be able to see the binary that is created by having it out put to something but with what was said before i am completely lost.

what im doing is trying to receive a bit stream from and engine control unit to gauge the rpm of a car

i believe i know how but when i finsih the interface im not sure of the data i will receive

i want to output to a file so that i may analyze the data i see.

with what was said before i am completely lost.

Well, so am I.

If you know what data you are receiving and how to receive it, then the rest of the issues you list are not relevant. If you don't know what data you are receiving, or how to receive it, then it seems impossible to write the rest of the code to use the data.

So, start with defining what "engine control unit" you are talking about, in as much detail as possible. Perhaps the ECU is outputting data in a known format, and you can make use of that information to capture and use the data.

You are right ive been not very consistent or made a lot of sense this is what i know.
The engine control unit transmits data via CAN bus and it provides me with a bit stream i know how to connect to the ecu and i have a theory as to how to actually acquire data but im not 100% sure if it will work. As well if my theory as to getting the data is correct i know that the bit stream output by the ecu is a square wave.

This is where i am unsure the sensor is to gauge the RPM of an engine and i feel there are 2 ways that this can be represented as the data is in a bit stream of a square wave that is a series of highs and lows right? If so id imagine that the highs and lows are actually binary which can be converted to real numbers ie 0101 = 5 or low high low high.

The other way i believe the data could be sent is the actual number or a real integer number that has a scaling factor and an offset. So far i have not been able to actually find this out.

What i want to do when i actually get a change to get the engine running is hook up to the ECU use the arduino to read in the highs and lows then output that to some file so that i may look at it or even read it into a java program to convert into real numbers.

These are my question then that i really need answered.

  1. Can anyone tell me how to for sure communicate through can bus and receive data
  2. How can i output data to an sd card for analysis
  3. Does any of this make sense cause i am half lost

Also thank you for your patience and help i really appreciate it :slight_smile:

I have one more question if you can data log to an sd card can you not just log to the pc hard drive through the serial port?

I have one more question if you can data log to an sd card can you not just log to the pc hard drive through the serial port?

No. Not directly.

You need some application on the PC monitoring the serial port, and sending data that it sees to a file on the hard drive.-

CAN Bus info:

CAN bus shields:

http://www.skpang.co.uk/catalog/product_info.php?products_id=706

http://code.google.com/p/skpang/wiki/Canbusduino

Here is a library:

http://code.google.com/p/sparkfun-arduino-can-shield-code/downloads/detail?name=CANInterface.zip&can=2&q=

The CAN (Controller Area Network) bus is very well defined and widely used in automotive applications. Do a little reading, you'll find that you can get a shield and code up stuff pretty easily. I have not personally done it but Google quickly found several shields, a library and the specification readily available.

Start with the library, look at the examples. Go from there.