Friday, March 04, 2022

3D Printer

I got a 3D printer for Christmas! I’ll try to post some things I’ve printed.

A Polaroid PlaySmart

The first thing I printed, a little heart for my wife! Awww! :)


A dangly key fob thing.

Another dangly key fob thing.

Plus some other bits, which I'll try to track down to photograph.


Tuesday, January 21, 2020

I’ve created my first Magic Mirror module. It displays electric and gas energy usage if you have an Octopus Energy supply.

screenshot

It uses’s Octopus’s public REST API to request usage history.
https://developer.octopus.energy/docs/api/

Very basic, but does the job.

Get the code on GitHub:
https://github.com/christopherpthomas/MMM-OctoMon

Inspired to create this because we’ve just bought a Nissan Leaf (full electric vehicle), and the ‘Octopus GO’ tariff gives us cheap overnight electricity between 12:30am and 4:30am which goes a long way to charge the car! Spotted their API and thought I’d have a crack at it.

Oh and, if you sign up to Octopus with my referral code, we’ll both get £50! Yaaay!
https://share.octopus.energy/amber-lion-261

I’ve had my magic mirror for two years now, and still going strong!
https://forum.magicmirror.builders/topic/5448/my-living-room-magic-mirror

Hope someone else finds it useful!

Thursday, November 09, 2017

Wedding Begging Poem

I got married to my wonderful wife nearly five years ago. We went to loads of wedding fairs, saw lots of wonderful things, and picked each other up off the floor when we found out how expensive everything was. So, we looked at little ways to cut costs, and one of them involved printing our own invites (very tasteful, laser printed, curly fonts, expensive paper, coloured ribbons, wax seal... very sophisticated). We included a fun little poem indicating our preference for cold hard cash instead of gifts, which is an idea we'd nicked from somewhere. I'm sure 75% of the below is repurposed from other sources, but I can't quite remember where those bits end and my bits start, so here is our version incase someone else wants to do the same.


We do not have a gift list,
we’ve got our pots and pans.
Our life is pretty sorted.
We’ve inked out all our plans!

We thank you for your presence,
to celebrate our day.
Your love is all we really need,
to send us on our way.

But if the mood should take you,
and you feel a little flash,
put on a cheque "C. Thomas"
we'd love a gift of cash!

The honeymoon's expensive.
The three kids bleed us dry!
Please don't be too offended, that
we gave this verse a try!

Tuesday, November 07, 2017

Chimney Clock Server

My 'wine box' fileserver was getting a bit creaky... there were no more XP updates, and IIS wasn't the most secure, so it was time to upgrade... and build stuff! By this time the 'maker' scene had really taken off and given me delusions of grandeur, so I thought I'd do things a bit differently this time around. I bought a newer, more powerful mini-itx board, more memory, and bigger hard disks. I also took advantage of the free upgrade from Windows 7 to Windows 10. I was on the bleeding edge!

Even though this was a more powerful board, it was still passively cooled, but to aid the cooling I decided to build it in a 'chimney' configuration, so that warm air escaping out of the top would draw in cooler air at the bottom. My first idea was to paint it in black gloss to make it look like the alien monolith from 2001 A Space Odyssey...


 ...but it was proving difficult to obtain wood in the right dimensions (1x3x9) and I also I don't have any woodworking equipment to make perfectly straight cuts, or to join pieces of wood together with any accuracy. Those problems, and the fact that it would probably need to be pretty big for anything to fit comfortably inside, kind of put the breaks on that idea.

I wondered if I could build the server into a wall clock. Not only would it look nice, but you'd be able to tell the time! However, all the lovely wall hanging ones on eBay were way too expensive to buy second hand, and I didn't relish the idea of destroying a beautiful clock by accident. I did however, discover some ready made A4 sized wooden box files, which are hinged, made specifically for you to decorate yourself, and were almost the same dimension as my original wine box server. I bought two of them and figured they'd stack up on top of each other. They looked a bit like this...


I wood-glued them together, end to end so the lids could open together, and cut a hole to allow air to flow between both boxes. I cut out two sections from the 'base' of each box with a craft knife, to allow for inflow and outflow of air. It worked a treat, but it wasn't very stable stood on the one end, so I got two cheap B&Q pine corner shelves, drilled holes in the edges for dowels, and stuck them together to create a wide semicircular base for the tower, which was glued in place.


More strips of wood were glued in place to provide airflow and support for the mini-itx board, hard disks, and I figured out a mounting scheme for the obligatory big red comedy sized power button. I temporarily used my old mini-itx board as a build template...


A cheap quartz crystal clock mechanism was built into the top lid. To protect the hands from accidental damage, a small square picture frame with a perspex window was glued to the outside. A little bit like this one...


Finally, a couple more moulded wooden strips were glued to the top and bottom of the outside of the boxes and it all had a couple of coats of wood stain, to give it a bit more of an authentic 'clock' look. I also drilled a small hole to thread the power LED light to subtly light the clock face. The hard disk light pokes out the back and illuminates the wall most effectively.


Specs:
Motherboard: Gigabyte J1900N-D2H quad-core 2Ghz Intel Celeron
Memory: 4Gb
Boot HD: 120Gb
Data HD: 3Tb WD Red (2.7Tb formatted)
OS: Windows 10 Pro 64bit (free upgrade from Windows 7 Pro)

Idle temperature: 37°C
Awesomeness: Very

Sunday, November 05, 2017

My First Wine Box Server

I wanted to build a cheap backup file server. Nothing too fancy, it didn't need a high spec, and I wanted it to be quiet and relatively low power, because it would be on 24/7. I purchased a cheap fanless mini-itx board, hard disk, memory, PSU, and set to building it into an old wooden wine box.


First to go in was the mini-itx motherboard. Holes were cut for network cable and for airflow. The thread on the 12V DC power socket was just about wide enough to let me screw it tightly to fix it through the backing board.


Two strips of wood were glued to the back to allow air to circulate more easily from the back side of the motherboard, and also to stop the screws holding it in from popping out through to the outside.


Two further strips were glued inside of the 'top' and 'bottom' of the box (left and right in the above picture), which allowed me to place two snugly fitting wooden props on top of them. The boot and data hard disks rested on the props, which kept them away from the heat sink to prevent any contact or electrical shorting, and permitted airflow.


More airflow holes were drilled (and later enlarged) into the top of the box allowed for a small chimney effect to draw cool air in and hot air out.

There was always a noticable 'warm wood' smell emanating from the box whenever it was switched on. I was of course concerned that it would catch fire, but the box was never under any great load, and the fragrance was actually quite nice. I ran some software called 'motherboard monitor' was was able to graph the cpu and system temperatures thoughout the day. After a couple of days, the temperature remained stable and acceptably low, so I didn't really worry about it.

A big red comedy power switch replaced the cheap little grey square one that came with the motherboard, and a four way USB hub in the shape of a robot was blu-tacked to the top to allow for easy file transfer by USB stick. The robot also has big blue glowing eyes which were useful to show that the server was powered on. The actual power and hard disk activity lights aren't even fixed permanently, and are just unceremoniously poking through one of the airflow holes.


One spare install of Windows XP later, and it worked great! I also included a webcam, some software to take pictures and turn the webcam into a security camera, and installed IIS to let me view the latest picture. Port 80 was forwarded from my home router, and hey presto, remote webcam monitoring!

With no fans, and barely audible hard disk activity, this was an ideal server to have in the living room, connected via ethernet cable to my home router. Thankfully it never did catch fire, and in the five or so years it was running, it was powered on 24/7. A great first 'maker' project!

Wednesday, November 01, 2017

Magic Mirror - build part 4

We had been away on holiday. We returned to discover the magic mirror stuck in a reboot cycle. I hadn't backed anything up. Crisis!


Troubleshooting consisted of swapping out different components with my test unit to work out what had failed. After a few hours of exhaustive testing, it turns out that the Pi power brick had failed, and was not providing enough power to boot properly. The constant reboots and power failures also seem to have irreparably damaged the boot partition on the SD card, because that wouldn't boot in my test unit. Luckily though, I was still able to access the SD card with a freeware Windows program called 'DiskInternals Linux Reader', which could open and read the root partition, which is where all the custom scripts, magic mirror module configuration and timebonger code were stored. All relevant files were immediately copied off and backed up safely! I just had to reflash the SD card, order a new replacement power brick, and then reinstall everything.

I chose to use the latest Google AIY Projects image, meaning that I shouldn't have to worry about trying to reconfigure any audio settings because it should all work out of the box. All I would need to do would be configure the networking, retrieve the previously created AIY credentials from my Google account, reinstall the Magic Mirror software and modules, and copy back the timebonger script. I also decided to keep some notes on what I was doing, just in case I'd have to do it all again! Here they are:

1. Flash AIY Projects image to flash card with Etcher

2. Boot Pi with new image

3. Connect to home wifi using menu icon

4. Using 'Preferences'->'Raspberry Pi Configuration'
    System tab: Set hostname to 'magicmirror'
    Interfaces tab: Enable VNC server (then set admin password in VNC server config)
    Localisation: check settings for UK

5. Set fixed IP Address
    run:
        sudo leafpad /etc/network/interfaces
    comment out:
        iface wlan0 inet manual
    add:
        iface wlan0 inet static
                address 192.168.0.98
                subnet 255.255.255.0
                gateway 192.168.0.1

 6. Update everything
    sudo apt-get update && sudo apt-get -y upgrade && sudo reboot
    sudo rpi-update

7. Configure AIY Projects
    Follow instructions in AIY project installation to create the 'client_secrets.json' and 'credentials.json' files and put them in /home/pi/

8. Install 'xscreensaver' to stop the default screensaver kicking in
    run:
        sudo apt-get install xscreensaver
    configure by going to 'Preferences'->'Screensaver' and setting the blank screensaver

9. Install 'unclutter' to hide the mouse after a few moments of inactivity
    run:
        sudo apt-get install unclutter

10. Install my 'timebonger' script
    copy timebonger.py and cuckoo_clock1_x.wav to ~/timebonger
    create ~/timebonger/tb.sh with leafpad to contain:
        python /home/pi/timebonger/timebonger.py
    make executable:
        chmod +rwx tb.sh

11. Install MagicMirror core - https://magicmirror.builders/
    run:
        bash -c "$(curl -sL https://raw.githubusercontent.com/MichMich/MagicMirror/master/installers/raspberry.sh)"

12. Configure some default MagicMirror modules
    Add a personal Google Calendar using the ical link
    Add local weather and weather forecast using details from http://www.openweathermap.org
    Configure a couple of BBC News rss feeds

13. Install some additional MagicMirror modules.

random_quotes:
        cd ~/MagicMirror/modules
       
        git clone https://github.com/KirAsh4/random_quotes

        add to MagicMirror config.js:
       
            {
                module: 'random_quotes',
                position: 'middle_center',
                config: {
                    updateInterval: 300
                        // The config property is optional
                        // Without a config, a random quote is shown,
                        // selected from all of the categories available.
                }
            },

mmm-systemtemperature:
        cd ~/MagicMirror/modules

        git clone https://github.com/MichMich/mmm-systemtemperature.git

        add to MagicMirror config.js:
       
            {
                module: 'mmm-systemtemperature',
                position: 'bottom_right',    // This can be any of the regions.
                classes: 'small dimmed', // Add your own styling. Optional.
                config: {
                    // See 'Configuration options' for more information.
                }
            },

MMM-ping:
add ip addresses and hostnames of the devices I want to monitor inside my network to /etc/hosts so we can see names and not a list of ip addresses.

        leafpad /etc/hosts

        192.168.0.1    sky_router
        192.168.0.99    deepthought
        192.168.0.150    chromecast 
        192.168.0.151    firestick
        192.168.0.200    tplink_ext 
        192.168.0.209    hipsy00005
        192.168.0.210    retropie

        cd ~/MagicMirror/modules

        git clone https://github.com/fewieden/MMM-ping.git
       
        cd ~/MagicMirror/modules/MMM-ping
       
        npm install --productive
       
        sudo chmod u+s /bin/ping

        add to MagicMirror config.js:

            {
                module: 'MMM-ping',
                position: 'bottom_left',
                header: 'Ping',
                config: {
                    colored: true,
                    font: 'xsmall',
                    updateInterval: 1,
                    hosts: [
                        'sky_router',
                        'deepthought',
                        'chromecast',
                        'firestick',
                        'tplink_ext',
                        'retropie',
                        'hipsy00005' 
                            ]
                    }
            },

MMM-Trello:
useful online collaboration post it notes for teams (we use it at work)

        cd ~/MagicMirror/modules
       
        git clone https://github.com/Jopyth/MMM-Trello.git

        cd MMM-Trello

        npm install

        add to MagicMirror config.js:

            {
                module: 'MMM-Trello',
                position: 'bottom_right', // This can be any of the regions, best results in center regions.
                header: 'Trello',
                config: {
                    // See 'Configuration options' for more information.
                    showTitle: "true",
                    api_key: "<my api key>",
                    token: "<my token>",
                    list: "<my card id>"
                }
            },

14. Adjust MagicMirror CSS to reduce the large border and maximise screen area
    Edit custom.css:
        leafpad ~/MagicMirror/css/custom.css

    Insert this css into body to override those defaults in main.css

        body {
          margin: 10px;
          position: absolute;
          height: calc(100% - 20px);
          width: calc(100% - 20px);
        }

15. Set pm2 to autostart everything

I initially followed these instructions Auto Starting MagicMirror and then adapted them to start the other features.

start timebonger
    pm2 start /home/pi/timebonger/tb.sh --name "TimeBonger"

start Google Assistant - assistant_library_demo.py
    create gassist.sh (which is mostly a copy of ~/bin/AIY-voice-kit-shell.sh):
        leafpad ~/bin/gassist.sh

                #!/bin/bash --rcfile

                source /etc/bash.bashrc
                source ~/.bashrc

                cat /etc/aiyprojects.info

                cd ~/AIY-voice-kit-python
                source env/bin/activate

                /home/pi/AIY-voice-kit-python/src/assistant_library_demo.py

    make it executable
        chmod +rwx ~/bin/gassist.sh

    add it to pm2 startup:
        pm2 start /home/pi/bin/gassist.sh  

start MagicMirror
    pm2 start /home/pi/MagicMirror/installers/mm.sh  --name "MagicMirror"
      
save pm2 process list
    pm2 save
   
add pm2 startup to /etc/rc.local
    run:
        pm2 startup systemd
    which should add a startup command (like the one below) to /etc/rc.local
        # pm2 startup
        sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi

16. Reboot, and cross fingers!

So that's about it for my Magic Mirror!

It's especially useful in the mornings to have a clock and calendar available, and to quickly check the day's forecast for good or bad local weather. Having the random quotes is fun, but the rss news feed is less useful because it only shows one thing at a time. Having the Google VoiceHat installed is also cool, and when I find the time, I'll have a go at swapping out the simple Assistant with the more powerful Cloud Speech API to implement some of my own commands, and bring me a bit closer to the Star Trek Next Generation LCARS interface! Yes, I am a nerd.

All in all, the timebonger is the icing on the cake as far as I'm concerned, it amuses me all the time, and no-one's complained about it so far!

Sunday, October 29, 2017

The Shite Before Christmas

Twas the shite before Christmas, when outside was froze,
not an inch wasn't covered, not even my nose.
My wellies were sloshing, with warm runny gunk,
and fast pace of walking, had coated my junk.

The fart I expected, arrived way too fast,
and brought with it solids, in one liquid blast.
The stench was amazing, and the crisp morning air,
was putrid with wretching, as I dashed home with care.

My eyes were both streaming, as I got to my door,
my backside was stinging, I could take it no more!
So learn from this lesson, and please tell a friend,
don't reheat old curry from before last weekend!

(by Chris Thomas - 15 Dec 2016)

Thursday, October 26, 2017

Magic Mirror - build part 3


So, my magic mirror had been hanging in the living room above the fireplace, happily serving information for a few weeks, when May 2017's issue of the MagPi magazine (issue 57) was published, containing some rather spectacular electronic gubbins, the Google AIY Project kit (Artificial It Yourself)! A big speaker cone, wires, arcade style button, and a Voice HAT printed circuit board, enabling you to build your own version of Google's Home voice assistant, all free with the magazine. I had to have one!


Publication day came, and I tried at least 5 different stores, all of which did NOT have a copy or had already sold out. My wife eventually found and reserved a copy that was still available (thanks Sainsbury's Shrewsbury!) and we were able to pick it up the following Saturday from the customer service desk. Phew! We also found some additional copies on the shelves in the main store... I had them too!

I also ordered a brand new Pi3 and built it into the cardboard version. This was to become my test unit to see how to install and configure it, and to see if it really was actually worth the effort to cram it inside the magic mirror. The cardboard build seemed to go relatively smoothly, if a bit fiddly, however the instructions in the magazine didn't quite match with the necessities of reality (if I recall correctly, there was a file renaming step missing) but after some further troubleshooting, it eventually worked really well. Run the code, press the button, talk, and receive an answer. Super!


Next problem. If I was going to build this into the mirror, I didn't want to have to press the button to activate the assistant, nor worry about where to position or how to mount it. Luckily, there were additional instructions on the following pages to circumvent the button push, and move to a 'clap clap' trigger, which also worked. There also appeared to be further instructions to change the clap trigger to using the hot words "Hey Google", so I also tested that with similar success. A hands-off voice assistant it was to be then!


The major problem though, was with the additional height of the larger speaker cone, and the VoiceHAT board on top of the Raspberry Pi.


There are two little white plastic connectors (one for the microphone, and one for the pushbutton, which increased the height required beyond the 2cm of space available inside the mirror.


I considered a couple of solutions. Cutting more holes in the backing board for the components to poke out felt inelegant, would look messy and may affect how the mirror hangs on the wall. Equally, extending the GPIO ports with an IDE cable might work electronically, but I didn't even bother testing that because that configuration would still not have fit in the space available.

I really wasn't sure how to proceed, and found my mind wandering. My daughter was watching Dr Who, rather loudly in her bedroom next door. He wouldn't have this problem, because his Tardis is bigger on the inside... Therefore the only solution was to steal some Timelord technology and actually make the inside bigger...
...ah-ha!


Thanks to that flash of inspiration, it would be a relatively simple modification to tack on some additional 20mm strips of wood to make the 'walls' of the backing board higher.


Then, after carefully removing the brass clasps, do exactly the same with the outer frame. Wood glue the strips into place first, then drill pilot screw holes for extra security, and reattach brass hooks.



Hey presto, extra room!


New blocks of wood were cut and glued on top of the existing ones to increase the height of the screen mounts to again push the screen against the inside of the glass pane.


Some additional scraps were used to hold the new speaker cone in place. Unfortunately, it completely threw off all sense of symmetricality, but as it's all neatly hidden inside it only bothers me when I think about it... :)



The microphones are not permanently affixed, and are instead woven between other cables and left to dangle slightly, but not so much that they push up against the inside of the black card and glass. The mics are quite sensitive, so being inside a glass picture frame with a large, sound deadening bit of thick card in the way doesn't actually seem to be a problem at all.



Back on the wall, and configuring by remote was a bit more of a trial. There are instructions available for you to install the required software manually, and I followed those. The Google AIY stuff worked pretty much first time, but I had problems configuring regular audio output for my timebonger script. Again, I didn't leave myself any notes on what I did to eventually get this working, but it took many attempts and lots of Googling. I might have just chosen an alternate output device from the volume control's wiget on the menu... can't actually remember!

Finally, everything was working smoothly!

Coming up... Magic Mirror Build Part Four - Everything stopped working smoothly!

Monday, October 23, 2017

What I want is a proper hookey copy

(To be sung to the tune of "What I want is a proper cup o' coffee")

A fat man sat, in a popcorn covered seat, in a cinema in downtown Barking,
The audience, were noisy, and the kids,
We're running, up and down, and talking,
Ah curse ya, curse ya, curse ya, it's the worst theatre I've been caught in!

'Cause,
All I want is a proper hooky copy,
Made by a pirate movie copier,
I did download a lot,
'Cause I want a cheap ass copy, and don't want to pay a jot!
Pirate Bay's blocked!
Links sites are cocked!
They're no use to me!
If I can't have a proper hooky copy from a pirate movie copier, I'll buy the DVD!

In days of old when pirates were bold, they would sneak a camera in, to the cinema,
The focus was off, you'd hear other patrons cough, and they'd wander in front of the camera,
They were the worst movie copies! I felt anger!

Chorus

 
Then the DRM was cracked, it was a breeze, to, churn out copies by the dozen,
And the blank disk prices tumbled to a point, you would make free copies for your cousin!
I just hope there's no repercussion!


Chorus

(a three verse version of the lyrics by Chris Thomas - 31 August 2012)

Here's a version of the proper lyrics featuring the marvelous Bernard Cribbins... 


Thursday, October 19, 2017

Magic Mirror - build part 2

Quick modification this. I wanted my magic mirror to play a sound effect on the hour, but for that, it would need some speakers. I found the cheapest USB powered speakers I could find on eBay to experiment with, and if I broke them, it wouldn't be the end of the world.

  • Cheap USB speakers £2.69

They were surprisingly quite chunky, but were easy enough to open and unscrew...



However, I had to break the back end of each speaker box because the wires were threaded through a tiny hole, which wouldn't allow the plug ends through, and I also didn't want to have to desolder the wires. Two pairs of pliers made short work of breaking apart the moulded plastic, and removing the hot glue that held the volume knob PCB in place.


Next, after a few attempts to work out optimal positioning for the speakers, and to keep everything OCD symmetrical (very important) the mounting holes were marked and drilled and cut...



Superey dupery! Next, the plan required that I was to bolt the speaker cones inside the mirror, however... catastrophe! They were several millimetres too tall to fit inside the case! Daaahhh!

There really was no other option than to mount the speakers on the outside of the backing board, which meant that I had to desolder the wires anyway, taking care to remember which way round the wires went originally.


Some delicately balanced soldering later, the speakers were rewired, and even though they're mounted on the outside, they don't protrude too much, and don't affect how it hangs on the wall.



I first tried plugging the audio plug straight into the Pi's audio out, but it was way too hissy. Luckily, the screen driver board also has a standard audio out socket, and all that was required was to fiddle with some configuration files* to force audio out of the HDMI lead. Luckier still, it's no where near as hissy as the Pi direct audio connection.

(* This earlier incarnation of the magic mirror used an older vanilla version of Raspbian Jesse. I think I had to uncomment or add some specific HDMI options in /boot/config.txt to get the audio to work properly through the screen driver board, though I didn't leave myself any notes and can't remember exactly what I did)

So, now to the business of automating a python script to play audio on the hour.

I've only used python a little, but from what I have done, I was able to reuse some previously written functions to get things moving along. The hardest part, as with every software engineering project, is to come up with a suitable name. After thinking long and hard about it, it was named "timebonger.py"!
#!/usr/bin/env python

#import libraries
import sys
import time
import signal
import datetime
import subprocess

from time import sleep

#define global variables
blnStopped=False

#exit when received SIGTERM or SIGHUP
def stop(sig, frame):
    global blnStopped
    blnStopped=True
    print "caught signal ", sig, " exiting"

signal.signal(signal.SIGTERM, stop) #-15
signal.signal(signal.SIGHUP, stop) #-1

def runcmd(strCommand):
    print "runcmd() strCommand='" + strCommand + "'"
    try:
        output = subprocess.check_output(strCommand, shell=True)
        output = output.strip('\n')
        output = output.strip('\r')
        output = output.strip('\t')
        output = output.strip(' ')
        #print "output=" + output
    except Exception:
        return "error"

    return output

def mainloop():
    global blnStopped

    print "mainloop() started"

    dteNow=datetime.datetime.now()
    intHourNow=dteNow.hour
    intNextHour=intHourNow+1
    if(intNextHour>=24):
        intNextHour=0

    intMinuteNow=dteNow.minute
    intNextMinute=intMinuteNow+1
    if(intNextMinute>=60):
        intNextMinute=0

    try:
        while(not blnStopped):
            dteNow=datetime.datetime.now()
            intHourNow=dteNow.hour
            intMinuteNow=dteNow.minute
            #print "mainloop() dteNow=" + str(dteNow) + " intNextHour=" + str(intNextHour) + " intNextMinute=" + str(intNextMinute)

            if(intMinuteNow==intNextMinute or intHourNow==intNextHour):
                #print "mainloop() New minute!"

                #prepare time output
                strMinute=str(intMinuteNow)
                if(intMinuteNow==0):
                    strMinute="o'clock"

                strHour=str(intHourNow)
                if(intHourNow==0):
                    strHour="midnight"
                    strMinute=""
                if(intHourNow==12):
                    strHour="midday"
                    strMinute=""

                #do we run now?
                if(intHourNow>=7 and intHourNow<=23 and intMinuteNow==0):
                    print "mainloop() Bing Bong! The time is " + strHour + " " + strMinute
                    runcmd("aplay --device=sysdefault /home/pi/timebonger/cuckoo_clock1_x.wav")

                #calculate next minute
                if(intMinuteNow==intNextMinute):
                    intNextMinute=intNextMinute+1
                    if(intNextMinute>=60):
                        intNextMinute=0
                if(intHourNow==intNextHour):
                    intNextHour=intNextHour+1
                    if(intNextHour>=24):
                        intNextHour=0

            sleep(1)

        sys.exit(1)

    except KeyboardInterrupt:
        print "mainloop() Keyboard Interrupt!"
        sys.exit(1)

mainloop()


Not very elegant, I'm sure you'll agree, but it gets the job done, and makes me giggle EVERY SINGLE TIME. Can't remember where I got the sound effect from (it took me a while trying to find a suitably funny one, eventually I settled on a cartoon sounding cuckoo clock), but you could probably Google the filename to locate it. You may also notice that I've limited the script to only play the sound between the hours of 7am to 11pm, because I don't want it to 'bong' throughout the night and piss my family off!

To get the timebonger script to auto run on restart, I used the pm2 scheduler that I'd previously installed to get the Magic Mirror package to auto run. As the recommended method for the magic mirror suggests, I created a small shell script, /home/pi/timebonger/tb.sh which contained the single line:

python /home/pi/timebonger/timebonger.py

...which executes python and passes a fully qualified directory path to the timebonger script, then I made it executable with:

sudo chmod +rwx timebonger.py

...then added it to pm2 with:

pm2 start tb.sh
pm2 save

pm2 is itself already autostarted from /etc/rc.local (which I believe I setup by executing 'pm2 startup systemd' because Raspbian uses systemd) so that's job done! Everything auto runs on reboot without me having to touch anything.

So, the last part was to carefully measure out exactly where the wall hooks had to go so I could drill holes for wall plugs and mount it over the fireplace in the living room, leaving everything level and symmetrical. After much headscratching, measuring multiple times, umming, ahhhing, pencil marks, and aching arms, I managed to get it right first time!



Coming up in part three - the Google AIY (Artificial It Yourself) version!

Tuesday, October 17, 2017

New Clicky Keyboard

My wife loves me! She bought me an expensive new mechanical keyboard, with nice tactile clicky keys that are a dream to type with, and evoke a bygone age of solidly built, albeit beige, computing.
I didn't want to make a mistake by buying a keyboard I wouldn't actually like, so my research consisted of watching a load of YouTube videos with people testing all sorts of switches. Also, I was pleased to discover that you can buy switch testers from eBay, which allows you to actually hear and compare what the different mechanical switches feel like. I bought a nine-key one for about £7, and it was very useful to compare the type of switches that are available. I decided that the Cherry MX Blue switches were the best of the bunch for me.


The keyboard is Bluetooth capable and interestingly it's USB cable can be removed, so can be wired and not require batteries, or be completely wire free.


I wrote a brief product review for the website that I purchased it from...
Great keyboard! Solidly constructed, and very very nice to type on. I can almost feel my typing speed and accuracy getting better! Yes, they're a bit noisier than a standard cheap USB keyboard, but really not by much. Pairing is straightforward, though I could actually do with more than 4 pair slots! The only problem I've had is that the @ and " symbols (and a few others) are swapped when paired to an iPhone and iPad, and there doesn't seem to be a way to change either the keyboard or iDevice's configuration. However, I'm still very impressed, and I'm considering getting a second one for work!
Does anyone know how to fix the iPhone/iPad swapped key problem?

Monday, October 16, 2017

Magic Mirror - build part 1

February 2017's issue of The MagPi magazine (issue 54) caught my eye in a supermarket, because it featured a 'magic mirror' build project. I thought it was a great idea, and since I had a couple of Pis sitting around, and just had to build one!

First, can I get it to work? I figured that I'd use the Pi Zero, because it's a very small device, and would have the best chance of fitting it in a suitable picture frame. I managed to get an image running, but it did seem to be terribly slow, and I hoped to be able to run a few other services on it in the future, so I plumped for getting a version running on the larger and more powerful Pi3. Here is the image, with a few configured modules, running on my 23" main monitor...




Configuring the modules was straigtforward enough, as long as you read their instructions.

So far so good, on to the difficult part of getting all the right bits.

I did all the standard things... find a cheap laptop screen on eBay, then Google the model number to find a compatible HDMI screen driver, and agonised over picking the correct power supply for it. I wanted to be a complete cheapskate in this build, and don't want to blow anything up in the process. Double and triple checking was a necessity! A few hours later, the main electronic bits are ordered.
  • 15.6" screen £25
  • HDMI Audio Controller Board Driver £13
  • Screen Power Supply £7
  • Short HDMI cable £3
  • Pi 5v 3A power supply £3

Once all the bits turned up, time to see if it all works...


...success!

Now, all this needs to be crammed into a picture frame. I needed one that would give me enough room to fit the 'tallest' component, which turns out to be the Pi itself, at just over 2cm, from the top of the USB ports to the bottom of the pins sticking out on the bottom. Plus this mirror was intended to replace the big mirror in our living room above the fireplace. I found just the right frame from B&Q for about £15. It's the sort that you have to bend a bunch of little metal tabs down to keep the picture sandwiched between the backing board and the glass, but it was deep enough that it would just about fit the Pi inside the frame with the backing board remaining flush with the back of the frame. A pair of pliers was required to remove the metal tabs.

B&Q have had a lot of my money thanks to this project! Some 2cm wide strips of wood were purchased, and glued to the inside of the backing board to make an inner frame. Some smaller and shorter bits were used to hold the screen display in place...



The screen is 4mm deep, so some other pieces that were 16mm high were used to prop the screen up from underneath, this allowed me to hold the screen right up against the glass to minimise internal reflections when finally complete. Clever, huh? ;)



 A few other scraps were used to help keep the driver board and Pi in position.


Here the backing board and inner frame is fitted inside the main frame 'in reverse' to show how much room is left for the glass. It all fits!


Next, more nerve wracking stuff... fixing the mirrored surface to the glass!

  • One Way Privacy Window Film £10
  • Brass plated side hooks £3
  • Heavy Duty Picture and Mirror Hanging Kit £4
  • M3 nuts and bolts £3.25

I had to re-read the instructions a number of times, to wrap my head around which sides of film and glass I was supposed to cover in 'slip solution' (soapy water) and to get the steps in the right order. I decided to trim the film before affixing to the glass, rather than afterwards as recommended, because I worried that I'd cause more damage to the reflective film by trimming it after sticking it than before.



Handy hint: I used a small scrap of film to test how to separate the backing from the film with a bit of sellotape. Also, you can see the definite difference between silvery 'front' and see-through 'back' sides of the one way film...


It was tricky to squeegie the trapped water out, and keep all the edges aligned. Here's the final squeegied result...


I planned to use the original picture frame card to separate the inner wood frame from the one-way film, and trim out the bits where the screen is, however, after putting it all together, the white card was actually quite visible through the one way film. Not good enough! Here it can be seen, with some A4 white paper taped to it, that I used to mark out a template for the exact size and position of the screen hole...


One trip to a local stationers later, I've obtained a large A2 piece of black card, easily trimmed to size using the backing board as a template. The paper template above worked perfectly to let me work out exactly where the hole for the screen display needed to be.


The only downside is that it was half a centimetre too short!


Again, some scraps of card were carefully trimmed to provide the last few millimetres and taped in place.

Even the cut inner edge of the black card reflected enough light back through the one way film to be visible, so a trusty Sharpie was employed to deal with the problem...


Some admittedly not-very-neatly placed holes were drilled to allow the screen control buttons to poke through the backing board...



Lastly, the heavy duty picture hanging loops were affixed to the backing board (being drilled through to the inner wooden frame) and the brass hooks were added with some little self tapping wood screws to hold everything together. It also became a necessity to drill a couple of holes for some more M3 bolts to hold the Pi and driver board down, otherwise, they'd keep falling out when ever I tried to put the inner frame into the outer frame.




And with a super pleased and self satisfied grin, here it is on the floor, finally assembled and booted!



That was build Phase One. It sat on the floor in the office for a month before I found the time to move on to Phase Two...