Close

Change to Sample Uploads

A project log for Drum Master

Electric drum set based on Teensy 3.1 and Audio Board

the-big-oneThe Big One 12/28/2015 at 06:008 Comments

Since I started, I had based my sample uploads on @Paul Stoffregen's sample code, where he copies files to the SPI Flash memory from an SD card. This works fine, but it was annoying that I needed to keep removing the card from the Teensy board, putting it in the computer (via an adaptor), copy files onto it, unount + remove it, and then put it back in the Teensy. I was worried that I would damage either the SD card or the socket. Furthermore, it meant that I needed to keep the cover off, since I needed access to the guts.

I finally got sick of it, and spent most of yesterday writing a serial based sample uploader.

I have a simple Python command line client that lets you select the files to upload (bash globs work). There is a menu option on Drum Master which puts it into serial listening mode, either with or without first formatting the flash. Formatting is slow, but works best when uploading many samples, since deleting from flash doesn't actually recover the space; however, if you are only upload MAPPINGS.TXT (the file which defines kits and maps samples onto them), you can quickly do so without formatting.

As an extra bonus, I copy the files directly onto flash from the serial port, so I don't need to use an SD card at all.

The protocol is very simple, with a start byte, a field end byte, and an escape byte. There are three fields which need to be sent: the filename (A-Z,0-9, period, underscore), the size (32 bit integer, MSB first), and the actual binary data (with any start bytes escaped).

The Teensy serial port runs at full USB speed of 12 Mb/s, which with overhead and processing time gives me a real world 250KB/s throughput. This means that uploading the entire 64MB takes about 4 minutes. There is another 2 minutes spent in formatting the card, for 6 minutes in total. While this is a bit longer than it took to copy files to the SD card, this process requires no user intervention once started, so I don't need to babysit it. Also, uploading only the MAPPINGS.TXT file can be done in seconds, whereas it would take almost as long as uploading an entire set of samples in the previous method.

(Also, as an update to my previous log entry: I ended up discarding the 5v linear regulator hack, and just got a real 5V wall wart - now there are no brownouts, and the regulators on board are staying nice and cool.)

Cheers

Discussions

Craig Hissett wrote 01/07/2016 at 13:29 point

Awesome update mate!

  Are you sure? yes | no

Paul Stoffregen wrote 12/28/2015 at 11:51 point

If you'd like to contribute this for others to use, I'd be happy to add it as one of the examples in the SerialFlash library.  Or if you'd prefer to publish it yourself, I could add a link in the readme file.

  Are you sure? yes | no

The Big One wrote 12/28/2015 at 17:10 point

I would be happy to create a sample with this same approach... however I am not sure that it would be suitable as a sample, since it requires an external python program with some extra modules (pyserial), as well as a basic knowledge of command line usage.  I guess it really just boils down to what external dependencies you are willing to have for examples; so far the ones I have seen are very much self contained, which makes perfect sense for example code.

Furthermore, the python program has only been tested on Debian Linux, running python version 2.7.  I have no reason to think that it would not work on other platforms, but for my case I really only care about Linux.

Anyway, the code is on my github account (https://github.com/thebiguno/microcontroller-projects/tree/master/projects/drummaster/rev2); specifically, the Teensy code to receive the files is at https://github.com/thebiguno/microcontroller-projects/blob/master/projects/drummaster/rev2/src/menu/LoadSamplesFromSerial.cpp and the python program to send them is at https://github.com/thebiguno/microcontroller-projects/blob/master/projects/drummaster/rev2/python/drummaster-uploader .

If you have time, please take a quick look and see if you like how things are done.  If you feel that it would be useful as an example, then let me know and I would be happy to make an Arduino-style sketch.

Cheers

  Are you sure? yes | no

Paul Stoffregen wrote 01/06/2016 at 22:39 point

Yes, I believe some people will use it.  Quite a good number of people who use Teensy and Arduino are very familiar with Python and command line usage.  Not all, but certainly a substantial portion.  Even when other ways exist (someday I'm going to add MTP protocol), there's always a pretty good number of more advanced people who like to automate things with scripts.  I'm they'd find your code and Python script useful.

Some other libraries have accompanying programs.  In Arduino's newer library spec, they recommend putting those things in an "extras" folder.

If you're willing to turn this into a .ino version, I'd be happy to include it as one of the examples with the library.  Please put your name, a link to here or github or other contact info, and the open source license of your choice at the top of the code.  I want you to have full credit for your work!

  Are you sure? yes | no

The Big One wrote 01/06/2016 at 22:59 point

Cool, will do.

Cheers

  Are you sure? yes | no

The Big One wrote 01/07/2016 at 06:21 point

Hi Paul,

I have just completed the example code.  It is on my GitHub fork of SerialFlash.  I don't think that I can make a different pull request since the CS pin one is still open... feel free to just grab the two files from my repo if that is easier.
I have tested it using the Teensy Audio board with flash soldered on, and it appears to work fine.
Since the serial port is being used for data transfer, it can't be used for debugging messages.  I flash the pin 13 LED instead.  1Hz flashes while formatting, followed by 1 second of 10Hz flashes when completed, then solid on while the python program is uploading.  When the python program is finished the light turns off.
Let me know if you have any questions / comments.
Cheers

  Are you sure? yes | no

The Big One wrote 01/07/2016 at 15:51 point

Looks good, thanks.  I see you also implemented the CSPIN selection - sweet!  I'll give the new code a try later on when I have some time.

Cheers

  Are you sure? yes | no