Low-cost 8 channel MIDI controller

In one of the recent presentations with Per Hüttner we used TouchDesigner for live visuals. The gradual transitions between scenes were implemented using (invisible) sliders in TouchDesigner. However, making a full and smooth transition just having the MacBook touchpad to slide from one to the other side on screen was not so comfortable. Hardware-based MIDI controllers would have much better tactile feedback, like the Novation LaunchControlXL, the Midi Fighter Twister and the Intech controllers. Looking for more affordable options, we found a nicely looking ParksTool 8P on Etsy.

This triggered me to look into DIY options, and I found the M5Stack 8Angle interface, which consists of 8 knobs that connect over a Grove I2C connection to a microcontroller. I ordered the 8Angle interface online for only €15.00 and a matching M5NanoC6 microcontroller for €8.00 which I used to construct a simple 8-potentiometer MIDI interface.

M5NanoC6 microcontroller connected with a 4-wire grove cable to an 8Angle potentiometer controller

MIDI controller based on M5NanoC6+8Angle

The USB interface of the ESP32-C6 does not (yet) allow to do MIDI over USB, but the Control Surface library for Arduino does support MIDI over Bluetooth for the ESP32-C6. To connect it to your macOS computer, you have to start the “Audio MIDI Setup” application.

In the upper right corner you have to click on the Bluetooth symbol to initiate a connection.

The M5NanoC6 shows up as “Control Surface MIDI” and you can connect.

Subsequently it shows in the main panel of the Audio MIDI Setup panel as a Bluetooth device.

Using the excellent MIDI monitor application you can check that the MIDI signals are arriving, and you can assign them to the controls in TouchDesigner or in Ableton Live.

In my Arduino firmware I mapped the 8 knobs of the controller onto Control Change (CC) messages 0 to 7. The small switch on the controller allows switching between MIDI channel 1 and 2. The individual RGB LEDs on the controller change color along with the respective MIDI values.

Hydrophones

With the EEGsynth we are not only working with EEG data but occasionally also with data from trees, from microbes and from cod fish. For the cod fish project we collaborated with Rebekah Oomen and John Andrew Wilhite-Hannisdal on the sounds that cod make during the mating season, using recordings of the “grunting” and “drumming” that were made in previous years at Flødevigen Research Station.

For the Science Festival in Gothenburg we are considering to take it one step further and integrate live video and possibly also sounds from the cod fish that are swimming in the large basin in the Sjöfartsmuseet Akvariet. Recording the sounds to use them live requires hydrophones, i.e., underwater microphones. Commercial hydrophones that are commonly used for marine research purposes are rather expensive, but luckily it is not too difficult to make a hydrophone yourself from a piezo element. I largely followed the process described by Felix Blume. Below I will detail some specific considerations, design steps, and modifications that I made to the original.

I ordered a bunch of 27 mm diameter piezo elements from Amazon. Since I did not have nicely fitting bottle caps, I designed a small round housing that exactly fits the piezo elements. I used my Prusa to 3D-print the housing in PLA, a bioplastic made from corn starch. Copper tape on the inside helps to prevent pick-up from electromagnetic interference. I found out experimentally that the copper tape needs to have a good connection to the copper of the piezo element so that they together form a Faraday cage, otherwise there was still a lot of 50Hz hum.

I ordered two instrument cables of 9 meter each (one red, one blue) and cut them into a 3 meter and a 6 meter section. The stripped cables were then soldered to the Piezo elements.

To ensure that the hydrophones will properly sink, I placed two nuts in the housing and completely filled it with silicone gel. As the hydrophones are to be used in an aquarium, I bought special Seachem silicone sealant in the local tropical aquarium fish store.

I had planned to use a coat of Plasti Dip Multi-Purpose Rubber Coating according to the instruction, but a review of the safety sheet revealed that Plastidip is made from petrol derivates and contains substances that pose a safety hazard to water and marine life. I don’t know whether that is in the solvents which evaporate during the drying process, or also with the remaining solid coating itself. Given the intended use in an aquarium with a closed water recycling system, I don’t want to take a risk and decided to keep the hydrophones bare with the PLA bioplastic and the copper of the piezo element exposed.

With the four hydrophones we will be able to do a four-channel recording of the sound that we record inside the fish tank and play it back spatially on a quadrophonic speaker array.

