Swapping SD cards between Raspberry Pi devices

Today I had the magical experience of finding a Raspberry Pi 4 that I’d forgotten I had. It was bought for playing retro games but I never used it much. So it’s been moved into the Chocolate Synthbox where it works really well. Transferring the program code was very easy. I just removed the sd card from the existing device and popped it in my “found” one.

It just worked. The only problem was that ssh (which provides the secure terminal connection between my desktop PC and the synthbox) got upset because some of the properties of the network connection hardware were different after the swap. If you ever have this problem the solution is quite simple. Open up a command shell and navigate to the folder .ssh folder.

cd .ssh

Now use notepad (or your editor of choice) to open up the known hosts file:

notepad known_hosts

Now you have to delete the line of the hosts file that refers to the machine named in the sd card that you have just moved. Next time you try to connect to that machine the ssh command will make a new entry in the file for the new machine.

I was moving the card between one Raspberry Pi 4 and another. I’m not sure what would happen if you moved it to a different model of Pi.

Pi Zero Version 2 Released

The Pi Zero has always been a favourite of mine. It’s a bit hard to get hold of sometimes, its frequently out of stock and they only let you buy one at a time. I don’t see that changing any time soon. They’ve just released version 2 which delivers a serious boost in performance, they say up to the level of a Raspberry Pi 3. It has a 64 bit architecture and four processor cores along with a general speedup of around 40%. I’ve been planning on making Pure Data output device to use with the PICO MIDI cheese box. It looks like this would be the perfect candidate.

Waveshare WM8960 Audio Hi-Fi Sound Card HAT

soundcard.jpg

I’ve been looking for a soundcard that will let me let me create a PureData powered musical instrument based on a Raspberry Pi device. This one looked like it might fit the bill. It even has two tiny microphones and comes with a pair of speakers.

The hardware isn’t directly supported by the Raspberry Pi operating system, so you have to do a mildly complicated install which involves downloading GitHub repository and then running an init script. My pro tip: rather than using Git clone from the command line (which will insist on you giving a GitHub username and password that you’d really rather not) use the browser to download the zip archive and then unzip the files onto your desktop.

I couldn’t get it to work (which is nothing new for me). I filed an online support request from the product page and was very surprised to get a prompt response offering help. Buoyed by this I had another go, starting from a brand new fresh install of Raspian. This worked a treat. Better yet, both the speakers and the microphone work perfectly with PureData (as long as I remember to start PureData in supervisor mode):

sudo puredata

If you are looking for an “all in one” audio solution for your Pi this is a very good bet. The speakers are OK for their size. The only thing it is missing is line audio in. You can only record from the onboard microphones. However, they do supply a full schematic, so if you are handy with a soldering iron and fine wire you might be able to make your own. And the support is very good. They even got back to me to ask how I was getting on after their first response.

Neat USB Hub for Raspberry Pi

usb hub.jpg

I really like the Raspberry Pi Zero. It's tiny and powerful. But connecting things to it can be a bit of a pain, particularly when you are setting up a system and really need a USB mouse and keyboard.

This little device makes things a lot easier. It is a hub which can plug straight into a Pi Zero and give you four ports of USB goodness. It even has an adapter so that you can use it as a “normal” hub as well. I found it in Amazon here.

Haunted USB sound adapter for Raspberry Pi

haunted usb connector.jpg

I needed a USB sound adapter for a Raspberry Pi device. I found this one on Amazon and also Pimoroni. it works fine. You get stereo audio output and mono microphone input. But the strange thing about it is the eerie glow that you get from the two sockets:

sound lights.jpg

I don’t think the device supports an optical audio connection (which is the only reason I can think of for there being lights in there). However, they do seem to flicker when you plug the device into a Pi.

Raspberry Pi Wide Angle Zoom Lens

lens.png

Pimoroni now stock a new lens for the Raspberry Pi HD camera. This one is a zoom wide angle lens. I’ve been impressed with the quality of the longer focus lens that I got a while back, so I thought I’d invest in the new one too. The price is very reasonable at 15 pounds.

The quality is very good. Focussing is fun. It is not a “pure zoom” in that if you change the zoom settings to move closer or further away from the subject you will have to refocus. And sometimes (at least on mine) I can’t find focus positions for some zoom settings. But the bokeh (the effect you get when things are out of focus) is rather nice in a blurry kind of a way

The artistic view..

The artistic view..

I’m using mine to give an overhead view of my work area for videos. If you want to do this you’ll need to set the camera up so that it gives you a full desktop view. This is the command that I use:

raspistill -t 0 -p 0,0,1920,1080

This makes the viewfinder image from the camera fill my video output, you can change width and height values to match the display values you are using.

The lens will focus very close, which makes it ideal for viewing components and circuits. If you have the Raspberry Pi HD camera unit it is well worth a look.

Visual Studio Code on Raspberry Pi is awesome

Visual Studio Code Raspberry Pi.png

I’ve been using Visual Studio Code remote development on my Raspberry Pi devices for a while, but what I’d really like to do is just run Visual Studio Code on the Raspberry Pi itself. And now I can.

sudo apt update 
sudo apt install code -y

All I had to do was open up a command prompt and type the two commands above. And then I had an extra option for programming and using all the lovely Visual Studio Code plugins.

This is wonderful, wonderful, news. I’ve installed the Platform IO plugin and I now have a completely self-contained system for development on the Pi. I’m using the Pi 400 device which has a fair amount of processing power. It’s not as fast as my desktop - but then it cost a tiny fraction of the price. And it does get there in the end. Such good news.

Makertober Day 8: Thermal Camera

thermal camera.png

I suppose there should be more to making things than just plugging together devices and running their example programs….. However, until that time: here’s an M5Stack device connected to a thermal camera. M5Stack sell a camera unit but I used one sold by Pimoroni to be used with their breakout garden. Both devices are based on the same camera unit, the MLX90640 that gives 32x24 pixels of heat readings. I got the M5Stack sample program from GitHub which I found here. It works very well. At the moment these cameras are pretty much impossible to get hold of - I’ve had this one lying around for a while.

You can also use the camera with a Raspberry Pi although they are rather hard to get hold of at the moment.

A look at the Raspberry Pi High Quality Camera

I’m beginning to wonder why we need “proper” cameras. My smartphone can now produce pictures that I can use for just about anything. And now you can get a high quality camera for your Pi. You can even swap lenses like the professionals. We are looking for something we can use to track robots, and so I thought I’d get one and see how well it works. I bought the “telephoto” lens because it seemed to be higher quality, but you if you can track down “C-mount” lenses (they are used in CCTV and video cameras) you can have what ever kind of lens you like. There is also a “wide-angle” lens which I’d quite like to have a play with now.

The camera connects to the Pi in just the same ways as previous cameras, but there must be an awful lot more data going down that little ribbon cable. I attached my camera to a Pi 4 and had a play. First thing I did was point the camera out of the window and take a picture. I got a 6.5 Mbyte Jpeg image. The top right hand corner of it looked like this:

This is not the entire picture. This is a tiny crop of the top right hand corner. There’s a lot of chromatic aberration going on (that’s causing the purple fringes) but detail is pretty good. Watch what happens when I stop it down a bit though.

Suddenly the image is much, much better. “Stopping down” means reducing the size of the hole that lets in the light. This means that the lens has to do less work and so I’d expect the image to be a lot better. The downside is that a smaller hole means less light, so the sensor takes longer to capture an image. This can lead to blur unless you use a tripod or increase the gain in the camera and get more noise.

I don’t particularly want to show you the view from my window, but what I will say is that the camera is doing a good job here. Once I’d taken some pictures out of the window, I took some of my desk.

This is the entire image of a corner of my desk. The minimum focus distance is not great for the tele-photo lens, at about 15 inches.

This is a 100% crop of the above picture, which should give you an idea of how much of the frame the branches above took. It should also give you and idea of the great quality of this lens and sensor combination.

This is a crop of the same image taken with the lens aperture wide open. This shows that you can get some lovely “out of focus” effects with this camera.

Good things to know:

There’s a really good book about how to use the camera. It’s a free download from MagPi Magazine here.

if you want to use the camera preview with VNC remote desktop you have to enable direct capture in the Troubleshooting Menu of VNC Server.

if you want to use VNC remote desktop to a Raspberry Pi with no HDMI monitor connected you have to use raspi-config to set a specific desktop resolution using the Resolution Option in the Advanced settings.

You can adjust the lens distance using a tiny spanner, but I’ve not done this. So it might be possible to get even sharper pictures.

The picture quality of the high quality camera is very good. But then again you’ll be paying around 100 pounds for the sensor-lens combination and so you’d expect something pretty impressive. I’m not sure how much the sensors in mid-range compact cameras cost, but I’d expect them to be around the same quality.

The “telephoto” lens that I got has quite a narrow angle of view, so if you want to do general stuff I’d suggest getting the wide angle lens instead.

Things will get properly interesting when these devices get into the hands of all the smart people that like to play with Raspberry Pi. There is considerable scope for some very interesting devices and if you want programmatic access to a very high quality image you’ve got that now.

Rob in Hackspace Magazine

I’m a writer again! Hackspace Magazine this month have printed my article about using a Real Time Clock to control the power of a microcontroller. They’ve done a really good job laying out the pictures and words that I sent through, and the whole magazine is a very interesting read - as usual.

You can read the article (and the whole magazine) here

Seam Client Fun and Games

I think this should be fast enough…

Now that we are getting into networked game nights I’ve decided that I have a need to play games on the big telly in the living room. Thoughts turned to a Raspberry Pi 4 running Steam Client. This was suspiciously easy to set up: there are a couple of splendid guides online that you can find here and here

Then I did some testing. One thing I didn’t appreciate is that fundamentally Steam Client is a souped up remote desktop. I was installing it using VNC on my PC and things got somewhat surreal when my PC desktop appeared on a machine where it shouldn’t be. I could see my VPC desktop on a remote desktop on the Pi. It was a bit like that bit in SpaceBalls when they watch the video of the movie inside the movie.

I wanted to take a screenshot but I was afraid this might cause a rift in the space-time continuum.

Anyhoo it seems to work for most games. Now I need to figure out how to do the video chat part of the evening.

The Raspberry Pi serial port is almost useful...

If you’ve ever played with a Raspberry Pi you’ll be familiar with the annoying way you have to configure the device before you can use it.

You might have no intention of using your shiny new Pi Zero W with a keyboard, screen and mouse but to get it set up you have to connect them all.

I thought I’d found the answer to my problems in the form of these serial connectors. You can connect them to the serial port pins on your Pi, plug the other end into your PC, fire up a terminal program (I use PuTTY) and then use the command line interface to set everything up.

A while back this would have been an excellent idea. Unfortunately modern versions of the Pi operating system are a bit more security conscious than the older ones, and disable the serial port command line by default.

So if you want to use this cable you have to use a mouse, keyboard and screen to turn it on and enable the serial console…… Oh well. It will still be useful for “on the fly” modifications.

No need for PuTTY

I seem to be spending more and more time talking to command line interfaces (CLI) these days. I think this is because I’m messing around with the Raspberry Pi that controls my LED panel cube and I’ve left off the desktop interface because it slows things down.

For years my weapon of choice for getting a command prompt on a remote system has been the PyTTY program. But no more. Later versions of Windows PowerShell for Windows 10 have an ssh command that just works. I found this lovely blog post from Scott Hanselman that shows how to create keys that let you connect without needing to enter a password. I’m especially impressed with the cunning way that he pushes the key file from the PC to the remote device.

Last night at the Hardware Meetup I discovered that you can use the ssh command to connect to a remote system without needing to know the ip address of the target machine. This meant that I was able to use the mobile hotspot in my phone to give a network connection to my Surface Pro and my Raspberry Pi and then use:

ssh pi@raspberrypi

.. to get a command line on the Pi. Very useful.

18th Hull Raspberry Pi Jam

I went to the 18th Hull Raspberry Pi Jam today. It was great. They had loads of Raspberry Pi machines set up and a lovely exercise wiring up neopixels. Everyone who did the lab was knocked out by how easy it is to create and control coloured light displays from software. I was showing off the work in progress for my LED Cube, which is presently two of my older panels connected to a Raspberry Pi and displaying demo images. I’m using this software to drive the panels and it works a treat.

I was telling anyone who would listen (there were a few) that the panels I really wanted to use were stuck in UK customs. I’m really hoping that soon they will be released, I can pay whatever hefty duty they figure out that I owe and I can get on with building the device.

Then I got to talking to Jon about his recent project which involved making an awesome piece of artwork. For his next one he’s going to be using a coin mechanism. These are the devices that you find on fruit machines and the like. Apparently you can buy them from Ali-Express for not much money. So I’ve bought one.

You configure the mechanism by setting it in “learn” mode and then inserting loads of a particular kind of coin. It can remember three different types of coin and the output is a simple sequence of pulses that should be easy to pick up with an Arduino or Raspberry Pi.

I’ve absolutely no idea what I will use it for. I was thinking of taking it to a hardware meetup and offering people the chance to see if it recognises their coins:

“Lets see if it can recognise your two pound coin. Oh, bad luck. Sorry, no I can’t get your money back again.”

If nothing else, this could be a nice little earner. The device has cost me considerably less than a computer game and I think I’ll have at least as much fun with it.

The next Raspberry Pi Jam (which I think will be the 19th), is on the 14th of March. This upsets me, because I would really like to go but I won’t be able to make it. Kudos to Jon and Matt who organised the event, provided the coloured pixels and then helped everyone to make them light up.

Raspberry Pi Jam in Hull on Saturday 1st Feb

The next Raspberry Pi Jam is in Hull on Saturday 1st Feb. It looks like all of the coding slots have been booked up, but if you want to go along as a spectator, or to show off something you’ve made it looks like there are spots available. You can sign up here. I’m going to take along some LED panels and talk about building a LED cube. I’ve just discovered that my LED panels are actually in UK customs at the moment, which is rather exciting.

Hull Raspberry Jam with Two Buttons

Well, that was fun. I really should have taken some pictures of the jam, it was great fun. There were loads of machines set up and creativity going on all over the place. I took my “Two Button Box” along and developed the rest of the software. Thanks to Ben, Jon and Matt for advice and help on getting my Python program to run each time the box is powered on (this harks back to my Unix days of old - editing the rc.local file to run programs on boot up).

Players need to press the red button when there are more red lights lit, and the blue button when there are more blue lights lit. I’d taken a bit of care to make the gameplay progressive. The game starts simple, with just red and blue lights, but then other colours appear and then they all start to move around.

It’s always nice to see people playing a game that you made. I’m not sure it pushes back any frontiers or brings anything particularly new to gaming, but it is always nice to see someone enjoying playing with something you’ve made; particularly if you enjoyed making it.

You can see it in action here. Thanks to Jon for the video.

Making plans for Hull Raspberry Jam

There’s a Raspberry Jam in Hull tomorrow. There is a kind of development theme where attendees are invited to create a game that only uses two buttons to control it. I love a good constraint. Ask me to make a game and I’ll fall apart. Ask me to make a game that only uses two buttons and I get interested. I mean, as you can see above, I’ve got two buttons….

My plan is to put the buttons, a Raspberry Pi and a power supply in a box. It’s one of the boxes that is supposed to have an Air Quality sensor in it (sorry Robin).

There’s a kind of reason in this madness, in that I’ve often wondered how good the Raspberry Pi is for creating what I’d call “pure” embedded devices. The Pi Zero W is very close in price to things like ESP32 based devices and brings a lot of advantages, including much more power and a “full fat” operating system. I get to write in Python - which I love - and I can actually run the IDE on the device itself if I want to.

You can see my first step above. The first thing I do is make sure that all the components will fit inside the box. As you can see, I think it will probably be OK. The only snag I’ve hit so far is that the holes for the buttons need to be a little bit larger than the ones in the box itself. However, a few minutes with a drill have sorted that one out.

The box that I’m using, like pretty much everything in my life, came from Amazon. You can get it much more cheaply if you are prepared to order it from China via Aliexpress. It’s supposed to be used as a junction box for connecting cables. It has eight big holes all round the sides into which you can run cables and connect them together, or put devices into. It has these rubber inserts for all the holes that you don’t want to run cables into and I got to wondering how good they would be at defusing light from a neopixel. Perhaps I could put some lights in the box and use these as the basis of a game of some kind. Time to build a circuit…..

What we have here is the first circuit. The two micro-switches will be fitted onto the buttons. The coloured pixels are to be stuck inside the box against each of the rubber fittings. The chain of lights is connected to a single GPIO (General Purpose Input/Output) pin on the Pi Zero. The buttons are connected to two other GPIO pins. There’s a splendid library available from AdaFruit that allows a Python program running in a Raspberry Pi to set the colour of each of the leds and also read the state of the inputs. So in no time at all I had the lights on under program control. Some tests have indicated that they will work quite well. I’ll put them all in the box tomorrow.

The next thing I need is an idea for a game. What I’ve come up with is a very simple idea. Each light around the box will light up with a particular colour. If there are more red lights lit than blue lights, the player must press the red button. If there are more blue lights lit than red lights, the player must press the blue button.

This should be easy to code and might make for some compelling short term game play, particularly if I add a bit of complication as the game is played.

I’m looking forward to taking the box to the Raspberry Jam tomorrow and finishing off the code.