5moons Nerdy constructive details

Hej!
Maybe some of you did some testing / research already…

Can you use the Usb host in 5 moons to connect a midi controller?
Has anyone measured the input impedance & latency (i/o)?
Cpu Clock freq + Ram ?
Power consumption?
Also: Can you run the pd patch in 5 moons while you are editing it in USB storage mode?
Pd externals are the same as in the Organelle or is it required to compile for that specific processor/Os?

My idea is to get one to create a new patch that might convert 5 moons into a super powerful guitar pedal…

If the performance is at least similar as an organelle 1st gen, it shouldn’t be a problem to have a chain of effects and ending up on a sound on sound looper that then could be dumped into Sdcard…

I’m hopeful also that because of the optimized OS, the latency should be ultra-low and therefore super nice to play an instrument through it…

Thanks so much in advance
& Greetings

Hey,
I did some tests with USB MIDI documented in a followup comment to my post here: Probe mission to the 5 Moons - #5 by samesimilar
TLDR … .I think the OS is missing the ALSA ‘seq’ module and PD seems to need that to recognize MIDI devices. (Or maybe I am wrong, but I couldn’t find a way to get MIDI input to work in PD on 5moons.)

Here is some info I gleaned about the CPU / memory here:

root@organelle2:/# free
              total        used        free      shared  buff/cache   available
Mem:         503464      146776      331204         200       25484      350028
Swap:             0           0           0
cpu:
root@organelle2:~# lscpu
Architecture:        armv7l
Byte Order:          Little Endian
CPU(s):              1
On-line CPU(s) list: 0
Thread(s) per core:  1
Core(s) per socket:  1
Socket(s):           1
Vendor ID:           ARM
Model:               5
Model name:          Cortex-A7
Stepping:            r0p5
CPU max MHz:         900.0000
CPU min MHz:         198.0000
BogoMIPS:            109.09
Flags:               half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae

I think PD externals direct from Organelle patches could work. I don’t recall specifically but I’m pretty sure I was able to copy them over. But if not, the 5Moons has the dev toolchain necessary to build them from source.

MIDI may not work, but basic USB HID devices, like a USB keybopard or basic USB game controller could work (I haven’t tested it yet.), if you needed some “pushbutton” input.

Regarding running Pd and disk mode simultaneously, you can see what happens here in the 5moons source code … when disk mode is enabled, the Pd process is killed (see the load_patch function): 5-Moons/hw/main.c at main · critterandguitari/5-Moons · GitHub

I’m guessing that one good reason for that is to prevent both USB storage mode and the Pd process from reading / writing files at the same time, which could cause lockups, or maybe event file corruption.

Hej!
Thank you so much for your answers :slight_smile:
I also did read your Probe mission post.
Hmm. If I just risk to corrupt a patch I guess I would still try to be editing a patch in the computer while running it in the hardware…
The only issue is that then,I will need to reload in order to notice the changes…

So far, you mostly code in the 5 moons via SSh?
Is there also a ‘mother.pd’ like patch or just the main one?
Greetings!
S

Mostly I code on my computer and move patches and scripts over to 5moons with scp over the network.

5moons doesn’t have a Linux “Desktop” installed, so it’s not possible to use something like VNC to edit on Pd directly on 5moons, like you would on the Organelle. It doesn’t have an equivalent of the ‘mother.pd’ patch, wherein the purpose of the mother.pd patch is to mediate between OSC messages and Pd messages, providing a unified interface for all the patches that people create. Rather, all that communication is integrated into the single pre-programmed 5moons patch.

When 5moons goes into “usb storage mode”, it has to unmount the SD card from the regular filesystem, then remount it so that it is available to the USB storage driver. So I think if you want to modify a PD patch, while it is running, doing it over a network connection would be the way to go.

