Self promotion at emf

Shameless self promotion in the lounge

We’ve had a couple of interesting nights here at emf. It’s quite fun to watch the tent around you swirl and dance as the wind howls and the rain pours down. Really. The best bit is the moiré fringe effects that you get when the inner and the outer layers of the tent touch each other. Quite mind blowing.

Anyoo, the good news is that just as we woke up the rain stopped and it wasn’t ever a hinderance right through the day. Oh, and here I present my tips for emf shower success. I meant to write these down last time, but I forgot and had to rediscover them all again.

  • wear shorts for the shower. There’s nothing quite as nasty as pulling on jeans over barely dry legs in a steamy, enclosed space.

  • don’t wear socks for the shower. If you think jeans are hard to pull over damp legs, you haven’t tried pulling socks over damp feet.

  • a carrier bag is your friend. When you set out it holds your clean clothes, towel and soap etc. You can hang it on the hook in the shower, and then move things in and out as you go through the shower process. A true ninja takes two bags, one for clean stuff and one for dirty.

  • put your toothpaste on the toothbrush before you leave the shower cubicle. The tap and basin are outside the shower. It’s a real faff to put toothpaste on a brush while standing in a queue. Much better to just have it all “tap ready” when you leave your shower. The first time I saw someone heading towards me holding a toothbrush in front of them I thought I was being challenged to some kind of duel. But when he shot past me and made for the tap I realised what a genius he really was.

Making Geiger Counters at emf

What better way to start the day than by building a Geiger counter. The session yesterday was fully booked so today saw me standing in my wellies (the weather has changed slightly) at the head of the queue to take part. I was lucky to get in, as in the previous session things got very busy. The bad news for everyone was that, due to a shortfall in Geiger tubes, not everyone would be able to take away a fully working device. But they are readily available on ebay for a modest price, and I never could resist a bit of soldering, so off we went.

It was wonderful. We had excellent instructions, plus lots of folks wandering around offering us components and advice. At the end of the day some of us walked away with working devices. Number one son got his built and working and even managed to get a tube to take home. I’m going to get myself a tube on ebay so that I can finish mine off . Somebody told me that bananas are a good source of radiation. I’m looking forward to investigating this.

Note that just because the counter makes a noise when you hold it close to something doesn’t make that thing dangerous. I’m very grateful to the folks from Bristol and their sponsors for making the whole thing possible though, it was awesome.

When presentations go wrong...

So much for testing

If you’ve been wondering where I’ve been for the last couple of weeks, I’ve been working furiously on a device for a presentation at emfcamp. Emf is a fantastic place to talk tech and meet folks. I was at the last one and really enjoyed it. We arrived at the camp on Thursday and yesterday I got to tell everyone about my “Chocolate Synthbox Synthesizer”.

I’d spent a lot of time building the device and after some careful testing in the tent in the morning I reckoned it was good to go. Fate however had other ideas. If you’ve ever done any presentations you’ll have heard of the “Demo Gods”. If they smile on you all will be well. If they frown on you, then get ready for trouble. The worst I ever had was a while back when I did a session in Amsterdan where every demo failed - that is, the worst until today.

The presentation involved me saying nice things about two technologies, sending MIDI messages to musical instruments using the Raspberry Pi PICO and using the Puredata program to make sounds. It hinged around live demonstrations of the soundbox itself. If that didn’t work, I was toast. It didn’t work. Worse than that, it gave the impression of working every now and then just to get my hopes up, and then failed when I tried to use it to show anything off.

The audience was great. They laughed at all my emergency jokes – that is until I ran out of them. I think they were entertained too, but not in the way I was intending. Oh well. You should treat every setback as an occasion to learn something. In this I’ve learned that you should always have a fallback position. Most of the other presentations I’ve been to have used videos to show things off, so I really should have had a few of them lying around to show off.

We’ve tracked the problem down to power supply issues and a broken speaker connection. I’m hoping everything can be got working so that I can wander down to the bar with it and show it off properly.

Apparently, to this day in some parts of Holland they speak of the time that everything broke for the idiot Englishman, perhaps it is OK to be remembered for something, even it is glorious failure.

I just hope I get the chance to present at emf again, so that I can show something that properly works.

Heading for emf

We headed off to emf today first thing. Well, around 8:30, we’re not fanatics. The roads were nice and quiet and the journey was very pleasant. We didn’t actually sing at any point, but wouldn’t have been out of place if we did.

The site was just coming alive as we arrived and number one son found us a nice site on the side of the hill. Actually, here everything is on the side of the hill which takes a little bit of getting used to. If Istand up suddenly I then feel myself instantly falling over. The tent proved quite easy to put up. We’ve taken the precaution of getting an extra groundsheet to keep the inside of the tent nice and dry, but the ground seemed pretty dry.

