Probe mission to the 5 Moons

Here is a report on some hacking / modding experiments I’ve made on the 5 Moons, in case it is useful to others. Please note that these are my own incomplete experiments, and there is no guarantee that these ‘features’ are fully stable and usable. DIY at your own risk, back up your data, keep a copy of the OS image in handy in case you need to restore it.

(This is not meant to be a ‘how-to’ guide, just a report on some successful proof-of-concept explorations.)

Enter the 5 Moons orbit (wifi + ssh access)

Just like the Pocket Piano 201 (I don’t have one, but I hear it’s nice), I found it’s possible to plug in a wifi adapter to the 5 Moons USB-A port and gain ssh access over a network.

I followed the general guidelines here and was able to connect my 5 Moons using ssh over wifi.

Here is my take:

  • I ejected the 5 Moons SD card, and I used an Ubuntu VM on my Mac to mount the 5 Moons OS partition on the card and edit the /etc/wpa_supplicant.conf file directly to provide my local network details.
  • Since my network uses a WPA passphrase for authorization, I used the wpa_passphrase ssidname plaintextpassphrase command in Ubuntu to generate the hex value for the passphrase (instead of simply using the plaintext passphrase in the wpa_supplicant.conf file).
  • On the 5 Moons I am using the little USB wifi adapter that came with my Organelle M.
  • After editing the wpa_supplicant.conf file, I put the sd card back in the 5 Moons, connected the wifi adapter, and started it up. After the startup procedure, and a few more seconds, I could see the light on the wifi adapter flashing to indicate that it was passing data to a wifi network.
  • I had to use the network scanner app (mentioned in the post above) to find the IP address of my 5 Moons.
  • I was able to ssh to it from my mac using: ssh root@x.x.x.x (where x.x.x.x is the IP address found in the previous step).
  • Username: root, password: organelle

Establish communications from orbit (ethernet over USB)

This is an incomplete experiment, but I want to report on it since it could lead to a more convenient way to connect to the 5 Moons.

The 5 Moons can behave as a “USB Gadget”, in that it can look like a USB peripheral to a computer connected to its USB-C port. This is how it can look like a mass storage device in ‘file access’ mode. There are a couple other types of devices that seem to work, and one I found to work is “Ethernet Gadget” mode.

  • Connect the 5 Moons to a mac using a USB C cable (don’t enable file-access mode)
  • Connect via SSH to the 5 Moons over wifi.
  • On the command line run: modprobe g_ether
  • Then run: ifconfig usb0 192.168.0.100 netmask 255.255.255.0
  • On your mac, the 5 Moons will show up as an ethernet adapter. I used System Information.app to find out the device name for my 5 Moons (e.g. for me it was ‘en7’).
  • In Terminal on your mac, configure an ip address on the new adapter:
    • sudo ifconfig en7 192.168.0.101 netmask 255.255.255.0
  • Now you can ssh to the 5 Moons over USB: ssh root@192.168.0.100

As it stands this isn’t very useful, since if you restart the 5 Moons, this configuration will be lost and you’ll need to set it up over wifi again. But I could see the possibility of setting it up so that these commands run automatically at powerup.

Note that g_ether cannot run at the same time as the mass storage (file access) module, since they would compete for access to the USB port. You need to unload g_ether for any other USB gadget configuration to work (and vice versa). You an unload it with the command:
rmmod g_ether

(or just reboot the 5 Moons)

Establish base camp (compile code on 5 Moons)

  • The 5 Moons OS includes your basic compiler tools.
  • I was able to build one of my gen~ -based pd externals see here
  • I haven’t actually tested it yet to see if it runs in pd. All I know so far is that it compiled with warnings but not errors.
  • To compile it I had to get a copy of m_pd.h from the pd(v51.4) source and copy it to /usr/include on my 5 Moons.

Send back audio from the surface (audio over USB)

Just like with the Ethernet Gadget mode, I was able to enable an Audio Interface Gadget Mode, which can make the 5 Moons appear to a computer (mac) attached via the USB-C port as an audio input/output device. (2in/2out)

Note: with anything related to audio, please be very careful. It’s super easy to create damaging feedback, or full-strength signals, especially with PureData in the mix. Note in particular that the ‘volume’ knob on the 5 Moons is just a ‘control’ knob for pd, not a direct control of an onboard amplifier. This means that if pd is not explicitly using the value of this knob to attenuate audio within a patch, the audio could be output on the main out at 100% volume. Proceed with caution.

Like I mentioned with the Ethernet gadget experiment above, you can only enable one of these ‘gadgets’ at a time.

  • Command to enable USB audio:

