Arm Mbed OS support forum

Reading in data from Sparkfun SD card on LPC 1768

I’m working on a project where I am reading in midi file data and then playing it out on stepper motors. Right now, I am just hard coding the arrays I need into a header file and then using those arrays in the program. The three arrays I’m using are MIDI note values (int), note start time (float), and note durations (float). With this setup, I’m able to get around 700 notes worth of data before the mbed runs out of memory. Ideally, I would like to be able to write the arrays to a file on the sd card and then read it back during the program to avoid having to store it on the flash memory. The thing is, the SD card documentation is kinda all over the place. I just wanted to see if someone could help point me in the right direction to get started on this or offer an example to help. I’m not sure how to format the data going to the sd card and then read it back in a usable way.

Thanks!

Hello,

I do not have experience with MIDI, its standards and so on, but basically it’s just data and because “There are no limits for imagination”… so only Idea

You can store those 3 data arrays in 3 columns in a text file.

Note (int) / startTime(float) / duration(float)
255/0.5/2.5
005/0.5/2.5
055/0.5/2.5

Then just move through the file, read whole line, parse it to the usable values and place it to your motor control function.

  • For floats the c++ has stof
  • For ints the c++ has stoi

BR, Jan

Thanks for the tips. I’m mainly lost on how to even begin reading through the file in the first place. I don’t know which documentation to use as there doesn’t seem to be a comprehensive one for the file system or for sd card systems. Could you point me to an example that shows how to open a txt file from the sd card and then parse through it? I haven’t been able to find anything that seems to work on Mbed os 6.

You need combination of SDBlockDevice and FATFileSystem with File.

Currently I have no actual example for that but I think this old one is useful.
SDCard - Example of using SD card with Mbed OS5
Just try it in this state, and later try to update it to latest Mbed OS. I think it will working.

Anyway the example from FATFileSystem contains all necessary things, I think.
You can replace the default BlockDevice with the constructor of SDBlockDevice, uncomment FATFileSystem and commented-out the LittleFileSystem.

Let me know

BR, Jan

in addition to Jans links, there is an example project on github:

Another idea: can you use a host pc to send the midi data? There is an USBMIDI class that makes it easy to receive midi notes via USB. Then you can use any keyboard or midi sequencer to send the notes.

Hi,

My SMF (Standard MIDI file) player code can be an example. This reads MIDI format 0 data from SD card and send MIDI stream to serial port.
https://os.mbed.com/users/MACRUM/code/eVY1_SMF_player/

Mbed OS 5 version is here: