DC motor, angular encoder and sd card

Hi everyone,

This is my first post on this forum and first project using arduino,

Recently I bought an old deskjet printer, and try salvaging it in getting dc motors, linear and angular encoders, buttons...

I want to send command to dc motor from file saved on sd card, the command that I'm talking about is a distance (for example 180 or -502). Each line in the file content a distance.

The problem is when I use the function myFile.read() it reads each char separately, Can you please tell me how can I get the entire number and not char?

Best regards

Read each line of text and parse it with atoi() or similar?

Or hand-parse your string character-by-character?

[ For the purists I use "parse" to mean the combination of lexical analysis and parsing ]

Thanks MarkT

It's a good idea ! I found this function http://forum.arduino.cc/index.php?topic=95303.0 to read each line and I'll use atoi() to extract the number.

But I wonder can this work also with negative numbers?

Yes it handles '-' and '+' at the start correctly.

Thanks!

Hi It's me again,

Yesterday I tried this http://forum.arduino.cc/index.php?topic=95303.0 but it doesn't work or maybe I can't figure out how it works.

Any idea? :cold_sweat:

Do you know other function that can read or get each line of txt file from SD card separately?