modprobe g_audio c_srate=48000

This creates a new audio ‘device’ on the 5 Moons, alongside the built-in hardware one. Anything sent to ‘out’ (playback) on this device on the 5 Moons becomes ‘input’ (capture) on your host laptop. Anything ‘captured’ (in) on this device, comes from the ‘output’ (playback) on your host laptop (or iPad, etc.).

On my mac & iPad, this audio interface is called ‘Playback Inactive’ and ‘Capture Inactive’. I have no idea why they are called “Inactive”, but it has been working for me.

There are a lot of possibilities here; I think an audio card with embedded pd could do some interesting things! Just trying to think through different kinds of routing really makes my head spin :wink:

Note that the stock ‘pd’ process on the 5 Moons will just use the built-in hardware in/out ports. To use audio over USB, you need to tell pd to attach to the alternative device when it starts up.

The hardware and USB endpoints for audio operate as two completely separate devices, so to mirror audio from one to the other, you need some software to make a connection.

As an experiment I was able to get audio in (to the 5 Moons) from its hardware port (as usual), but send the 5 Moons audio output directly over USB to my laptop, instead of to its output audio port, then listen to it on my laptop speakers, by explicitly telling the pd process to use device 1 (hardware) for ‘input’ and device 3 (usb) for ‘output’:

  • killall pd
  • cd /sdcard/pd
  • pd -nogui -rt -audioindev 1 -audiooutdev 3 -audiobuf 8 main.pd &

(I was also able to get the 5 Moons to behave as a full ‘sound card’ (stereo in / out) for my iPad, along with its standard looping functions, but that required creating a separate ‘passthrough’ pd patch and running a second pd process for the output side of things.)

This thing has been pretty solid so far in my brief experiements with USB audio, but I haven’t been listening closely for glitches etc. So I don’t know how reliable ultimately this would be.

To unload the USB audio gadget driver:
rmmod g_audio

(or restart the hardware)

Sample return mission (file transfer over network)

Of course, with ssh, it’s possible to copy files to & from the 5 Moons over a network with scp, as expected.

Current mission status

So, anyway, after about one day with my 5 Moons, I’ve been able to try some interesting things with the hardware. I love this little device, and much respect to C&G for leaving the door open for experimentation. Hopefully all this is useful to others. Cheers.

4 Likes

Here is another built-in command that is also potentially useful - a local web server:

cd /sdcard
python3 -m http.server

Now you can access a (most basic) directory listing for your files in a browser at x.x.x.x:8000
(where x.x.x.x is the ip address of the 5 Moons).

1 Like

Thank for these notes. That is really interesting about using the 5-Moons as an audio interface. I knew g_audio existed, but never actually tried it. Using g_ethernet is also cool, I think this is how the Bela board works, then runs a small webserver allowing you to edit code. Its nice because you don’t have to mess with WiFi. (another option is a cheap USB to ethernet adapter, although this isn’t quite the same it does provide a wired network connection which is always less headache than WiFi)

One thing I’ve been meaning to look into is using g_serial to emulate a serial port. Then you can get a console on your computer (using screen, or minicom, or whatever) without dealing with network at all. Too bad the gadgets can’t be used at the same time… I thought I had g_serial and g_mass_storage running, but I’ll have to check.

1 Like

Not only does g_audio exist, I had it sending up to 10 channels of audio into my mac (& iPad pro), alongside receiving 2 channels out :slight_smile: So that gives you stereo from 5 moons->USB->laptop for every moon individually which was really cool. I’ve been trying various combinations of ins / outs and routing / passthrough on the pd side … So far (after admittedly some brief sessions) it’s pretty solid, however I noticed that pd hangs if the application (e.g. Ableton Live, or Aum) consuming the USB audio stream is shut down. That’s a glitch I wasn’t expecting.

Composite gadgets might be possible, but it would require messing around with configfs… seems like a “lost weekend” project but I’ll report back if I can get it to work with, say, USB audio + USB Ethernet at the same time.

Unfortunately the g_midi gadget is not available in the kernel as far as I could tell, so the 5 moons cannot behave as a USB midi device. (I think you said … in a different thread … it could behave as a host through the USB-A port though.)

1 Like

Updates -

Composite Gadget I was able to get USB composite gadgets (libcomposite) working on my 5 Moons. This allows the 5 Moons to behave as several types of USB gadget at the same time, e.g. Audio, Ethernet, ACM (which is serial I think…). I’m copying the setup/teardown script I came up with below, for reference.

