How the trial box was made
Just to give an idea - complete different variants are possible (I would not build it like this anymore)

  • A sturdy case: somewhat bigger than normal, enabling viewing board status and attaching to music standards. Just to give you an idea..I'm not getting paid for this, I was just too lazy build my own.
  • 3 off-(on) buttons.
  • 16x2 Hitachi HD44780 compatible LCD display, plus means to fasten it. I used nuts and bolts, Erik used glue and wood.
    2 trimmer potentiometers (take 5 or 10K). One to protect the display and one to control the contrast. In fact you will find that you need both to tune for a convenient readable screen.
  • Jumper wires with female connectors. Anything will do...
    Various ways to solder if needed, see / click on pictures on the right to see what I did.
    I've attached all one-to-one to GPIO, so I've initially used 22 wires (because one wire detached from the display I fell back to 4 bits mode - the dotted lines are obsoleted).
    You can combine the various ground and 5V connectors to save GPIO pins.

Making other types to fit your requirements

The image now supports up to at least 3B+.
Configuration has become easily adaptable, so there are various options without need for hacking:

  • PI audio
  • USB Audio
  • I2S audio = HiFiBerry compatible high fidelity DAC / "audio hat"
  • Pimaroni Audio Pirate (I2S audio, a color LCD and 4 buttons)
  • I2C 7 segment display
  • HD44780 compatible LCD display's (direct GPIO like in the trial as well as I2C). The coding for the I2C version supports a 4 line display.
  • 128x64 OLED display: SSD1306 & SH1106(with buttons) via SPI
  • LED indicators
  • DIN cables support using DIY direct midi.
  • Single-board microcontrollers like Raspberry Pi Pico and Arduino.
    For such boards there are multiple options by nature :-)
    • If board uses serial MIDI, they are "just midi devices". Being at this level of DIY, you could even go for direct connecting the serial interfaces of the two (with optocouplers if still needed) to create an efficient one-box solution.
    • If board uses USB, they may connect to samplerbox using the USB port as a mix of midi device as well as a storage device (similar to a stick/thumb-drive containing samples).
      Samplerbox can't deal with multiple usb storage devices (yet).
      The bypass for now: if a the usb connected usb storage does not contain sample sets, samplerbox assumes "no USB samples" and takes it's samples from SD storage - in short: samples on stick are impossible.
      Royal solution: enhance the microcontrollers logic (they usually have a boot selection button) to disable the storage device behaviour when functional.
I'm now using a PI3-B+ with HiFiBerry and indicator LEDs, boxed in a standard HiFiBerry metal case. So the DIY drilled down to solder extra header (mind to use "Short Feather Male Headers" as the space is limited) on the HiFiBerry and attach two LEDs from an "Adafruit LED Sequins - Multicolor Pack of 5" (they have builtin 100 Ohm resistors, so no extra components necessary). See pictures on the right for inspiration.
I had to remove the plastic cover from the jumper wire connectors to make them fit between header and box; space was 2 mm short on my RCA version. The XLR version will be easier in this respect as well as be more robust.
Things making a man humble: the biggest challenge was to get the LEDs solidly positioned under the heat openings, while keeping those open. Solved with a corner part of a leftover plastic wrapping pinned between two spacers and case and duct tape on strategic points.

On request I've introduced the "USE_48kHz" parameter in the configuration.txt to support 48Khz DAC's not supporting 44100Hz, see FAQ.

Commandline access and debugging