Here are some ideas:
a. Use a Wifi dongle to connect to 5moons over the network.
b. Or use a usb cable to turn 5moons into an “ethernet” devices and connect to it that way (see the original thread I mentioned.)
c. Use scp to copy files over the network. (Or now that I think of it maybe it is possible to enable network file sharing on the 5moons, but I haven’t tried that.
d. 5moons has python3 on it, IIRC, and there is a simple command line that you can use to set up a directory listing webserver that can let you download files. I think to upload files you would need to program a more sophisticated web server. Maybe the webserver scripts from the Organelle could be adapted to that purpose.
e. Send OSC messages to Pd over the network somehow, if you want to change parameters in the patch you are working on, as an alternative to the 5moons’ hardware controls.

One thing I should clarify is that if you, say, edit a Pd patch on your laptop, save the file, then transfer it over to the 5moons somehow, say using scp, to hear the changes you would need to restart the Pd process. Currently the only ways to do this in the OG OS are either to restart the device, or to switch to USB storage mode and back again.

OR what I do is start/stop the Pd process manually using the command line over ssh. But it wouldn’t be “seamless” in a performance sense.

Hmm. Actually if X forwarding was enabled, it would be possible to edit the pd patch remotely via ssh while it is running in the hardware… I was doing that back in the day in a raspberry pi 1st generation…
it was something like : ssh -XY ccrma@192.168.105.106 and then when launching pd from terminal (Having Xquartz or simmilar installed was required on mac) I could patch in the raspberry from the mac. I loved to work in this way and I think it could be more efficient than running a Vnc server…
Btw. could you check how much cpu does the current / your 5moons patch takes?
greetings
S

Yeah that is definitely something to investigate. Xquartz - now that’s a throwback! Maybe there is a browser-based X terminal out there that could work too. Beware though that 5moons is running a Yocto Linux build, not a more full-featured distro like Debian or RPi OS. So it may not have the necessary shared libraries installed to run Pd in gui mode. (But this is getting way past the limits of my knowledge of how desktop guis and windowing work on Linux.) I’m pretty sure it doesn’t even include a built-in package manager, but now I may be misremembering what I tried back in August.

Here is some CPU data that I saved back in August:
This is with some extra stuff running beyond stock: 5 tracks playing + input monitoring + audio line in → usb audio out → laptop + wifi/ssh

  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
21604 18761 root     S     123m  25%  35% pd -nogui -rt -audioindev 1 -audiooutdev 3 -audiobuf 8 main.pd
  170     1 root     S    11404   2%   3% ./main
21784     2 root     IW       0   0%   1% [kworker/0:1-eve]
  165     1 root     S     6756   1%   1% python3 powerbutton.py
21727 18761 root     R     2340   0%   0% top
  304     2 root     IW       0   0%   0% [kworker/u2:3-ph]
  351     1 root     S    11912   2%   0% /usr/sbin/rngd -r /dev/hwrng
18703   363 root     S     5316   1%   0% sshd: root@pts/0
    7     2 root     IW       0   0%   0% [kworker/u2:0-ph]
22085     2 root     IW       0   0%   0% [kworker/u2:1-ph]
  184     1 root     S    10732   2%   0% /sbin/udevd -d
  289     1 root     S     7896   2%   0% /usr/sbin/wpa_supplicant -B -P /var/run/wpa_supplicant.wlan0.pid -i wlan0 -c
  363     1 root     S     4608   1%   0% sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups
18761 18703 root     S     2632   1%   0% -sh
  384     1 root     S     2412   0%   0% {start_getty} /bin/sh /bin/start_getty 115200 ttymxc0 vt102
  348     1 messageb S     2348   0%   0% /usr/bin/dbus-daemon --system
  375     1 root     S     2252   0%   0% /sbin/syslogd -n -O /var/log/messages
  378     1 root     S     2252   0%   0% /sbin/klogd -n
  331     1 root     S     2252   0%   0% udhcpc -R -b -p /var/run/udhcpc.wlan0.pid -i wlan0
  385     1 root     S     1508   0%   0% /sbin/getty 38400 tty1
^C403   384 root     S     1508   0%   0% /sbin/getty -L 115200 ttymxc0 vt102

RE: remote gui, consider this:

And check out this project:

(That Bela project looks like it needs Docker / Node to run, so I don’t think it’s easily installable on 5moons.)

Not answering the question directly. But I just copied the files across, working on the patch on the computer, and included logging to a text file from the patch to check it was doing what it should and in the right order.

1 Like

Ok here we go, it seems the question of how to connect to Pd remotely is infrequently asked, and frequently unanswered, at least according my searches on Google. But I have had some interesting results tonight getting Pd’s GUI to connect over a local network connection to a Pd process on the 5moons.

Here is my setup for this experiment:

  • 5moons is connected to my Mac with a USB cable.
  • The USB Ethernet gadget (see previous thread mentioned above) is enabled, and my 5moons is addressable to my Mac at IP address 192.168.0.100. I can ssh to the 5moons to run commands at this address.
  • I have Pd installed on my Mac. (The current version I have is Pd 0.54-1.)

Steps:

  1. ssh to the 5moons (ssh root@192.168.0.100 with pw=organelle) and do the following:
    i. Edit /etc/hosts on 5moons (I used vim), so that:
    The first line:
    127.0.0.1 localhost.localdomain localhost
    is
    0.0.0.0 localhost.localdomain localhost
    (See notes below.)
    ii. Stop the default Pd process from running (so that the audio device is available):
    killall pd
    iii. Now start Pd on 5moons with the following command:
    pd -verbose -guicmd dummy /sdcard/pd/main.pd
    (Note that the ‘-guicmd dummy’ option is really there literally as ‘dummy’; it’s there to prevent Pd from starting its standard gui process and to wait for a connection instead. The ‘-verbose’ option is used so that Pd will log the port it is listening to on the on the console.)

Here is what it might look like:

root@organelle2:~# pd -verbose -guicmd dummy /sdcard/pd/main.pd
Pd-0.51.4 ("") compiled 11:48:56 Sep 16 2021
float precision = 32 bits
port 54321
whateverWaiting for connection request... 
sh: dummy: command not found

Note the ‘port’ number. Here for example it is 54321.

  1. Ok now on the Mac, I start the gui process as follows:
    i. In a terminal window, assuming Pd is installed as /Applications/Pd-0.54-1.app, run:
    /Applications/Pd-0.54-1.app/Contents/MacOS/Pd 192.168.0.100:54321

… and at this point what you should get is the Pd gui running on your mac, talking over the network to the Pd process running remotely on 5moons. Note the host IP of the 5moons is used here, and also the port number noted above.

Results:
What I saw working:

  1. The Pd log window prints messages from the 5moons patch, which would be useful for remote debugging.
  2. Interacting with objects and controls. The basic Pd patch stuff.
  3. Saving the current patch (cmd+s).

What didn’t work (not limited to):

  1. one of the ‘properties’ dialogs (I think for the integer control?). This may come down to the difference in Pd versions between my Mac (0.54) and 5moons (0.51).
  2. Right-click → Help on objects in the 5moons.
  3. File dialog boxes (save as, open), obviously, since the gui is running on my mac, those will only see the mac’s filesystem, not the 5moons’ directory tree.

Theory of operation:

When Pd runs, it usually splits itself into two processes. The ‘core’ process which runs a patch, and the GUI that you can interact with (by default a tcl/tk script running in the ‘wish’ runtime executable) . These processes communicate exclusively over a network socket. Normally this network socket is bound to both processes via a random port on ‘localhost’, so all communication is local.

To get this to work, I had to ‘trick’ Pd to open itself up to remote connections. This was done by editing the /etc/hosts file, which translates a host name (i.e. ‘localhost’) to an IP address (i.e. 127.0.0.1). By changing 127.0.0.1 to 0.0.0.0, it means that when Pd opens a socket connection to ‘localhost’ it makes itself available on all network interfaces, rather than just the loopback controller (internal connections).

So while it is waiting for a connection, on the remote computer I started Pd’s special GUI process . It takes a command-line argument pointing to the parent process, i.e. host:port.

Once the connection is made, Pd can talk to its gui, even though it is over a remote network connection.

Finally Note:

Probably, in general, very bad practice to set ‘localhost’ to refer to ‘0.0.0.0’ instead of ‘127.0.0.1’ in /etc/hosts, since in general any process that sets up a socket on localhost would now be open on any network interface on the device, rather than just to internal processes, breaking the assumption behind ‘localhost’. But for me this is just an experiment, so I’m not too concerned :wink:

Ultimately I don’t know how solid this setup is. I’ve only played with it for a few minutes. But I thought I’d report my results.

Awesome work!

I will test this out with my organelle…
In case that you wanted to test out with same pd version, here is a directory with all vanilla versions: (0.51.4 can be found there too)
https://msp.ucsd.edu/Software/
I wonder why although 5moons seems to be about 1 year old, the Pd version supplied with is 4 years old now…

Greetings
S

I’d be interested to know if you can replicate these results!

All the usual caveats for hackers apply, of course … back up any data you might think is important in case you need to re-image your SD card, … Protect your ears and speakers.

Note that with this method we are opening up a passwordless & unencrypted network connection on the 5moons. Doing this over a cable direct to a laptop is probably not risky, but if your 5moons is on a wireless connection in a cafe, for example, a malicious composer could connect and mess with your patch, or at least observe it. Maybe there is a fancy way to tunnel this over ssh.

Last night I came up with a quick python script that can forward messages on the 5moons from a port on localhost to another network interface. This would mean it would not be necessary to edit /etc/hosts. I’ll post more about it if I get a chance to clean it up.

Thinking longer term - I was thinking about a modification to the Pd source code to add a commandline option that would allow us to specify the hostname it binds to when setting up the
TCP port for the gui. Currently ‘localhost’ is hardcoded in s_inter.c.

I have some sympathy for the choice to use an older, tried and tested version of Pd in a product like this. Since the requirement would be to just have something that can run the builtin 5moons patch, then why use something more bleeding edge? All this hacking stuff is icing on the cake, and since we are hacking it anyway, we could probably figure out how to update Pd for ourselves if we need to :wink:

Thanks for sharing this info @samesimilar I’d never been able to get the Pd GUI operating remotely, I’ll have to give this a try!

The 5-moons, in addition to the Kaleidoloop and Pocket Piano 201 are all designed around the same Linux ‘sound brain’ board…The idea was the same hardware platform could be used to create different instruments. We’ve considered releasing just the board so other people could experiment creating their own instruments, but get hung up on what this would look like, e.g. would it have any knobs or buttons at all, or if people would even be interested (?)

The Pocket Piano and Kaleidoloop are setup slightly differently than the 5-moons in terms of disk mode. On the 5-moons, a separate Pd test patch is run in disk mode. The PP and KL on the other hand run the main patch in disk mode and they provide another key combo that will restart Pd. This way you can edit and save the patch right from the USB disk and reload it without having to eject the disk and exit disk mode… so not quite ‘real time’ editing, but a nice compromise.

One issue (mentioned above) is when in disk mode and your computer has write access: the partition must be mounted read-only from the instrument side. So when developing the KL patch for example I would just change file writing path to ‘/tmp’ so any files would be written to the temporary filesystem (stored in RAM), then change it back when done editing.

1 Like

The 5-moons, in addition to the Kaleidoloop and Pocket Piano 201 are all designed around the same Linux ‘sound brain’ board…The idea was the same hardware platform could be used to create different instruments.

Interesting! Thank you for the context. That makes a lot of sense.

We’ve considered releasing just the board so other people could experiment creating their own instruments, but get hung up on what this would look like, e.g. would it have any knobs or buttons at all, or if people would even be interested (?)

Wow cool! I would be interested :wink: I think that one of the things that contributes to the strength of the Organelle patching community, for example, is that everyone has the same basic physical interface on their device, so people who are sharing patches can make certain basic assumptions about the UI of the devices where the patch will run, and explore different ideas for interactivity within that framework. So I would vote for some standard knobs etc. to be included.

(When I think about a simplified board, what I dream of really is a device with like a half-dozen more inputs & outputs (audio and midi/cv?), with the capability for custom routing and processing in Pd… call it the “Lab” concept … so many things out there are limited to stereo in / stereo out, but we have all these devices to connect together… but I doubt it’s easy to just throw a few more ADACs on an existing board haha … anyway that’s a subject for another thread)

Here is the python script I hacked together. This changes the setup, so you don’t have to edit /etc/hosts. What it does is accept one connection on localhost (from Pd) and one remote connection (from the Pd gui ‘child’ running on a remote system, e.g. a macbook). Then it passes all messages between the two connections.

It doesn’t support recovery or reconnections, so save often to not lose your work!

Also below is a simple command line script to automate the start up procedure. So on the 5moons command line, start the script, wait a few seconds while it starts the python script and pd, then start the Pd gui on your laptop as mentioned above. e.g. on Mac use:

/Applications/Pd-0.54-1.app/Contents/MacOS/Pd 192.168.0.100:65432


# link.py

import socket
import select


# Accepts two connections on defined interfaces/ports, and forwards data both ways between them.
# Doesn't support reconnection after disconnects (e.g. errors or timeouts). Re-run the script to restart.
# (i.e. Save your Pd patch often.)

def start_port_forwarding(pd_iface, pd_port, remote_iface, remote_port):
	try:
		pd_client = None
		remote_client = None
		# Create a socket to listen for incoming client connections
		pd_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		pd_socket.bind((pd_iface, pd_port))
		pd_socket.listen(5)
		print(f"Pd on {pd_iface}:{pd_port} and forwarding to {remote_iface}:{remote_port}")
	
		pd_client, pd_address = pd_socket.accept()
		print(f"Accepted pd connection from {pd_address}")		
		
		remote_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		remote_socket.bind((remote_iface, remote_port))
		
		print(f"Go ahead and the remote gui process now. Connect to port {remote_port}...")
		remote_socket.listen(5)
		
		
		
		remote_client, remote_address = remote_socket.accept()
		print(f"Accepted gui connection from {remote_address}")
		
		while True:
			rlist, wlist, _ = select.select([pd_client, remote_client], [pd_client, remote_client], [], None)
			for ready_socket in rlist:
				if ready_socket is pd_client:
					if remote_client in wlist:
						data = pd_client.recv(4096)
						if data:
							remote_client.sendall(data)
				else:
					if pd_client in wlist:
						data = remote_client.recv(4096)
						if data:
							pd_client.sendall(data)
							
							
						
							


	except Exception as e:
		print(f"Net error: {e}")
	finally:
		print("Closing.")
		if pd_client != None:
			pd_client.close()
		if remote_client != None:
			remote_client.close()
	

if __name__ == "__main__":
	# Configure the source and destination IPs and ports
	pd_iface = "127.0.0.1"  # Listen on localhost interface
	pd_port = 54321     # port for local connection
	remote_iface = "0.0.0.0"  # Listen on all network interfaces
	remote_port = 65432       # port for remote connection
	
	# Start the port forwarding
	start_port_forwarding(pd_iface, pd_port, remote_iface, remote_port)


# link-pd.sh

killall pd
killall python3
python3 /home/root/www/link.py &
sleep 5
(cd /sdcard/pd; pd -guiport 54321 -rt -audiobuf 8 /sdcard/pd/main.pd) &

1 Like

Do you know Axoloti platform? (Now revived as ksoloti) . The board had Usb host for midi. Usb device for programming and power. Midi I/o, High quality / low latency audio i/o, SDcard to optionally store patches + sounds and Also it had a generous amount of Gpio pins…

https://web.archive.org/web/20180628201152/http://www.axoloti.com/

It could serve as reference for an audio / pcb / brain thingy… It used to cost around 85 € after taxes & shipping and people gladly paid that for it + they usually got several boards destined to different projects…
The community around it was amazing and the advantage over raspi + pd was the ease of use… It was fairly easy and quick to program, resembling a lot the ‘nord modular’ environment…

As disadvantages: very little memory in the microcontroller and Non real time patching.

I’ve successfully replicated this with a 201 on Windows. The only real difference from the Mac process that I encountered was locating/running the GUI. Here’s how I did it:

  1. Change directory to the bin subfolder of where Pd is installed on your computer.
    cd \Program Files\pd\bin

  2. Run the pd-gui.tcl script using the Critter’s IP Address (in this case 192.168.0.100) and Port Number (in this case 54321).
    wish86 ..\tcl\pd-gui.tcl 192.168.0.100:54321

1 Like