MIDI - I was able to get the 5 Moons to appear on my mac as a USB Midi device, however it seems that ALSA’s ‘seq’ module was not included in the kernel build, and Pd seems to depend on that to be able to communicate with MIDI. I was able to send and receive MIDI over ALSA’s rawmidi device, but just not to Pd. This seems to apply to regular MIDI devices plugged into the 5 Moons’ USB-A port too. (I noticed in /proc/config.gz that CONFIG_SND_SEQUENCER is not set.)

Audio - I mentioned previously that the Pd schedular blocks with the following conditions:

  • USB Gadget is enabled
  • Pd is configured to use one of the USB audio gadgets for audio input and/or output
  • An application on my Mac or iOS is not actively running and sending/receiving audio over USB to the 5 Moons

I haven’t found a workaround for this, and I suspect it won’t be possible to get Pd to not block when audio data isn’t being actively sent over USB under these conditions. It’s not a dealbreaker for exploring USB audio but it is something to keep in mind. The fix if Pd glitches out is to restart the Pd process.

usb_audio_ether_acm.sh

#!/bin/bash

# Script to setup and enable a composite Audio, Ethernet and Serial USB gadget
set -x
whoami
modprobe libcomposite
mount -t configfs none /sys/kernel/config
if [ ! -d "/sys/kernel/config" ]; then
  echo "/sys/kernel/config does not exist."
  exit 1
fi
cd /sys/kernel/config/usb_gadget/
GADGET_DIR="g1"
mkdir -p $GADGET_DIR
cd $GADGET_DIR

# Set basic USB device settings
echo 0x1d6b > idVendor  # Linux Foundation
echo 0x0101 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB    # USB2

mkdir -p strings/0x409
echo "420" > strings/0x409/serialnumber
echo "Critter" > strings/0x409/manufacturer
echo "5Moons" > strings/0x409/product

# Create a configuration
mkdir -p configs/c.1
mkdir -p configs/c.1/strings/0x409
echo "Configuration 1" > configs/c.1/strings/0x409/configuration
echo 100 > configs/c.1/MaxPower

# Add USB functions. Note: Required driver for each function is loaded automatically.

# Add USB Audio 2 device
UAC2_DIR="functions/uac2.usb0"
mkdir -p $UAC2_DIR

# Playback settings:  Stereo, 48000 Hz, 16-bit
echo 0x3 > $UAC2_DIR/p_chmask  # 1 for mono, 3 for stereo (10 channels aka 0x3ff seems to be the max allowed)
echo 48000 > $UAC2_DIR/p_srate

# Capture settings: Stereo, 48000 Hz, 16-bit
echo 0x3 > $UAC2_DIR/c_chmask  # 1 for mono, 3 for stereo
echo 48000 > $UAC2_DIR/c_srate

ln -s $UAC2_DIR configs/c.1/

# Add USB Ethernet Device
ECM_DIR="functions/ecm.usb0"
mkdir -p $ECM_DIR
ln -s $ECM_DIR configs/c.1/

echo "USB ECM ETHERNET GADGET CONFIGURED"

# Add USB Serial Device
ACM_DIR="functions/acm.usb0"
mkdir -p $ACM_DIR
ln -s $ACM_DIR configs/c.1/

echo "USB ACM GADGET CONFIGURED"

# Bind USB Device Configuration to USB Device (from /sys/class/udc)
echo "ci_hdrc.0" > UDC

echo "USB AUDIO GADGET CONFIGURED"

# Configure ethernet
ifconfig usb0 192.168.0.100 netmask 255.255.255.0

echo "ETHERNET CONFIGURED"

usb_audio_ether_acm_down.sh

#!/bin/bash

# Script to disable and take down a composite Audio, Ethernet and Serial USB gadget
set -x
if [ ! -d "/sys/kernel/config" ]; then
  echo "/sys/kernel/config does not exist."
  exit 1
fi
cd /sys/kernel/config/usb_gadget/g1

echo "" > UDC

rm configs/c.1/uac2.usb0
rm configs/c.1/ecm.usb0
rm configs/c.1/acm.usb0

rmdir configs/c.1/strings/0x409
rmdir configs/c.1

rmdir functions/uac2.usb0
rmdir functions/ecm.usb0
rmdir functions/acm.usb0

rmdir strings/0x409

cd ..
rmdir g1

# After a gadget is disabled and torn down, the modules remain loaded.
rmmod usb_f_uac2
rmmod usb_f_ecm
rmmod usb_f_acm

echo "USB GADGET DEACTIVATED"



1 Like