As samplerbox is a stripped but basically normal Raspberry implementation, so:

  • Direct acces via USB-keyboard and display (HDMI or video) if plugged in before poweron, should always work. If it doesn't, either your SD card is corrupt, your PI is not supported (or broken, but that's rare) or the HDMI cable is poor (yes, I've tested that by coincidence).
  • Remote access is possible via available network connections (see GUI usage) with ssh. The ethernet(cable) port is default configured to receive its address from the network it connects to and will publish its hostname(samplerbox) to the dhcp/dns network device.
    - SSH software for console access: PuTTY (etc..) and the linux ssh command.
    - SSH software for file transfer: WinSCP, Filezilla (etc..) and the linux sftp command.
  • In all cases: uid/pwd=root/root gives you access to the commandline of the linux system.
You can stop the automatic running script with
systemctl stop samplerbox

All filesystems are mounted read-only to allow blunt poweroff and removal of USB storage.
To get the partitions in update mode (use what you need):

mount -o remount,rw /
mount -o remount,rw /boot
umount /samples
mount /dev/mmcblk0p3 /samples
  .. and if USB storage is present:
mount -o remount,rw /media

Mind that having a filesystem in RW mode requires the box to stopped with a poweroff (or reboot) command to avoid corruption.
Also mind that the samplerbox's internal clock is reset every reboot, so if you want your file time stamps to be correct, you have to set the date (using UTC time!!) with:

date <MMDDhhmmYY>

Starting the script by hand to see the informational and error messages:

cd SamplerBox
python samplerbox.py

On first invocation it can show GPIO errors you can ignore (the systemctl stop caused the GPIO to remain active). You can stop again with <ctrl-c> and any subsequent starts won't have these GPIO errors anymore as <ctrl-c> is a controlled stop.

To check your topology you can use the script testdev.sh (or just pick the necessary commands from it :-).
If you want to check what your midi device exactly sends, you can use the midimon.py program or the midimon.sh script in the /root directory (for the script the running samplerbox should be stopped). For more specific debugging, you can uncomment some of the print statements in the scripts (or add your own).
Sometimes it is however more useful/convenient to directly monitor the device via your PC. If you don't have a midi monitor available on there, you can use the tools mentioned above (the script only works in Linux and requires "alsa-utils" and "dialog" to be installed, both pretty standard packages). For Windows you might also use the small, free & easy Send SX when full midi dump is necessary.

If your USB stick and/or the contents don't show up in /media, you may have one of the issues described in the first dots of Some goodies.
In these goodies you may find more usefull stuff for debugging.

Enlarge the samples partition

Image on the right depicts the layout of the SD. The exact size figures depend on both image version as well as how your OS/tool counts the bytes (1K can be 1000 or 1024). The slack size can differ significantly as not all SDcards are equal (brand, disabled sectors etc), this is the reason for having this slack space: the image needs to fit on on any SD.

Your SD card is presumably larger than the image, but as the last used partition (samples folder) is NTFS formatted from releases 2021 onwards, it can easily be enlarged without erasing any data.
On windows PC you can use the included diskmanager.
On linux the diskmanager varies per distribution.
As the image is MS-DOS MBR, commandline "fdisk" can do the job on Microsoft, Linux and MacOS - be it not as convenient.

Ofcourse it can be done from within samplerbox, next instructions entered on the samplerbox commandline will make the samples partition use the full SD capacity. If you do this on your pc, adapt the statements to contain the correct device !!.

  • Unmount the partition:
    umount /dev/mmcblk0p3
  • Run fdisk:
    fdisk /dev/mmcblk0
  • Check the SD's content:
    Choose "p", you should see a screen like (sizes may vary):
    Command (m for help): p
    Disk /dev/mmcblk0: 1.9 GiB, 1977614336 bytes, 3862528 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x67e24ed1
    
    Device         Boot   Start     End Sectors  Size Id Type
    /dev/mmcblk0p1 *       2048  133119  131072   64M  c W95 FAT32 (LBA)
    /dev/mmcblk0p2       133120 3459071 3325952  1.6G 83 Linux
    /dev/mmcblk0p3      3459072 3721215  262144  128M  7 HPFS/NTFS/exFAT
    
  • Choose "d" and choose "3" to delete the last partition
     
  • Choose "n" to create a new partition and make next choices:
    1. "p" to create a primary partition
    2. enter the startsector you got with the "p" command (may be the default)
    3. enter required size (or accept the default to use the full disk size)
       
  • Choose "t" to change partition type and make next choices:
    1. accept the default partition (should be 3)
    2. choose "7" (HPFS/NTFS/exFAT)
       
  • Choose "p" again to check...
     
  • Choose "w" to write the changes to disk
     
  • Reboot
     
  • Unmount the partition:
    umount /dev/mmcblk0p3
  • Expand the filesystem to the partition size
    ntfsresize /dev/mmcblk0p3
  • Reboot again
Some goodies

  • In the original samplerbox as well as in my release, samples are loaded from the USB interface device SDA1. USB sticks however don't always have a partition table and in that case the filesystem should be mounted from SDA. You can check your situation with the "lsblk" command. You can change this behaviour in the /etc/fstab. Discussion Differences between /dev/sda and /dev/sda1 gives more detail.
  • If the stick is formatted as exFAT instead of the required FAT32 it will not be found by RPi. This is reported to be remedied by:
    mount -o remount,rw / # remount main partition as read-write
    apt-get -y install exfat-fuse # install exFAT support driver
  • Raspberry PI low level peripherals: GPIO
  • Raspberry.GPIO.Python wiki: RPi.GPIO module basics.
  • The 8-bit code for the LCD display is untested, so you may need How to use character LCD (especially the initialization scheme).
  • Article on the WAVE file format.
  • For connecting the samplerbox via cable without network I use a fixed IP address on the ethernet connection of my laptop in combination with a DHCP server. On Linux just setup the DHCP server for your distribution, for windows I found a free DHCP server.
  • One cheap soundcard occasionally produced nasty noise, mostly when using the function buttons. I bypassed it by adding "dwc_otg.speed=1" to cmd-line.txt. This however made sample loading slooooow and disabled the usb-keyboard. Several discussions can be found, none giving me a full picture of the issues here. FYI: in depth, quick, available cmd parameters
    Changing from pyaudio to sounddevice made the problem disappear.
  • PI2 and lower: if your USB devices are not stable because of using much power, Boost USB Current in Raspberry Pi 2 and B+ shows ways to double the software limit on the USB ports power supply.
    More Power For Raspberry Pi USB Ports is an in-depth article on the same subject and gives the hardware solution to get to 4 times more power.
Trial Box:
click both to enlarge
Making it, click to enlarge Wiring, click to enlarge


Alternatives:

Making it, alternatives


Connecting peripherals
click to enlargeGPIO fixed pins


SD card layout
click to enlargePartitionMap