It's been a busy week with the caravan and it still doesn't look like we've done that much to it - a lot of behind-the-scenes work went on over the weekens to sort out some of the electrics. The 240v system has had an overhaul. There were some interesting choices going on there, like the standard single socket hanging from the underside of the caravan, the discovery that between 1 and 4 sockets were not earthed - I don't know for sure how many because I'm not sure which earth wire was tucked behind the pattress, and decidedly weedy cable used for wiring some double sockets! I've also started first fix for the 12v extensions for new kit, and the speaker wiring.
Under-cupboard LED strip (in soft focus ;-)
I've now replaced all bar one of the strip lights with LEDs and the ambient light is looking much nicer. I'm particularly pleased with the kitchenette light, which has gone from being a grotty strip light to a concealed LED strip below the high cupboards. Just got the toilet one to do, but I'm not quite sure how best to do it, so I might leave it until it's time to decorate.
Anyway, to the real business in hand: the RGB light strip with the Raspberry Pi! The MOSFETs I ordered finally showed up, which meant I could construct the test circuit on a breadboard. For those that don't know, a MOSFET is a transistor which works a bit like an electronic switch, allowing a lot of current to be switched by a low voltage / current to the gate pin. It can switch much faster than a relay, so they're ideal for this project, as the LEDs are dimmed by rapidly pulsing the output rather than decreasing the voltage.
The results were a) I didn't blow myself or any of the components up, and b) the lights looked great and the music synchronisation worked really well. I want to look into the source code to see if the light threshold can be altered, and a delayed fade be introduced if necessary, as some music can make the lights quite strobey, which won't be suitable for everyone.
I also received a wiring header to get the car stereo plugged in. It seems to work OK, although without a working battery and a charger that doesn't have an emphasis on smoothness means there's a fair bit of hum at the moment. It seems go pretty loud without distortion, which is all good. Can't wait to get a new battery!
Exciting times! While waiting for half the lighting electronics to turn up (still waiting for the MOSFETs and a board to solder them into) I thought I'd turn my attention to the coding side of things. I've had to pull out my extremely rusty novice C++ coding knowledge and get up to speed.
It was initially really difficult - finding something that suited my use case and platform. The Raspberry Pi has libraries for a subset of OpenGL, called OpenGL ES (the ES is for Embedded Systems, see https://en.wikipedia.org/wiki/OpenGL_ES ). This means that a lot of the full-fat OpenGL examples have to be adapted. and most of the ES ones are to do with Android and iOS.
Inevitably this has meant a lot of cobbling stuff together, trying to write out other libraries where possible, and lots of looking at black (and white) screens, and scratching my head as to why nothing was happening!
As the week drew on, I've made more sense of exactly what the examples do, and have adjusted them to suit my needs. Until eventually, it worked!
So, my program basically works like this:
Initialise and compile an OpenGL shader program, consisting of:
a vertex shader which draws triangles based on points we feed it
a fragment shader which runs the Julia code, and picks a colour for each pixel on the triangles, with the C vector and scale/offset being set externally
Then, Set some initial defaults for C and scale Loop Check the keyboard for keypresses and quit when there is one Read the mouse and see if it's moved Pass new values to the shaders if necessary Clear the screen Tell the shader program to draw 2 triangles that fill the screen (the shader draws the 2 triangles in the Vertex shader, and applies the Julia fragment shader to them) Repeat
Computing the Julia set in the GPU is great because it's fast at floating point maths, and also means the main CPU can concentrate on all the other things I'll be asking the Pi to do!
I've been away for a few days and it's been great to come back to a few new bits and pieces! The Raspberry Pi 3 is here, as well as the lights. I completely forgot that the new Pi only takes a micro SD card, so I'm moved all my pics and vids from my phone SD onto the computer so I can format it!
Sadly no sign of the components for connecting the 2 together yet, but over the course of the weekend I've managed to rig up the Raspberry Pi with a some test LEDs (one of dubious brightness) and played around with various software to get them to work in a sound activated way.
The best I've come up with so far is Lightshow Pi at http://lightshowpi.org/ which does most of the stuff I was interested in programming - hopefully there will still be some room for customisations! That software will control a ridiculous number of channels though. Here's a little demo of it in action...
I've also embarked on a crash course in graphics programming (and C++ come to that, it's been a while) - looking at the SDL library but might need to go into GLES programming for better speed on the Raspberry Pi. I also need to work out how to get both Lightshow and whatever graphics routine I come up with to both listen to the same piece of music and be reasonable in sync and responsive.
I've also got a car stereo to wire in (but no speakers yet). It's one of those Chinese import ones but it'll play video, does Bluetooth, and has a composite video out, so hopefully I can use it for something useful that isn't just making noise - perhaps a second projector source? I spent some of this afternoon fitting it (well, attacking one of the cupboards with a drill and a saw until it fitted) and started replacing some of the ancient 12v striplight fittings with warm white LEDs. They give a much nicer light at a lower power rate, but it's highlighted that we really need a new leisure battery in the caravan :-(