Cirrus Logic audio card for the Raspberry Pi revisited

There is more green space and trees around me where I am now, with many more garden birds, though no sparrows1, and occasionally some tawny owls in the night.

Tawny owls, recorded ME66 handheld

So thoughts turn to a garden recording gizmo again. I have enough power, and a network connection to a shed, a oddly wind-sheltered location and many trees nearby. For short term recordings in the field I am still in favour of the timed field recorder approach, but for the garden where I have power and data the Pi still scores. You don’t have to fiddle with it, it’s entirely remote controlled. Many years ago I had a PC in the garage which was the music server, I used a piece of software called loop recorder on that. This cat fight is one of my favourite urban recordings from that time.

although I was really trying to record a hedge full of sparrows. A loop recorder lets you go back and catch things like that, and the microphone would be much closer to the area where the owls are.

So I thought I’d revisit this Cirrus Logic audio card, particularly as a case for a Pi with this mounted was being sold off cheap for £5

The Cirrus is the only audio card for the Raspberry Pi that lets you record sound with it, as opposed to the legion of DAC cards for the Pi. You can, of course, use a USB sound card instead, though that precludes using a Model A if you want to use wifi and have the lowest power.

The good news is that a hero hacker, Matthias Reichl, has sorted out the drivers, it’s now a RPI-update rather than patching kernels and esoteric crap.

The bad news is that the manufacturer discontinued the card 🙁 Having said that, it still seems to be available for about £60 if you work hard enough, GIYF. That’s dear – a Behringer UCA202 is a good Pi compatible USB sound card for about £24, line level input. The Cirrus Logic card offers a bit more sensitivity and on board mic bias. Continue reading “Cirrus Logic audio card for the Raspberry Pi revisited”

Solar Powered 12V lighting system

This project is about resilience more than energy saving, though it can also be used to save energy. Total costs should be in the order of £100, but there are ways to reduce that by getting some items from Ebay. The idea for the project came from the Transition Ipswich Energy group in 2011. It had to be targeted at a competent DIYer, and is for small scale lighting. This was originally published on TI’s website, which is no more.

This project lets you run lighting off of solar power, effectively storing sunlight for later use. It can be used at home to keep lighting during power cuts, but the same principle can be used to provide power to sheds on allotments, outbuildings or island sites without mains power. Although I have used lighting as an application, such a system can run an electric fence for much of the year if suitable solar panels and battery are used.

The system as described lets you run one or two 12V 1.8W LED lights through the year – my system was able to run mine through the winter and the shortest day where the light would be on from about 6pm to 11pm. In the summer you can also run a laptop computer power supply independently of the main for a couple of hours (these run typically 40W). That is because in the summer you get far more solar energy and you’ll probably use the lighting less.

If you want to primarily save energy or reduce your carbon footprint using solar power, this is not the solution. For that it is best to get a grid-connected solar power installation which will allow you to save energy and get renewable feed-in tariff payments. That sort of thing is on a different scale from this project, and capital costs are usually in the order of several thousand pounds, but the energy savings are much, much greater. A grid-connected solar PV system does not give you resilience against power cuts, because the anti-islanding systems in the grid tie inverter shut the system down if the main power fails, so that a PV system does not send power back into the grid when it may harm power workers trying to repair faults.

Continue reading “Solar Powered 12V lighting system”

Raspberry Pi camera after several years outside

It doesn’t pay to put a Raspberry Pi camera out directly facing the great British outdoors for more than a season even if you can keep the water out of it. I had a RPi Model B and camera doing just that and groused about the lens crazing problem where there seems to be some sort of microbial attack on the lens after a season outdoors.

damaged Raspberry Pi lens
you can just about see the grungy effect on this damaged Raspberry Pi lens which was outdoors for a season. The mechanical marks around the outside is because you have to break the glue to get the lens out. I did not mechanically damage the lens.

That didn’t respond to pretty aggressive scrubbing with isopropyl alcohol (IPA), and the Pi lenses are proprietary.

the lens on its own
the lens on its own

The back side of the lens not facing the elements looks fine

Sensor side of the lens
Sensor side of the lens

They are not standard M12 CCTV lenses1, so I got to buy another camera board, and used Sugru and a cut down glass microscope slide to try and keep it intact. I can buy aftermarket RPi compatible cameras using M12 CCTV lenses now, but then it wouldn’t fit in the PICE case.

Pi camera behind glass
The Pi camera is still bright-eyed after three years in the outside, behind a glass microscope slide

I left this camera out in the open on the farm for a while, and then watching my sparrows on the feeder. It looks like the glass slide technique has been a win, it’s been around three full years and the camera lens is still OK. The slide can be cleaned with IPA and comes good as new. Angling it down slightly reduces reflections and flare, but yes, it is uncoated so flare will happen. I built the Sugru up a but round the top to make a lens hood to minimse the amount of open sky that falls on the glass. Maybe the original Pi camera lens is plastic and gets eaten, although I know to my cost that optical coatings on glass can get hit by fungus too in damp conditions 🙁 Continue reading “Raspberry Pi camera after several years outside”

Experiences with the Vilistus EEG interface

I went to an open day in October run by the mind people, makers of the Vilistus EEG interface. It was an opportunity to see this in action and ask questions – the day was £85 which wasn’t too bad, there were about five other people there. It was run in some anonymous hotel near a football ground in Birmingham just off the M6, and led by Stephen Clark who knew the product well.

It was an interesting day, the Vilistus 4 box is a digitising interface but analogue signal conditioning is done in the sensor boxes, which add some cost to the overall system. Their default software looks fine even for Mind Mirror since it seems to have the filter bank in it, the extra costs for the Mind mirror package probably involves extra training. You seem to get the vilistus pro software with the box. I haven’t seen any of the units come up on Ebay.

I learned that the interface between the Vilistus interface and the computer is OpenEEG P3, which was good to know, and Stephen did warn that a lot of the older OpenEEG code from the OpenEEG project made the assumption that there were only 6 active slots rather than following the protocol specification which allowed the source to say whether there are 6 or 8 slots of data. Vilistus use 8 slots, so code assuming 6 would barf.

He did say the existing API would allow the Vilistus Pro software to continually dump the values of the filter slots to a text file that could be read by a program to display the output on LEDs, obviously I would get to build the interface and write the program 😉

The Vilistus Pro software did show correlations well – most clearly on a display where they showed heart rate against a trigger for breathing in and out. The heart rate slows a teeny bit on breathing out relative to breathing in, although this effect fades with age – it was clear on the 25 year old student and not really visible on a 50-something lady on the course. EEG was tough to get going in the course, although it was demonstrated using disposable electrodes on the forehead. This isn’t the optimal placement for Mind mirror but you can’t use disposable electrodes on areas of the scalp covered by hair.

The trouble is this rig would be about £1200 all in, and I’m not yet sure I am £1200 interested in the Mind Mirror. I did get a much better feel for using this in the field, and I’m aware that while I have been able to solve the digitising side of things using the PIC, I still need to solve the EEG diff amp, and solve the electrode problem.

Vilistus seem to have solved a lot of that, but even the electrode set is ~£200, so the bundle would be the way to go. One to mull over really, to work out whether I want the functionality or the engineering challenge. I could probably knock off £500 going DIY if the development went OK, but experience shows only one to two PCB fails or wrong turns can wipe out the savings on a one-off project where there’s a COTS solution.

One to think about. The Olimex EEG-SMT and 4 electrodes is about Euro100 – okay so it has the iffy antialiasing filter but a £1100 saving has its attractions 😉


Oscilloscope options – standalone or PC based?

I started redecorating the lab, so the EEG project is now relegated to an Autumn/winter project 😉 Which is a shame as I’d got close to replicating the Mind Mirror system in Open EEG and getting a hardware gizmo set up using a PIC. The best laid plans of mice and men…

Just before I cleared it down I tested a device I’d been given by Jason Wildlife Gadgetman when he was clearing his lab out getting ready to move. The DrDAQ is a bare-board device made by Pico Technology. which shows a lot of promise for the openEEG testing.

DR Daq from Pico Technology

It’s basically a single channel digital oscilloscope, but it works with Picotech’s Picoscope software, which has all sorts of features that are new to me, like software RS232 decoding, click to set trigger levels, and long persistence simulation.

I have a decent Tek 2245A analogue scope, which computes frequency and voltage levels from cursors on the traces,

This is now very old , from 1989. It does most of what I want/need, and most of my design career I worked with analogue ‘scopes, with the logic analyser as a separate piece of gear. However, despite its measly 100kHz bandwidth the Pico did show me some of the attraction of a more modern approach. Every so often I’ve toyed with the idea of getting a Chinese scope, something like Rigol 2000 series or similar. So far I haven’t cracked. There’s a lot to be said for a standalone scope, but I wonder if the combination of my regular analogue bench scope together with a Pico will be even better.

EEVblog did take the piss out of the cheap Chinese DSOQuad FPGA scope, and I’d agree with him. I got one of these DSO Quads  to be able to print out slow captures like the one in this project, and it works well enough at that

but it would be a terrible thing to do to give this to a beginner. I could only make this thing trigger properly because I’ve used analogue scopes for years and had some feel for what should happen – all too often on the FPGA scope if the vertical trigger wasn’t in range you simply don’t get to see anything useful at all, so you can’t see which way to shift the trigger point. And the user interface is revolting. Too much clickety-click of two separate left-centre-push-right buttons for my liking.

Picoscope is far better thought out although it still suffers from the problems of not enough control of input sensitivity and offset as a regular bench scope. But it, and the associated DC coupled arbitrary waveform generator will be a great tool for testing the OpenEEG filters at sub-audio frequencies. And unlike the typical fly-by-night USB scopes, the software supports legacy models back to when Pico started, because that is of course always the problem with any hardware that depends on a piece of software running on some other device – it easily becomes orphaned before its service life is over. See pretty much any hardware made by Apple that is more than three or four years old 😉

The DrDAQ does pretty much all that I want for the EEG work, but the AWG doesn’t support frequency sweep mode which is a shame. I’d need to go for something like the 2206B at £250 to get that. In that case I’ll probably do it the old way and set up the AWG to output a single frequency and step through the frequency range. What isn’t clear is the frequency resolution of the AWG.


Using OpenEEG’s Fiview to reproduce the Cade-Blundell filters

Now I have convinced myself that I can get a version of the OpenEEG hardware to run into EEGmir, I want to how see if I can reproduce one of the Cade-Blundell filters. I have an analogue simulation from earlier, and I want to see if I can reproduce this in EEGmir. The filter specification protocol in EEGmir is the same as in Fiview from Jim Peter’s site[ref]they use the same underlying library, fidlib[/ref], and since that displays the transfer function it looks like a good place to start.

a tale of linux graphical display woe…

The windows version doesn’t run, beats me why. So I try it on Linux. My most powerful Linux computer is an Intel NUC but because Debian is hair-shirt purist and therefore snippy about NDAs and proprietary drivers, I think it doesn’t like the graphics drivers. It was tough enough to get the network port working. Xserver and VNC is so deeply borked on that. If something is stuffed on Linux then it’s reload from CD and start again because I haven’t got enough life left to trawl through fifty pages of line noise telling me what went wrong. So I’m stuck with the command line. So I try fiview on the Pi, and this fellow sorts me out on tightVNC and the Pi which is a relief, trying to get a remote graphical display on a Linux box seems to be an endless world of hurt, and I only have a baseband video monitor on the Pi console.

Simulating the 9Hz Blundell filter

I already have SDL 1.2 on the Pi, so it goes. Let me try the 9Hz channel, which was the highest Q of the Cade-Blundell filters. If you munge the order and bandwidth specs you get fc=9Hz BW=1.51.

Converting that to Fiview-speak that is

fiview 256 -i BpBe2/8.22-9.72

which in plain English means simulate a sampling rate of 256Hz bandpass Bessel 2nd order IIR between 8.22 and 1.51. So let’s hit it.

fiview on the 9Hz Cade-Blundell filter. Shame about the linear amplitude axis…

Unfortunately the amplitude axis is linear, which is bizarre. Maybe mindful of their 10-bit (1024 level) resolution OpenEEG didn’t want to see the horror of the truncation noise and hash. I can go on Tony Fisher’s site (he wrote the base routines Jim Peters used in fiview) and have another bash

The same filter with a log amplitude scale, but a linear frequency scale Grr…

Running the analogue filter with the same linear frequency display I get

The analogue filter in LTspice on a linear frequency scale (256Hz × 0.15 = 38Hz, roughly the same endpoint as the digital chart)

which shows the same response[ref]It’s not strictly exactly the same because of the increasing effect of the frequency warping of the bilinear transformation as the frequency approaches fs/2. But in practice given the fractional bandwidth of the filters the warping only has an effect in giving the upper stopband a subtly different shape in the tails, I struggle to see it here.[/ref]. H/T to the bilinear transformation for that. I had reasonable confidence this would work, I did once cudgel my brain through this mapping of the imaginary axis of the s plane onto the unit circle when I did my MSc. Thirty summers have left their mark on the textbook and faded the exact details in my memory 😉 But I retained enough to know I’d get a win here.

My late 80s digital filtering textbook after many years

Modding the OpenEEG analogue to digital converter and comparing with OpenBCI

Now I can get signals into the OpenEEG modP2 format, the next stage is to qualify the filtering used within eegmir and to put an antialiasing filter in front of the ADC. The sampling rate is only 256Hz, so the highest frequency possible is 128Hz. Anything else will alias down, particularly frequencies +/- 50Hz of 256Hz, which will be aliased down to 0-50Hz and corrupt my area of interest. This includes the fourth, fifth and six harmonics of the 50Hz power frequency and the second harmonic of the 100Hz full-wave rectifier ripple tossed onto the powerline by every switched-mode power supply in the neighbourhood.

OpenEEG are good enough to put their schematic up on the Web, so I simulated their antialiasing filter.

Simulation of OpenEEG analogue filtering injecting signal at Electrode DC checkpoint, front-end isolated. Line is at the Nyquist frequency fs/2

Hmm, colour me underwhelmed. At a 10-bit resolution the steps are 1/1024, so quantisation noise is 20×log(1/1024) or about -60dBFS. So you’d like to be 60dB down at fs/2 of 128Hz, which is where I’ve drawn the line. We are at, …drum roll…, -16dB by then. At least the crap there gets aliased to the high frequencies, but by fs we are at -26dB. Nice try, but no cigar. I guess that’s the price I pay for saving myself the grunt of lining up all those analogue filters. TANSTAAFL and I get to try harder here. At least there are only two of these filters.

Elliptic filter design

The obvious way here would be to get an elliptic filter and target a notch at fs/2 and another at fs. I had thought there would be an online calculator by now, but perhaps nobody makes analogue filters any more[ref]You can do this with Matlab it appears, if you have a spare £1800. That looks a lot easier then the filter table process I used[/ref]. So it’s back to the Williams book. It’s all about the ratio between stopband and passband. The stopband is non-negotiable at fs/2, say 120Hz so hopefully a notch will be dropping just beyond that into 128 Hz. I have flexibility on the passband, the Mind Mirror goes up to 38Hz, say I choose a passband cutoff of 60Hz, I get a steepness of 2. I’m easily prepared to take a passband ripple of 0.3dB (p=25%)[ref]Electronic Filter Design Handbook, A Williams, McGraw-Hill, 1981, Table 2-3[/ref] so I am after a C ?order 25 ?theta

From Table 2-2 I want Θ=30° for my steepness of 2, so I want a C ? 25 30 filter, with only the order to determine. I’d really like that to be 3 rather than 5 😉 Sadly I look up C 03 25 28[ref]Electronic Filter Design Handbook, A Williams, McGraw-Hill, 1981 Table 12-57[/ref] and the stopband is only 30dB. Shifting Θ=20° would give me a steepness of 3 and a stop of 40dB, so my passband comes down to 40Hz

A C 05 25 32 would give me a stop of 60dB, I will give some of that up in component tolerances, but it’s better than 16dB and gives me some chance to fight all that mains rubbish, so let’s take a look.

the magenta line is the theoretical version, the green using preferred values. The blue line is the original OpenEEG one

It’s not bad. I’d probably want to shift the corner frequency down by 5Hz. It’s good that it isn’t anywhere near as sensitive to component values as the Cade-Blundell bandpass ones were, the shifts due to preferred values were significant but the traces are close. For comparison the original OpenEEG line is in blue. The filter is complex, but not terrible, I can take solace that this is the quid pro quo for not having to line up all those 54 filter centre frequencies 😉 Continue reading “Modding the OpenEEG analogue to digital converter and comparing with OpenBCI”