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/ contains the following:

/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" "">
<plist version="1.0">

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 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.


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

Use SSH tunnel to access remote linux computer

This is a very short reminder for myself how to set up a reverse SSH tunnel between two computers, using an intermediate Raspberry Pi computer that can be accessed from both.

This assumes that you have three computers

  1. A remote linux computer that you want to tunnel to. You should be able execute commands on it, for example through VPN, TeamViewer or so.
  2. A raspberry pi or similar linux computer at home that is in the DMZ of your home network, i.e., it can be directly accessed from the internet.
  3. Your macbook that you want to connect to.

The schematic connection setup is like this:

remote -> raspberry -> macbook
macbook -------------> remote

Continue reading

Calibrating the Sonoff ZNB02 zigbee temperature and humidity sensor

I recently installed a few Sonoff ZNB02 temperature and humidity sensors around the house. Monitoring them for some time, I noticed that the humidity level was higher that what is recommended for a comfortable and healthy indoor environment. Initially this got me worrying about the indoor climate, but as there are no other indications that it is so humid, it made me think that these sensors are perhaps not so accurate. Therefore I decided to calibrate them.

When you mix half a cup of normal kitchen salt with water into a sludge (i.e., a fully saturated solution) and put that in a closed container, that acts as a sort of constant humidity buffer for quite a wide range of temperatures. For a solution of NaCl at room temperature the relative humidity in the container will be 75%.

Continue reading