We’ve carefully planned our itinerary for the first day, I’ve tested everything for the presentation and the WiFi reaches up to us. We’ve even got our own mains power courtesy of the tent next door. This is going to be fun.

Bringing back the Autographer

I’m thinking of taking my Autographer to emf camp. I bought it a while back when the idea of wearing an automatic camera to record my so-called life seemed quite attractive. Since then the product has been withdrawn and the company behind it has vanished along with all the software support. You can go onto GitHub and find someone hosting all the apps and documentation but the program flatly refuses to work on the Mac. On the PC the application runs OK until you try to press buttons and do stuff, at which point nothing happens. It’s all rather sad.

The good news is that the device itself does work and you can get the pictures off it after you’ve taken it somewhere interesting. The date and times on the pictures are all wrong though, which is surprising given that the Autographer is supposed to have a GPS system built in.

The thing about the Autographer is that it decides when to take the picture. It has a bunch of sensors that help it do this. You can trigger it to take a some pictures if you like, but you’ve no idea precisely when they will be taken. This not the kind of camera you can say “cheese” for. However, it does come up with the occasional gem, like this one of me coming down the stairs. I’d left the camera lying on the floor of the hall and it has captured a very interesting angle that I probably couldn’t have got any other way. The ultra-wide angle also captures a good view of what’s around.

Sending messages to Pure Data using fudi

Isn’t this exciting? I’m just on the brink of sending useful messages between my PICO powered controller (which has buttons and a display) and a Pure Data patch running on a Raspberry Pi. Last time I got the comport working now that I can send raw data bytes between the devices. Now I want to see about sending packets of useful data.

The man behind Pure Data (Miller Puckette) has thought of this. He’s invented the FUDI protocol for sending messages. It’s a very simple text based protocol which means that it will be very easy to make the PICO assemble FUDI messages for the Pure Data patch to read.

Lets take a look at the kind of message that I might want to send from the controller to a Pure Data patch:

encoder 97 5;

The controller generates messages like this when an encoder is turned. The word encoder tells the receiver that a new encoder value is coming The first number (97) is the new encoder value. The second number (5) is the number of the encoder. The encoder message is generated by Circuit Python running inside a PICO which is connected to the encoders and sends messages out over the serial port. The Python code that sends these messages is:

b1 = int(self.active_config.serial_channel)
b2 = int(self.active_config.controller_value)
message = "encoder " + str(b1) + " " + str(b2) + ";\n"
send_buffer = bytes(message,"ascii")
print("Sending to serial:", send_buffer)
self.client.serial_port.write(send_buffer)

This code takes the two values and puts them into the variables b1 and b2. Then it creates the message string. Next it makes a byte array containing the message in ASCII. Finally it uses the serial_port_write method provided by the serial port to send the entire string out to the Pure Data patch. Now lets take a look at how this serial data stream is received.

My blog post here shows how to get a Pure Data patch to receive data from a com port. At the bottom of the patch you can see a data flow coming out of the comport object and ending in a rather enigmatic way. The patch decodes the input message and routes it to the required destination. It uses a Pure Data loop to assemble the message (which is a line of text) and then uses FUDI (Fast Universal Digital Interface) to parse the text and extract a message which is then routed to the appropriate destination.

Remember that what is happening is that individual bytes are arriving, one at a time, and need to be assembled into a line of text. The text is terminated by a newline character (10) or a return (13).

The sel object at the top of the patch takes the input stream and feeds it to one of three outputs. If the input value is 10 or 13 (the characters that mark the end of the list) the list is triggered to push its contents into the fudiparse object. If the input value is anything else (this is what the right hand output from sel is for) the newly received character is added to the start of the list, building up the line of text.

The fudiparse block takes the buffer containing the incoming message (in our case “encoder 97 5” and uses it to generate a Pure Data message that contains the values “encoder”, 97 and 5. This message is then sent into a route object. This looks at the first item in the message and then sends the rest of the message (the values 97 and 5) to the output that matches that name. In the case of the patch above, this means that the two encoder value are sent to a message endpoint called “encoderReceived”. Patches in other parts of the of the application can receive these messages and act on them.

You should be able to work out that the decoder above can also respond to an incoming message called button, which tells the Pure Data application when a button was pressed.

Using the comport object in Pure Data

I’m building a Raspberry Pi 4 based device that uses a thing called Pure Data to play sounds in response to incoming MIDI messages. The device also has a controller and display which is controlled by a Raspberry Pi PICO. I’ve connected the hardware for a serial connection and discovered how to send serial messages from the Circuit Python program in the PICO. Now I need to get the messages from the PICO into my music making software. This is how to do it.

The above patch fragment (is that even a thing?) shows how it we can surface serial data in a Pure Data patch. However, before we can do this we have to add the comport object to your Pure Data installation. If you re using a Raspberry Pi it turns out that this is very easy:

sudo apt install pd-comport

This console command installs the comport object. Now we can add one to our patches. The patch above shows that we can send it messages to make it do things. The message on the left sets the device name. The second messages sets the baud rate. The third message asks the comport to display all the available comports that Pure Data has found.

When the above patch is triggered by a message on the inlet it will set up a comport and set the baud rate to 19200. Any messages that we send to the comport object will be sent out of the comport. These need to just lists of bytes. If the comport receives any bytes from these are sent out of the bottom of the comport object. In a while we’ll take a look at how we can encode and decode messages that we want to send over the serial connection.

Linking a Raspberry Pi 4 and a PICO over a serial connection

I want the Pure Data patches in my Chocolate Synthbox to be able to display lights that flash in time with the music. The lights in question are a bunch of neopixels connected to a Raspberry Pi PICO which is handing all the inputs and outputs for the device. I’ve done this to keep the design simpler and to remove any chance of issues with the sound code on the Pi interfering with the pixel animations.

However, to make it work I have to connect the Pi and the PICO together. Both devices have plenty of serial ports, so the best way is just to use one of those.

On the Raspberry Pi 4 (note that this only works for the 4) there are four serial ports which are surfaced on the “hat” connector. You have to enable them and they surface as devices you can use.

You enable them by editing the /boot/config.txt file:

sudo nano /boot/config.txt

Then, if you want to enable serial port 2 (which I do) add the following line at the end of the file:

dtoverlay=uart2

Save the file and then restart the Pi. You can now ask it which pins it uses with the command

dtoverlay -h uart2

The important part of this information is the “uart 2 on GPIOS 0-3. This means that the pins will be assigned as follows:

Pin 27 GPIO0 UART2 TX
Pin 28 GPIO1 UART2 RX

The other two pins (GPIO2 and GPIO2) can be used for hardware handshaking, but I’ve not enabled that. The device will appear as /dev/ttyAMA1, I’m going to use it in Pure Data (but that’s a different blog post. For this one, let’s discover how to connect the port to a PICO. I’ve decided to use uart1 in the PICO. This can be used on pins GP8 (TX) and GP9 (RX). So the wiring I need is:

Raspberry PI         PICO
Pin 38 GND           Pin 13 GND
Pin 27 GP0 UART TX   Pin 12 GP9 UART1 RX
Pin 28 GP1 UART RX   Pin 11 GP8 UART1 TX

Note that the TX and RX are crossed over. The PIC is running Circuit Python, this is how to connect a program to this port:

serial_port = busio.UART(board.GP8, board.GP9, baudrate=19200,receiver_buffer_size=500)

Now if the Circuit Python program in the PICO sends data to this port it can be picked up in the PI.

Auto-Start a Pure Data Patch on Raspberry Pi Bootup

Today I needed to find a way to auto start a Pure Data patch when a Raspberry Pi boots up. This is so that the Chocolate Synthbox (patent pending) can play sounds without the owner having to do anything to get it going.

Above you can see how I did it. The /etc/xdg/lxsession/LXDE-pi/autostart file contains commadns that are obeyed once the desktop has loaded. I used this command to start the editor:

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

I added the line you can see at the bottom:

sudo pd /home/pi/Desktop/Synthbox/ChocSynthboxMain.pd

This works well for me because the file Synthbox on my desktop contains the file ChockSynthMain.pd If you want to use it you change this to the location of your Pure Data patch.

You can use this technique to start any other programs on power up.

Player 2 has entered the game....

I hate it when I can’t get things to work. The Lora board I was playing with yesterday has all the hallmarks of a great product. It is excellent value and has some lovely hardware features. But when I try to send a message to a Lora TTN gateway all the addresses end up garbled. Fortunately Brian has also bought the same board and it doesn’t work for him either, so I feel a bit less alone now…

Rob at emfcamp

I’m really looking forward to emfcamp this year. I went to the last one four years ago and it was excellent. Last time I attended lots of splendid sessions and just enjoyed the atmosphere. This time I’m presenting as well. I’m going to be showing off my Chocolate Synthbox synthesizer and describing how you could build one of your own. It’s going to be great fun. Trust me.

There are lots of other great sessions too. You can find the complete list here.