IR blaster remote control

Previously I wrote how I designed and implemented a 12 Volt trigger for an NAD D-3020 audio amplifier and on the PCB version to automatically switch the amplifier on and off. In response to those posts I occasionally receive comments asking why I am not using an IR remote control instead of the 12V trigger input. The advantage of IR is that it also allows switching to the corresponding input, and allows to control other devices as well.

A lot of the available IR blasters come with some form of cloud-based integration such as Amazon Alexa, Apple Siri, Google Assistant or Tuya. I am not a big fan of those and prefer to implement my home automation without big tech looking along. Tasmota is a great platform for that; it implements a firmware that can be combined with all sorts of sensors, switches and actuators based on the ESP8266 or ESP32 modules. In the past low-cost IR blasters based on Tuya would have an ESP8266 module and could be flashed with Tasmota, but nowadays many Tuya devices use another non-compatible wifi module.

There are also ready-made ESP8285 IR blaster modules, which are very cheap on Amazon or Aliexpress. I decided to implement my own and learn a bit more along the way. I ordered 6 of these IR LEDs and this HX1838 IR receiver. After an initial design and test on a breadboard, I implemented it as a shield for a Wemos D1 mini.

While translating the initial working design from the protoboard to the perfboard, I initially made the error to use pin D3 for “IRsend” and D8 for “IRrecv”. This would not work for both, seemingly because of their special functions and/or internal pull-up or pull-down resistors of the ESP8266. This page has a lot of details and here is a clear list that orders the best input and the best output pins to use. I switched “IRsend” and “IRrecv” to the neighboring pins D2 and D7, after which it worked fine again.

Note that the old Wemos that I still had lying around is a cheap clone with the micro-USB connector on the opposite side as the ESP12F module. Modern ones have the ESP chip directly mounted on the PCB rather than in the form of an ESP12 module with a metal cap, making the whole design more compact. Due to the way I soldered the stacking pin headers, the pinouts on the board are left-right mirrored compared to what I would consider the normal orientation.

This shows the top and bottom of the IR shield:

The photo below shows the IR blaster mounted underneath the corner of our couch, using a paperclip and some safety pins. The couch is about 3 meter distance from the TV and audio setup.

Unicorns are multiplying

This page is part on a series on the Unicorn EEG system, see also the other posts on the design of the alternative case and wet “sponge” electrodes, and on the native Python interface for Linux and macOS.

Following the design and implementation of the 3D printed case for the Unicorn EEG system, I have had some chance to evaluate it and make some design modifications. The most important is that rather than using the 5×2 shrouded male header ( or “box header”) that needs to be soldered to the 10 tiny wires, I switched to an insulation displacement connector (IDC) version that is clamped on the wires. I still need to squeeze each of the individual wires between the teeth (using pointy squeezers), but that already makes the fabrication much easier. The connectors I used are these, which are similar to these but with “ears” that nicely slot in the sides of the 3D printed enclosure, which also means that no glue is needed any more.

I made 4 so far for various projects and collaborators, all using the standard 5×2 male headers.

Recently we did a demonstration at the Tekniska Museum in Stockholm where visitors could try the EEG out. Combining three different sized S, M and L Unicorn caps (each with its own set of dry electrodes connected to a female 5×2 header) and a single Unicorn EEG amplifier (with the new male header) worked like a charm. The back of the enclosure still has the magnetic mount, similar to the original Unicorn case.

Switching the amplifier by unplugging it from one cap and plugging it into another one without even turning off the amplifier or software made it very easy to maintain attention to the visitors and keep a smooth flow in the EEG demonstration, not having to struggle with reconfiguring the hardware for different head sizes.

Backing up a macOS home directory using launchd

Apple Time Machine can be used to make backups of the whole computer. Launchd serves to start a process at specified intervals and can be used make regular backups of a certain directory, for example your home directory.

The example below starts a bash script every 10 minutes, which calls rsync to do the actual backup over ssh. I implemented this to back up to a Raspberry Pi with a large USB disk attached. It requires the public/private ssh keys to be shared between the two machines.

The bash script /usr/local/bin/backup2fileserver.sh contains the following:

#!/bin/bash
/sbin/ping -c 1 -q fileserver.local || exit 1
/usr/bin/rsync -a /Users/robert robert@fileserver.local:/media/backupdisk/

I made the plist file /Library/LaunchDaemons/com.zerowidth.launched.backup2fileserver.plist with launchd instructions to start the script every 600 seconds using this online launchd plist generator. It contains the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.zerowidth.launched.backup2fileserver</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>/usr/local/bin/backup2fileserver.sh</string>
</array>
<key>UserName</key>
<string>root</string>
<key>StartInterval</key>
<integer>600</integer>
</dict>
</plist>

Subsequently I used the following command in the macOS terminal to tell launchd to manage the backup script:

sudo launchctl load -w /Library/LaunchDaemons/com.zerowidth.launched.backup2fileserver.plist /Library/LaunchDaemons/com.zerowidth.launched.backup2fileserver.plist

12 Volt trigger for audio amplifier – PCB version

Previously I wrote how I designed and implemented a 12 Volt trigger for an NAD audio amplifier. Some time ago I also designed a PCB version of it. Here you can find some photos and the Eagle schematic.

There is one error in the design: the GND pin of the Wemos D1 mini board is not connected to the ground plane. I solved it with an air wire.

Some of the differences to the previous version are that it now has a button, a 12V input trigger, and a status LED. The button allows to manually switch it on and off without having to use my mobile phone. The 12 V input trigger allows the amplifier to be switched on by and off by the Sonos Port that is also connected to the amplifier.

I am using Tasmota as the firmware which – besides the button to switch it on and off – allows control over a web interface and over MQTT. The Tasmota template for the configuration is the following: {"NAME":"12V trigger", "GPIO":[1,1, 1,1,32,288,0,1,256,1,160,1,1,1], "FLAG":0, "BASE":18}.

The MQTT interface makes it easy to implement some automation with Node-RED that I have running on a Raspberry Pi. The automation is the following: whenever the smart TV or the MacMini (used for music) are switched on, as detected by them returning a network ping on their IP address, then the amplifier switches on, and vice versa.

I also have it configured using Homebridge in my Apple Home environment, which allows the Home application on my iPhone or iPad to manually control it, besides the Tasmota web interface.

Combining all of these, the NAD amplifier is switched on and off by either

  • the manual button
  • the smart TV (detected by an IP ping)
  • the MacMini (detected by an IP ping)
  • the Sonos Port (detected by its 12V output trigger)
  • the Apple Home application on my iPhone/iPad
  • the Tasmota web interface

However, the automation is not perfect: when after an afternoon of listening to Sonos we switch on the TV and switch off the Sonos Port, the Sonos Port only falls asleep after a minute or so. Consequently, the last action happens to be the Sonos Port 12V output going low; the amplifier therefore switches off after a minute or so, whereas we just switched the TV on. A quick press on the manual button switches it on again. Also, whenever we switch between MacMini, TV, or Sonos, we still have to walk to the amplifier to toggle it to the right audio input. An idea for the future is to mount an IR blaster that switches between the audio inputs automatically.

Native Python implementation for Unicorn wireless EEG data

This page is part on a series on the Unicorn EEG system, see also the other posts.

The Unicorn EEG system is a low-cost wireless 8-channel EEG system including an IMU and the “naked” version lends itself well to making your own 3d-printed enclosure as I demonstrated here. Most important for me is that it “just works”.

As the software that comes with only works on Windows and I prefer macOS, I made a platform-independent native Python implementation for real-time data streaming. My example streams the data to LSL, but can also be used as a starting point for real-time processing. See the gist of unicorn2lsl.py on GitHub.

Unicorn Naked case and connectors for EEG, EMG and ECG

This page is part on a series on the Unicorn EEG system, see also the he other posts for a review of the Unicorn Hybrid Black, and the design and prototyping of alternative wet “sponge” electrodes.

The Unicorn Naked comes with the same dry electrodes and electrode leads (wires) as the Unicorn Hybrid Black. However, there is no real advantage of the Naked version over the Hybrid Black version if you want to use them with the same electrodes, unless you insist on a 3-D printed headset to hold the electrodes in place instead of a cap. We figured that the small size and weight, and it being wireless, made it an ideal candidate for developing a wearable system for EEG research on infants and children. At the same time, we sometimes have other applications where a small and wireless ExG system would be useful, for example to record EMG from the muscles or ECG from the heart.

This first image shows the result, further down on the page you can read more on the details and design considerations.

3d-printed unicorn naked case and connectors

Continue reading

Unicorn Naked EEG system with wet “sponge” electrodes

This page is part on a series on the Unicorn EEG system, see also the other posts for a review of the Unicorn Hybrid Black, and a 3D-printed case for the Unicorn Naked with connectors for EEG, EMG and ECG.

Together with the Unicorn Hybrid Black EEG system that I reported about in another post, I purchased a Unicorn Naked system. It is basically the bare PCB board of the Unicorn Hybrid Black amplifier, including connectors and electrodes, but without the housing and the cap. It comes with a LiPo battery, the cable bundle to connect the electrodes (including the LED strip), a set of 8 dry electrodes, a pack of 50 stick-on electrodes, and a Bluetooth USB dongle. It pairs with the computer just like the Unicorn Hybrid black and uses a unique device name; mine is UN-2022.01.10, which suggests that it includes the date of production and the serial number.

Although it comes with the same g.SAHARA Hybrid dry electrodes as the Unicorn Hybrid Black, the reason for me specifically getting the Naked version is that I want to attach other types of EEG electrodes and also use it for other biosignals like EMG and ECG. For EEG there are four types of electrodes that are common:

  • electrode paste, often combined with cup electrodes
  • electrode gel, usually applied with a syringe
  • wet sponge-like electrodes with saline solution, i.e., salt water
  • dry electrodes

The advantage of dry electrodes and wet sponge electrodes over the others is that you can put them on quickly, you can put them on on yourself, and they don’t leave any residue. Electrodes with gel or paste are more suited for a lab environment where a researcher or clinician applies the electrodes to the participant or patient.

However, they all share the same basic physical principles to pick up the potential differences on the scalp due to activity in the brain. Electric currents that flow through the head due to neuronal activity in the brain consist of ionic currents, i.e., these currents correspond to the displacement of positively charged Na+ and K+ and negatively charged Cl- ions. On the other hand, in the amplifier, the lead (wire) and the electrode the electric current is conducted using electrons. The electrode makes the contact with the nonmetallic part of the circuit, i.e., the scalp. The concept of the electrode as the interface between conductive and non-conductive materials has been long known and also applies to fields outside of neurophysiology; the Wikipedia lemma puts this nicely in perspective and provides links to the electrochemistry that happens at the interface.

On this page I present the details and design considerations for sponge electrodes that I constructed myself, based on Ag/AgCl ring electrodes that I had available. The design that I currently consider the most optimal due to its simplicity is electrode design 7. You can find more details further down on this page, including links to the sponge material.

Continue reading

Review of the Unicorn Hybrid Black 8-channel EEG system

This page is part on a series on the Unicorn EEG system, see also the other posts on the design and prototyping of alternative wet “sponge” electrodes, and a 3D-printed case for the Unicorn Naked with connectors for EEG, EMG and ECG..

I am exited to report on the Unicorn Hybrid Black EEG headset that I received a few weeks ago and that I have now been able to explore. Together with colleagues from the Donders Institute, the Baby and Child research center and the Body Brain Digital Musical Instrument project we are going to explore this system, both for non-intrusive EEG measurements in young children and for EEG biofeedback for creative musical applications.

The Unicorn is a low-cost 8-channel wireless head-mounted EEG device developed by Gtec and first released in 2019. Gtec has been developing research-quality EEG systems for Brain-Computer Interfaces for a long time, and in recent years have been organizing a series of BR41N.IO hackathons that target hackers/makers and creative applications. I have worked with Gtec systems at a number of BCI2000 workshops, and we used the Gtec Nautilus for the Cogito in Space project (see also here) Given this background, I had high expectations for this new system and the Unicorn does not disappoint.

Unboxing

It arrived in a nicely designed and environmentally friendly cardboard packaging, including dry electrodes, a pack of 50 stick-on electrodes for the reference and ground, a medium-sized cap, an USB Bluetooth dongle and a micro-USB cable for charging. The Bluetooth dongle was not needed to get it working, it also works fine with the built-in Bluetooth of the Lenovo Yoga and Lenovo Thinkpad laptops that I tested it with.

Continue reading