Posts

Showing posts from 2020

Document breadboard builds by writing Python code

Image
In my last post I mentioned that I was using breadboarder - a Python program that eases the pain of documenting breadboard-based projects. You write a descriptiopn of your project using a Python-based DSL - a domain-specific language. It lets you explain what wire or component to add to the breadboard, and where to connect it. You write code like this: And it generates markdown and png files which render like this: It saves hours of layout, you can build complex projects out of simple ones, and everything is under source control. I need to improve the documentation but breadboarder is  on GitHub .

Fault-finding breadboarded circuits - a tale from the trenches

Image
blobstar Yesterday I destroyed an Atmel ATMega328 chip. (That's the chip at the heart of the Arduino.) The Atmel chips are very well designed, and it's really hard to damage them, but I've managed it twice in the last decade. Yesterday's episode was due to a mistake in wiring up an Arduino clone that I've been building on a breadboard. The clone is a descendant of Cefn Hoyle's excellent Shrimp design. I decided to build an alternative version which could be programmed using an FTDI cable and made permanent using an Adafruit perma-proto board. The correct layout (shown above) is easy to follow, but my ageing eyes led me to connect two of the power wires to the wrong pins. When I powered up the board using an FTDI cable the LED didn't blink and I knew something was wrong. But what? A simple approach to problem-solving When something stops working, you focus on what's changed. When

An Adafruit proto Bonnet for the Raspberry Pi, Jetson Nano and Grove I2C

Image
babelboard bonnet Adafruit's protoBoards lets you make a bread-boarded design permanent, and Seeed Studio's Grove system lets you wire up a prototype really quickly. In this half-day project I combined the two to create a simple, cheap, flexible prototyping system for the Raspberry Pi and Jetson Nano The Grove system is based on standard 4-way connectors which can be used to connect digital, analogue and I2C-based components. I've focused on I2C since most of the robots I build use I2C to interact with their environment. I mentioned the Jetson Nano - a hot topic at the moment, as NVIDIA have just announced a low-cost 2 GB version of the Nano which will be available at the end of the month. One of the clever features of the Nano is that it has a Pi-compatible header, so the bonnet will work on the Nano without modification. Fritzing the design I started by laying out an Adafruit bonnet design using Fritzing. The design is really simple. All it does is connect the pins of the

Mu, Edublocks and the Kitronik Inventor's kit

Image
A friend of mine recently asked me about Python programming on the micro:bit. I told him that I wrote a free workbook about that a while back. (If you'd like to get a copy you can sign up here ).   It's based around the excellent mu editor . Code with Mu Mu is a no-frills editor that you can use to develop and run programs on the micro:bit , Adafruit CircuitPython boards , the Raspberry Pi and other Python environments Mu has just enough features to be usable without being daunting. I love it. But some young students find text-based programming a bit scary. How can they get started? Code with Edublocks Some younger programmers are happier with block-based (visual) programming. For them, Edublocks is a great solution. Edublocks is block based, runs in your browser, and looks like the popular Scratch environment, but it's Python-oriented . Here's the Edublocks version of the code for the first experiment for Kitronik's excellent micro:bit Inventor's Kit .

Build your own Arduino clone - updating the Shrimp

Image
A Shrimp assembled A while ago I ran a series of workshops showing how to build your own Arduino clone, based on a low-cost e-book called Making the Shrimp.   The book needs an update and I'm looking for reviewers. They will get a free copy of the book and a free kit to build. If you're interested, sign up here .

Getting started with Pimoroni's Tiny 4WD Rover

Image
Kit contents with extras I just finished my book on the Pimoroni Explorer HAT, and I'm celebrating! I have treated myself to a Tiny 4WD Rover kit. It looks a lot of fun, and should be simple to assemble. The product page has a link to a great blog post from Emma Norling which has detailed build instructions. I'll be following that closely. I have already encountered one  minor gotcha . You need a few extras over and above the parts in the kit. Some of them are mentioned on the product page (battery, Pi zero W), but Emma found she needed spacers to mount the Explorer pHAT on the Pi zero W. I have suitable spacers in stock so I think I'll be OK. I also got a LIPO shim and a USB charger. Once I've completed the build I'll document it and provide a link on this blog. A nice bonus if you hurry!  Pimoroni are currently offering a free Pi Zero WH for customers spending more than £100 (excluding postage). The offer ends soon, but I managed to get my order in on time whic

Explorer HAT tricks is nearly finished!

Image
If you're thinking of experimenting with the Pimoroni Explorer HAT,  Explorer HAT tricks is a great place to start. It covers over a dozen simple projects, complete with Python code, and you won't need to do any soldering. If you're an experienced Pi user, you probably feel you don't need it, and that's fine. But if you're just starting out with Physical Computing, or new to the Explorer HAT, it's well worth a look, and there's a free sample available . The book is now over 80% complete. You get the book from Leanpub, which means that you get updates free whenever the book changes. The book was written for use with the Pimoroni Explorer HAT Pro but Pimoroni are currently offering a great deal on their Electronics pHAT kit . The kit costs just £19.92 including a Raspberry Pi zero. ! I've ordered one to experiment with. I know a couple of the projects in the book will need to change, but almost all of them will work unmodified. I'll write up what

Baby talk - Audio analysis on the Pi

Image
I'm working on two projects at present. I want to finish my book on the Pimoroni Explorer HAT, and I'm getting close. All of the code examples are available on GitHub , many with documentation, and the book itself is now 70% finished. It's still only $5, but the price goes up this weekend. I've also started another project - one that I expect to take months or years. It's based on some fascinating work by Jürgen Schmidhuber and his team on a technique they call UDRL - Upside-Down Reinforcement Learning. It looks as if they have cracked a problem that has been bugging me for decades. How can we get an ANN-based Parent Agent to train a Child Agent without hard-wiring in an unrealistic amount of innate behaviour? If you're interested in their solution (and have a basic background in reinforcement learning) there are two papers on arxiv that explain it: Training Agents using Upside-Down Reinforcement Learning and  Reinforcement Learning Upside Down: Don't Pred

Explorer HAT book - two more draft chapters

    I've drafted a couple more chapters for Explorer HAT tricks . They need editing but I will publish a new version of the book with the new chapters next week. If you've bought it you will get the updates free of course. The video shows one of the projects - a simulation of a Pelican Crossing. You can find out more about the book here .

Explorer HAT update on its way!

Image
HAT and Keypad I am about to update my book about Pimoroni's excellent Explorer Hat. I've finished the code and the Frizing diagrams for all the planned projects. The next step is to write the remaining chapters that describe them, and I hope to publish a couple of those later this week. The image on the right shows one of the new projects: a 12-key numeric keypad controlled by the Explorer HAT. The price for the book is still just $5 (+ VAT for EU buyers) but I'll have to raise the price once I've added more content.  You can buy the book through LeanPub, so you get a 45-day no-hassle money-back guarantee and you'll get future updates to the book at no additional cost! If you want to make the most of the Pimoroni HAT, don't wait - get the book while the price is still just $5!

Quantum Computing with qiskit on the Raspberry Pi

Image
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

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

The micro:bit is talking to the VL53L0X ToF sensors!

Image
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 imp

Read distances from up to 8 VL53L0X sensors via SPI

Image
I'v now got my two-Arduino version of a multiiple ToF sensor LiDAR working. I have only tested it with two sensors; I'll add one more later, and report, but the code should work with more. I'm a little hesitant about that claim. The Slave Arduino code has little spare memory but I've tried to  reduce requirements to a minimum. I have more VL53L0X sensors on order, and I am hoping I can handle up to eight. That would allow a robot to get a good sense of the closest obstacles. The Slave code uses an SPI interrupt routine modified from Nick Gammon's excellent example . The code that configures and then reads from the ToF sensors is a complete rewrite of Adafruit's example code for dual VL53L0X sensors. I'm no expert at C programming, so if you can see improvements (or bugs), let me know! The code is on GitHub , along with some minimal documentation. The next step will be go get the Arduino slave working with a micro:bit master; then I'll n

SPI access to multiple ToF sensors is working

Image
I've been ploughing through the steps towards my goal of connecting multiple distance sensors to Anastasia's micro:bit. I now have a pair of Arduinos connected via SPI, with the slave reporting distances from two VL53L0X sensors. The wiring is a mess and the code needs cleaning up. But it's working, and replacing the Arduino master by a micro:bit should be pretty straightforward. I'll report on progress. The code is on GitHub .

7 steps to add multiple ToF LiDAR sensors to a micro:bit

Image
I'm happy with the solution I came up with to attach multiple Time-of-Flight (ToF) sensors to a Raspberry Pi or CircuitPython board. Now I want to add one or more ToF sensors to Anastasia , my Python-powered micro:bit robot. Anastasia needs at least one distance sensor to stop her running into things. Since she can travel backwards as fast as she goes forwards, she really needs two sensors: one looking forwards, and one looking behind. I've been looking for a simple solution but I have hit a snag. I've found several Python drivers for the VL53L0X chip I'm using, but none will run on the micro:bit. Some are Python wrappers for C code; others are just too big to fit on the micro:bit. I finally came up with an approach which looks as if it may work. The goal is to use a board with an Arduino-ish clone, programmed in C, driving the sensors and returning results via SPI. Seven steps to ToF success I've broken the project plan into seven steps whic

Muliplexing I2C with the Adafruit TCA9548A multiplexer

Image
I want to attach multiple VL53L0X Time-of-flight sensors to a single I2C bus. It looks as if that should be easy, but it's not. One solution involves disabling the sensors and then enabling them one at  a time to change their address. It's workable, but fiddly. If you only have two sensors you could use different I2C buses, but I eventually want to run 8 sensors, so that won't work. The TCA9548A I2C multiplexer There is another approach that is easy to implement and works out of the box. The TCA9548A is an I2C device that acts a little like a telephone exchange. You can use it to route I2C transactions to one of eight separate I2C busses. That allows you to have eight devices with the same I2C address, one on each bus. I did a first experiment using an Adafruit CircuitPython m4 feather. That worked well, and I've just confirmed that it works just as well with a Raspberry Pi. Since I'm using Adafruit's CircuitPython libraries, the same code run

Build details for Anastasia

Image
I've uploaded pdf files with full build instructions for Anastasia the micro:bit robot and the power strip I made for her. These are free/immediate downloads, no email required. Links: Build Anastasia the micro:bit robot Power Strip Build Guide

Bill of Materials for Anastasia - build instructions coming soon.

Image
I've added a Bill of Materials for Anatasia the home brew micro:bit robot in her GitHub project . They are in the project README. I'll add building instructions here and on GitHub over the week-end. Meanwhile, here is a video showing her in action:

Driving Anastasia's Kitronik motor controller via radio

Image
Anastasia with the controller This is the fourth in a series of articles about Anastasia - a home-brew robot based on the micro:bit. In my previous post I shared the micropython code that runs on Anastasia's remote micro:bit controller. The controller can send one of five commands to Anastasia : stop applies a brake to the motors. left spins the robot anti-clockwise. right spins the robot clockwise. forward ( you guessed it1) drives the robot forwards. backward also does what you'd expect. In this post I'll step through the code than implements these commands on Anastasia. The code looks for incoming radio messages. It translates those messages into methods on a Driver class. These methods then send control signals to the  Kitronik motor controller. Here's Anastasia's code The code starts with the necessary imports, and then begins the definition of the Driver class. from microbit import * import radio class Driver: "&quo

Controlling Anastasia from a second micro:bit

Image
This is the third in a series of four articles about Anatasia, a home-brew micro:bit based robot. Here's the full list of articles: 1. The original article introducing the robot. 2. A short update when I released the code on GitHub. 3. This detailed walk-though of the controller code. 4. A detailed walk-through of the code that runs on the robot .  The code for Anatasia and her controller is finished. It's simple and it's all working well. You control Anastasia via a separate hand-held micro:bit, which communicates using the micro:bit's built-in radio. You tilt the controller and Anastasia responds by advancing, retreating or spinning to the left or right. Anastasia stops when you hold the controller level. Here's the controller code: Controller Code   The controller code starts with a bit of set-up from microbit import * import radio radio.on() # The critical value for tilt detection. # A lower value makes the controller more sensitive.

Anastasia is a simple home-brew robot - now on GitHub

Image
Anastasia V1 Anastasia (my latest home-brew robot) is now on GitHub . The code is described in a series of articles on this blog. I've listed them at the end of this post. I've made rapid progress with Anastasia and will do more work on her today. Anastasia is currently driven by a pair of micro:bits. The motor is managed by an on-board micro:bit connected to a Kitronik motor controller and I control Anastasia over radio using a second micro:bit. Anastasia is working, but needs some minor enhancements to the code and electronics. I may also need to replace the motors which run a bit unevenly. Once I've done the upgrades I'll post a video of Anastasia in operation. Soon I'll replace the on-board micro:bit by an Adafruit clue which will be controlled via Bluetooth. Eventually I'll add an on-board camera. Articles in this series: 1. The original article introducing the robot. 2. This short update. 3. A detailed walk-though of the controller c

How to program a simple homebrew micro:bit-based Robot

Image
This afternoon I assembled a simple micro:bit mobile robot. It uses the Kitronik motor driver board and some Adafruit motors. I like the Kitronik board. It's easy to use, well documented, and the build quality is good. I'll be making some minor mods over the next couple of days. It needs a ToF Lidar sensor to make sure it doesn't bump into things and I plan to power it from a phone charger battery with an additional on-off switch. I'll use a second micro:bit to control it via radio. Update! There are now four articles in this series, and the robot has been named. It's called Anastasia. Here are the articles: 1. This introduction. 2. An short update when I released the initial code on GitHub . 3. A detailed walk-though of the controller code. 4. A detailed walk-through of the code that runs on the robot . Simple control code The test code I wrote to check the wiring was very simple. from microbit import * left = (pin16, pin0) right = (pi

An I2C keypad for the micro:bit - part 2

Image
A working prototype I've now got a home-brew Arduino clone reading the keyboard and sending key-presses to a micro:bit using I2C. Preparing the Arduino clone was trickier than usual. As I mentioned in yesterday's post , the Arduino needs to run at 3.3 volts. That's the working voltage (V cc ) for the micro:bit, the Pi and the Jetson Nano. Connecting I2C lines from a 5v device would damage them, so 3.3 v operation is essential. I have a good stock of ATmega328P chips left over from the days when I was running Shrimping workshops. The ATmega328P  works well at 3.3 volts, so long as the clock frequency is no more than 8 MHz . Most Arduinos run at 5v with a clock speed of 16 MHz, so there's work to do.   8 MHz clock issues If I2C is to work reliably at 8 MHz the Arduino needs to be configured for an 8 MHz clock, and it needs a bootloader that works at that clock rate. My first step was to wire up a working clone on a breadboard with an 8 MHz crystal and i

An I2C keypad for the micro:bit - part 1

Image
I love the micro:bit. It's affordable, it runs micropython, and it's instantly engaging. These days it's supported by a huge range of add-ons that extend its capabilities, but there's always room for more. A lot of the add-ons that I buy or build use are based on the I2C protocol. I2C is a  widely-supported way of connecting and controlling add-on boards to single board computers like the micro:bit, Arduino and Raspberry Pi. There's lots of sample I2C code for the Arduino and the Pi, but not so much for the micro:bit. A few days ago I posted about an experiment connecting a micro:bit to a numeric keypad using I2C . That worked well, and the code is on GitHub . As you can see, the program needed quite a bit of code, and space on the micro:bit is at a premium. Since I wanted to add an LCD display I started looking for a more compact approach. Help from Arduino I decided to try out a design that used a home-brew Arduino clone to scan the keypad and make key

Adding a DS1307 Real Time Clock to Raspberry Pi

Image
Grove RTC The DS1307 RTC (Real Time Clock) is widely available, but adding one to a Raspberry Pi turned out to be a bit of a Yak shave. I'm gradually adding code and wiring instructions to my babelboard hardware and software projects, and I thought it was time to cover an RTC. I had a Grove RTC board from years ago and decided I'd document connecting that to a Raspberry Pi. The need for Battery Power First Yak Shave moment: RTCs normally use a coin battery to maintain power so they can keep time when their host is off, and the battery in my Grove board was way past its use-by date. This happened on Sunday evening, and the local supermarkets were shut, but the local convenience store was open. No CR1220, though, so I had to wait until the next day to get started. While I was waiting I read the data sheet for the DS1307 chip and realised I had another problem. Don't connect this chip directly to your Pi! Seeed Studios describe the DS1307 breakout as P

I2C and SPI on the micro:bit; additions to the babelboard range

Image
micro:bit Keypad using I2C+ MC23008 For some reason there's not a lot on the web about using I2C and SPI with the BBC micro:bit. The I2C and SPI protocols allow single board computers like the micro:bit, the Raspberry Pi and Jetson Nano to drive hundreds of different types of useful peripheral chips. There are lots of widely available drivers for the Raspberry Pi, the Arduino and  Adafruit boards. I've seen fewer for the micro:bit, and I have started writing some more as part of my babelboard project . I am also building a babelboard for the micro:bit. The babelboard project Babelboards allow you to connect a range of I2C and SPI devices to several popular single board computers. The image on the right shows an mcp23S08 reading a hex keypad driven by a micro:bit using SPI. The micro:bit babelboard allows you to connect Grove I2C devices and the Quick2Wire port expander and analog boards. You can get adapters that connect Grove to Qwiik , so you can also con

The bistable flip-flop 60 years on

Image
flip-flop from 'Electronic Computers'  - T.E. Ivall About 60 years ago I started to teach myself about how digital computers worked. I'd already written some simple programs and I wanted to build a computer of my own. In 1960 that was a bit ambitious, but I did manage to build a few simple digital circuits including a flop-flop . (A few years later I hand-wired a core store, but that's another story). The flip-flop lies at the heart of digital electronics.The thing that makes digital computers so powerful is memory. Memory  can store the data that programs work on, and it can also store the the programs themselves. Early computers used a variety of techniques for storage but almost all of them used flip-flops to some extent. The bistable flip-flop is a very simple circuit. It can store a single binary digit (bit) of information.  The flip-flop was not new in 1960. The original patent was granted to the inventors (Eccles and Jordan) in 1918. That was long befo