Pages

Friday, 5 June 2020

Quantum Computing with qiskit on the Raspberry Pi

IBM Quantum Computer
Quantum Computing is fascinating, and you can now explore it with a Raspberry Pi!

IBM have created Qiskit, a very accessible Python-based framework for Quantum Computing. You can install qiskit on Linux, OS X and Windows platforms.

You can even install it directly on the Raspberry Pi, though the installation is a little tricky and takes quite a while.

(Image copyright IBM)

Qiskit supports the IBM Quantum Experience - a collection of tools and tutorials that enable you to learn about Quantum Computing.

You can explore qiskit via the web or install a local copy. You can even submit your own Quantum Circuits to run on IBM's publicly available Quantum Computers.

 If you're looking for interesting STEM topics to explore, Quantum Computing is worth a look.
If you can use a jupyter notebook to run simple Python code you can explore the qiskit examples.

If you have a basic background in linear algebra and complex numbers you can understand the mathematics that underpins Quantum Computing.

qiskit on the Raspberry Pi


I mentioned earlier that qiskit runs on a Raspberry Pi - a good choice if you cannot easily install qiskit on a workstation or laptop computer.

It's not hard, though it takes an hour or more on an 8GB Pi 4. There are a few pitfalls, but I've listed the steps I took on GitHub.

An alternative solution is to run qiskit on the Pi inside a docker container. I've built a publicly available image on DockerHub.

It's big (about 2 GB) but you can pull (download) it in a few minutes over a fast broadband connection. It runs well on a Pi 3B+ or a Pi 4B of any size.

I've also included the Dockerfile used to build the  Docker image in the same repository, but it's not for the faint-hearted. It takes about 4 hours to build on an 8 GB Pi 4!


Sunday, 26 April 2020

Virtual Pi Wars 2020 was outstanding!

This year Pi Wars went virtual, and it was a huge success.

Mike Horne did a superb job as compère, and the Robot videos were wonderful: always informative, often amusing and of very high quality.

Over the next few days we'll have a chance to vote. It's going to be a very difficult choice!

The Teams presented creative and individual solutions, but some common themes emerged. Lots of teams made use of simulations. Some used custom software based around standard libraries; others were based on specialised open source frameworks like VTK.

Most Robots were programmed in Python, but several used Pi controllers with peripheral Arduino nanos or teensies programmed in C.

Some teams used ToF (Time of flight) sensors for distance sensing and SLAM (Simultaneous location mapping and mapping). A growing number of entrants used OpenCV or plan to use it next year.

Many Teams share their software and designs. I'm looking forward to exploring several of the projects on GitHub as I look through the videos over the next day or so.

Over 300 people watched the virtual presentation. They  savoured three hours of excellent virus-free entertainment. Thanks to everyone involved, and special thanks to Mike Horne and Tim Richardson for turning that bright idea all those years ago into a wonderful, enduring institution.

Tuesday, 7 April 2020

The micro:bit is talking to theVL53L0X ToF sensors!

This chip is no more :(
This morning I got my Arduino sensor driver talking to a micro:bit using SPI.

The Arduino Uno runs at 5 volts, and the micro:bit works at 3v3, so I used a level shifter to connect the two.

My first attempt failed disastrously.

The level shifter I used was based on the TI TXB0108.
I managed to connect the 5v power and inputs to the 3v3 side, and I fear the magic smoke has left the chip.

It's a shame, as the board was my first attempt at soldering SMD devices. It's been sitting unused in my bits box for a few years, though, so it's not the end of the world.

Fortunately I had an Adafruit level shifter breakout based on the same IC. It's well laid out with very clear pin markings and I managed to connect it correctly.

The replacement worked perfectly and the micro:bit MicroPython code was very straightforward. I've listed it below, and it's with the other code on GitHub.

from microbit import *
import struct
from time import sleep

SENSORS = 2

def spi_read(sensor):
    pin16.write_digital(0)  # Chip select
    ibuffer = struct.pack('<B', sensor)
    spi.write(ibuffer)
    result = spi.read(1)
    pin16.write_digital(1)  # Chip select off
    return result

spi.init(baudrate=100000)
while True:
    for i in [0, 1]:
        print(i, ord(spi_read(i)))
        sleep(0.1)


The technology is working. The next step is to build a compact version for Anastasia. I'll report on progress.