Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: How to receive big sysex dumps and save to SD. Not enough RAM to store as a buffer!

  1. #1
    Join Date
    Jul 2019
    United Kingdom

    How to receive big sysex dumps and save to SD. Not enough RAM to store as a buffer!


    I want to receive a big midi SysEx file (approx 300,000 bytes) and have my Teensy 3.6 save it to the onboard SD card. There isn't enough ram to store it between receiving it and saving it to the SD, so I tried to write it on the fly as each byte arrives. The incoming data got corrupted though, I think because I was using serial port 1 and that shouldn't be used at the same time as writing to SD (wish I'd known this earlier or I could have designed my hardware using serial3).

    So I tried USB serial instead. I can receive smaller dumps ok using usbMIDI.getSysExArray() and then save them to the SD, but my big dump is too big for RAM. Is it possible to read individual incoming bytes and store them to the SD as they come in? Will this be fast enough? How can I read individual bytes as they come in over USB? I know how to do this with DIN midi ( if (Serial1.available()) {.....dumpByte =; etc.) but how can I do this with USB?


  2. #2
    Don't bother with individual bytes because writing one at a time to an SD card will slow things down. The best way would be a have two buffers in RAM of perhaps 1024 bytes, and when one is full, start writing to the other one and write this one to the SD card.

    This won't work with USB MIDI though because it waits for the full message to be received before it shows that a sysex message has been received, and I don't know if there would be a way round that. USB Serial would probably work in theory, but devices don't use that for MIDI. Sending MIDI over USB isn't the same as sending MIDI bytes over USB serial, as far as I know.

    Reading over serial, you don't have to wait for the sysex end byte, but I am not too sure how to solve the SD/Serial1 issue. If you're not using Serial3, can you run a wire from Serial1 to Serial3 and use that instead?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts