Category Archives: Technology

Raspberry Pi – first steps to blink a LED with Python

I already purchased my first Raspberry Pi in 2011, but have been postponing connecting any electronics to its GPIO interface. Instead, I have been using it for more general computing applications (media center, web server, remote ssh access and tunnel, etc.). Rather than using the Raspberry Pi for in refacing with hardware and IOT, I have been using a bunch of Arduino’s to implement sensors and actuators for home automation.

Since I recently have been brushing off my Python programming skills for the EEGsynth project and been teaching myself Node JS, I was triggered to revisit the Raspberry Pi for GPIO electronics. With the Raspberry Pi it will be easier to implement my own web server and to use webhooks to integrate my home automation hardware projects with online platforms such as IFTTT.

I decided to try Python first and after browsing the web decided to use the WiringPi interface, as it supports C programming in the same style as on the Arduino, but also has wrappers for more high-level languages (Python, PHP, Ruby and Perl).

I started with installing the WiringPi library as per instructions

git clone git://git.drogon.net/wiringPi
cd wiringPi/
./build 

and tested it with a LED in series with a 680 Ohm resistor attached to the first GPIO pin, aka pin 17 on the Pi cobbler. I still have to wrap my head around the pin numbering, but understand that there are different numbering schemes.

Subsequently I ran the test from

cd examples/
make blink
sudo ./blink

and also tried out this on the Linux command line

gpio write 0 1
gpio write 0 0
gpio write 0 1
gpio write 0 0

This all worked as expected and the LED would nicely blink. I subsequently moved on with Python. Instead of following the detailed installation instructions, I simply tried

sudo pip install wiringpi

which worked like a charm. The following Python code

#### this is blink1.py #### 

import wiringpi
import time

wiringpi.wiringPiSetup()

wiringpi.pinMode(0,1)

while True:
    time.sleep(0.5)
    wiringpi.digitalWrite(0,1)
    time.sleep(0.5)
    wiringpi.digitalWrite(0,0)

works with sudo, i.e.

sudo python blink1.py

As with the pin numbering, it is still a bit of a puzzle to me when super user rights are needed and when not. But the following worked for me without sudo

#### this is blink2.py #### 

import wiringpi
import time
import os

wiringpi.wiringPiSetupSys()

os.system('gpio export 17 out')

wiringpi.pinMode(17,1)

while True:
    time.sleep(0.5)
    wiringpi.digitalWrite(17,1)
    time.sleep(0.5)
    wiringpi.digitalWrite(17,0)

and then on the Linux command line

python blink2.py

It is already rewarding to see a simple LED blink. Next challenges will include combining it with a RFM12B or RFM69CW module to have the Rasperry Pi receive the messages from the (battery operated) Arduino’s for which I use the RFM12B for communication.

Furthermore, Adafruit has a nice tutorial showing how to use Node JS with a Raspberry Pi. That is also something to explore…

Raspberry Pi as Eurorack synthesizer module

Processing realtime EEG data from the OpenBCI system requires software running on a computer. For the EEGSynth project we do the rapid application development using the platforms that we are most familiar with, i.e. standard laptops and the FieldTrip toolbox, which is based on MATLAB. However, in the end we want to implement as much as possible using affordable and open hardware and software. Hence we opted for the Raspberry Pi, a credit card–sized single-board computer. It runs Linux, which makes it easy to use standard programming platforms and interfaces such as Python and Redis to implement the software stack.

In the first EEGSynth studio performance you can see Stephen in the middle, operating the MATLAB-based GUI for the EMG/EEG processing, and Jean-Louis at the back operating the synthesizer. The goal of the technological development is to put Jean-Louis completely in control and to make the interface of the EEG synthesizer as similar as his other modular synthesizer modules. Hence the need for fitting the Raspberry Pi into a Eurorack synthesizer case.

Here you can see some photo’s from the construction of the front panel.

2015-11-14 15.32.52 2015-11-14 16.30.57

The front plate has holes for the various interface ports to interface with the Raspberry Pi. For a sturdy mount I glued a section of L-profile rails to the front plate.

2015-11-14 21.36.36

After mounting the Raspberry Pi, I connected the HDMI and audio port with a short cable to the front panel.

DSC_0061

Here you can see the Raspberry Pi in the Eurorack case, next to the power supply.

DSC_0084

Eurorack power supply

I am working on fitting a Raspberry Pi as a Eurorack module in the EEGSynth. A previous post shows the completed case. Besides the Raspberry Pi which needs 5V, it will also hold a CV/Gate controller and some other modules for interfacing between the digital and analog parts of the synthesizer. The operational amplifiers and some other ICs on those modules require a symmetric positive and negative rails.

As I am not planing any critical parts that require an very stable voltage (such as a VCO) in my enclosure, I decided not to go for an expensive linear power supply, but rather construct one myself on the basis of two 12V switching power supply that I salvaged from some old wall-warts that once served some external 3.5 inch USB hard disks. The AC-DC converters have the 220V side isolated from the 12V side. This allows to connect the positive DC rails of one to the negative DC rails of the other, resulting in +12V and -12V from either converter relative to the common ground.

The Raspberry Pi requires quite a bit of current compared to most synthesizer modules, hence converting the 12V into 5V with a voltage regulator such as the L7805 would not be very efficient. Therefore I also added a 5V 2A AC-DC converter.

DSC_0071

DSC_0069

For safety I made a small plexiglass enclosure using the laser cutter at the Techlab Nijmegen. All electronics, except for the connector, switch and three LEDs are completely enclosed behind the aluminum front panel.

DSC_0072

The connector with the synthesizer modules consists of a flat cable, wired according to the A-100 system bus.

The LEDs show the status for each of the three voltage levels. Surprising is to see that it takes a good 10 seconds for the capacitors of the +12V and -12V to completely drain when switching the power off.

USB to CV/Gate converter: Schematics and Bill-of-Materials

This is a copy of my post on the EEGSynth homepage, the original can be found here.

To link the digital signal processing on a laptop or Raspberry Pi to the analog synthesizer, I have made two usb-to-cvgate converters. The first one I designed and implemented was a one channel version that is able to output up to (approximately) 5 Volt. The second one is an improved version with four channels that can be controlled from 0 to 10 Volt.

Using the EAGLE PCB design software, I have drawn the schematics which should allow others to copy them. Also included below is the bill of materials (BOM) with links to component vendors. I have mainly been shopping on Ebay, you can also get it elsewhere of course.

Details of the one-channel USB-to-CV/Gate converter.

2015-10-03 16.35.52
Details of the four-channel USB-to-CV/Gate converter.

2015-10-18 13.11.43

Monitoring the central heating with an Arduino and two DS18B20 sensors

This post is part of a series on Arduino-based energy and climate monitoring.

About 40% of our energy bill is spent on electricity and 60% on gas, which we use to heat our house and for hot water. Although we do have a relatively recent HR central heating installation, I don’t think that it has been tweaked for efficiency. After reading this post on optimising the yield of the central heating installation, I decided it would be worthwhile to try and acquire some data.

P1130997

I wired up a Arduino pro mini (3.3V) with a RFM12b and a pair of DS18B20 temperature sensors to measure the temperature of the outgoing and returning water of our central heating system.

P1130995

Power is provided by connecting a rechargeable 18650 LiPo battery to VCC on the programming header of the Arduino. This battery provides nominally 3.7V, which in my experience is close enough for the board to work fine. The whole module is mounted in a battery holder for two 18650 batteries.

Every 66 seconds a temperature reading of both sensors is performed and transmitted it to the central relay module. The central module forwards it to ThingSpeak to acquire a long-term log of the behaviour of our central heating system.

You can find the sketch for the Arduino here.

Arduino with CNY70 reflective sensor as KWh meter

This post is part of a series on Arduino-based energy and climate monitoring.

P1130998

Logging electricity use from the KWh meter was the first Arduino project I started. I made various attempts at measuring the KWh electricity usage from our Ferraris KWh meter. Detecting the small black section on the rotating disk turns out not to be easy due to a lot of other reflective surfaces in the meter.

I started off with an Arduino nano combined with a TCRT5000 Infrared Reflectance 2-Channel that I purchased at DealExtreme. The TCRT5000 module combines The TCRT5000 module had two (related) problems: (1) I could not get the calibration to the appropriate sensitivity to detect the rotations of the KWh meter disk, which was probably due to (2) the focus distance of the sensor was not appropriate for the approximately 10 mm distance to the disk.

P1130989P1130990

After trying an OPB740 sensor, I settled for a CNY70 infrared reflectance sensor. I combined it with a 5V Arduino Pro mini and a RFM12b module.

P1130994

The electronics are mounted on a 4×6 cm perfboard, which can nicely be boxed in a repurposed 3xAA battery holder. Power is provided by a USB phone charger. Since the CNY70 is constantly illuminating the rotating disk and the Arduino constantly detecting whether fluctuations in the reflectance, it is not possible to run this from a battery.

P1130993

I recently switched from Nuon to Qurrent and now have a Qbox energy monitor. My attempts of implementing my own energy monitor use have therefore been overtaken by the availability of commercial meters. Nevertheless, I learned a lot and still see the advantages of having my own meter. Right now the Qbox is not yet installed due to the lack of a free Ethernet port in my basement. But as soon as my WRT703N becomes available again, I’ll try to combine the Qbox with my own meter. For this purpose I added a LED, which blinks at every rotation of the disk. I hope that I can have the QBox sensor detect the flashes of this LED, allowing me to use both monitors.

At the time of writing, gas monitoring by detecting the reflective surface in the last digit of the gas meter has not been implemented yet.

You can find the sketch for the Arduino here.

Arduino with BMP085 barometric pressure and temperature sensor

This post is part of a series on Arduino-based energy and climate monitoring.

P1130988

The BMP085 is a barometric pressure and temperature sensor that connects over i2c to a Arduino pro mini (3.3V) with a RFM12b transceiver. The barometric pressure will be the same everywhere in and around the house, but the -40 to +85°C operational range makes this sensor specifically suited for outdoor use.

P1130986

Power is provided by connecting a rechargeable 18650 LiPo battery to VCC on the programming header of the Arduino. This battery provides nominally 3.7V, which in my experience is close enough for the board to work fine.

P1130985

The Arduino, battery and sensor are packaged in a zip-lock bag to keep moisture out and are lying in a shady spot on the balcony. It performs a temperature and pressure reading every 64 seconds and transmits it to the central relay module. Between recordings it falls asleep to save power.

You can find the sketch for the Arduino here.

Module 3 – Arduino with AM2301 sensor

This post is part of a series on Arduino-based energy and climate monitoring.

The AM2301 is a humidity and temperature sensor. It is the packaged version of the DHT21 sensor. I connected it to a Arduino pro mini (3.3V) with a RFM12b tranceiver to record the ambient temperature and humidity in our bathroom.

P1130984

Power is provided by connecting a rechargeable 18650 LiPo battery to VCC on the programming header of the Arduino. This battery provides nominally 3.7V, which in my experience is close enough for the board to work fine.

The AM2301 sensor occasionally returns extreme values outside of the normal range. To prevent these spikes from polluting my ThingSpeak channel, I repeat the measurement. If the voltage is stable within 0.1V, the temperature stable within 1 degree and the humidity stable within 5%, the values are transmitted by the RFM12b.

P1130983                  P1140004

The AM2301 is glued together with the Arduino and battery onto a piece of plastic, which allows for mounting it behind the wall mirror.

It performs a temperature reading every 63 seconds and transmits it to the central relay module. Between recordings it falls asleep to save power.

You can find the sketch for the Arduino here.