Reading back from Serial.print

Hi all,
very new to Arduino. I am wanting to read data from an SD card file, which I have managed ok, but there is more data than can be held in the Arduino memory. Is there a method of reading a section of the file (maybe line by line), writing/printing this using serial.println to the serial monitor and at the end of the file - re-read this data back from the serial monitor at will, so I can then act upon it. I really need ALL the data from the file before I start processing it.

Thanks for your help.

Is there a method of reading a section of the file (maybe line by line), writing/printing this using serial.println to the serial monitor?

When you read data from the SD card you do so one character at a time. It is up to you how much you read before pausing.

However, if all you want to do initially is to print it on the Serial monitor it does not all have to be in the Arduino memory at the same time merely once character at a time.

And, no, it is not possible to read back data that has been sent to the Serial Monitor.

However as your program knows what it sent it should not be necessary to read it back.

...R

Why do you think you need all your data in memory before you can process it?

Even if it were possible to do what you ask, if you can't hold the entire file contents in memory as you read the data from the file, how do you think you'd be able to hold it all in memory if you read it from somewhere else instead?

geebee95:
I really need ALL the data from the file before I start processing it.

Explain your actual problem. You're thinking in solutions and you might not need all data. Even if you would be able to read it back from the serial monitor, you would still experience the same problem as you state that you need all the data.

Thanks for all your comments.

The reason I need to read all the info in one go is that I am trying to use the data to play music.

It therefore needs to be processed in strict time sequence (ie. the speed of the music)

I think that reading the notes in from the sd card may happen at differing speeds and may not be ready to read from at times. I thought I could somehow read the file in line by line, store it somewhere (serial monitor?) and at the end of the file and the 'START' button is pressed I can then work my way through the whole file in an orderly way at a speed I choose. I have now realised that I cannot re-read from the Serial monitor.

Can anyone think of another way I can read/store/re-read more than the 2k the uno allows?

Thanks again

If I recall my piano lessons from 65 years ago, musical notes vary in the length of time they are held. So, you already have a problem.

How are the notes encoded numerically in your SD file?

Paul

You could set up a buffer in memory, read as many lines as needed off the SD card to fill the buffer, then start playing the music. As the music plays and the buffer empties, at some point you read more data off the SD card to refill it. As long as the average read speed on the SD card is faster than the data use by the music player, you should be ok. This is assuming that you can read from the SD card and play music simultaneously.

geebee95:
Can anyone think of another way I can read/store/re-read more than the 2k the uno allows?

Arduino UNO works on 16MHz crystal oscillator, thus quite slow and is not ideal for music files, it even stuck with heavy images (in case of TFT LCDs). So, better to switch to more powerful board like Arduino YUN or Raspberry Pi or you can also use mp3 shields, advanced mp3 shields come with SD card slots.

Thanks Paul David & Jack.

The pattern is actually drum notes and not 'musical' notes so the length of each 'beat' is not as important. From the sounds of things it looks like I may have to use a Raspberry Pi or something bigger as suggested.

I was hoping to use Arduino Uno but this looks like it might not be possible. I'm just not sure the timings will work if I am having to do other processing (like topping up an sd buffer etc) I was wanting to just have all the data in front of me so I could read in sequence at a stead rate and fire each drum as required. Hope this makes sense.

geebee95:
Thanks Paul David & Jack.

The pattern is actually drum notes and not 'musical' notes so the length of each 'beat' is not as important. From the sounds of things it looks like I may have to use a Raspberry Pi or something bigger as suggested.

I was hoping to use Arduino Uno but this looks like it might not be possible. I'm just not sure the timings will work if I am having to do other processing (like topping up an sd buffer etc) I was wanting to just have all the data in front of me so I could read in sequence at a stead rate and fire each drum as required. Hope this makes sense.

The length may not be important, but the time between each on is. You don't want to run through the whole file in 10 seconds.

Paul

Hi Paul_KD7HB,

No, the idea was to try and process ALL the data in strict sequence and as you say at a strict but controlled speed. I was worried that reading the info a bit at a time and then processing it (playing that note/beat) the timing would go to pot by having to check if I need to read more data, plus actually reading from the sd card etc, hence why I wanted to read the data as a whole, set the speed and then start playing without doing anything that would alter that timing and ruin the time sequence. I'm beginning to think there is no simple way.

OK. Then turn your timing on it's head. You know how often you need to do something with the next note. How many milliseconds of free time do you have before you need to do something with the next note? Once you know that you can figure out what can be done in that time frame.

Paul

Thanks Paul,

Was hoping for a straightforward way but I'm guessing nothing is simple.

Probably look at Rasp pi.

Thanks for your help.

The advice to use a Pi is only relevant for .mp3 files. Playing music from data (e.g. MIDI) is very easy, even for the slowest Arduino.

What is the data you have and what is your output? Are you actually hitting drums or are you trying to play a .mp3 sample of a drum?

Hi Morgan,

Not playing any actual music. I am trying to create a sort of 'drum machine' that fires solenoids (or something similar) at the correct time. I would have to transcribe each piece of music to decide when to fire each solenoid or combination of solenoids (to correspond to each drum). This is why the timing is critical plus I need to have enough data available for a full, say 5 minute song to play along to.

Hope this is clear

thanks

Ok. Hitting a real drum with a solenoid is what the Arduino is good at.

Look at using MIDI as your data format, although it is more complicated than you need.

I still don't understand the need to read the whole before you play the start.

Read a note, trigger the appropriate solenoid, throw that data away, repeat.

What am I missing?

I still don't understand the need to read the whole before you play the start.

Read a note, trigger the appropriate solenoid, throw that data away, repeat.

What am I missing?

hi Gypsum,

My only concern is that reading from a file as in any form of programming I've ever dealt with can be a relatively slow process and the trigger needs to be done at a precise, regular interval ie. without waiting for the read process to complete. I can imagine it will be difficult to get exact trigger timing whilst having to keep reading from the file after every trigger ( or even using a buffer of x number of notes read from file). I may have to try it out and see but I just wanted to see if there was a way of reading ALL the data beforehand and then processing it sequentially with no other processes running..I thought this would give me the best chance of keeping the 'music' in time.

cheers