Infra-red Remote Control

Further exploring of the libraries has brought these commands to my attention. I wasn’t sure whether it was possible to get one to communicate with another, which might be useful in the future for remote controlling robots.

To communicate between two systems via Infra-red, an infra-red diode is needed for transmission along with an infra-red receiver/demodulator.

Infra-red transmission normally takes place as a series of bursts of pulses. These pulses are sent as on/off outputs from the microcontroller at 38kHz. The bursts are then grouped to encode the signal in a similar way to morse code. It is possible to see these pulses on some mobile-phone cameras as they are often slightly sensitive to infra-red emissions. There are a number of different protocols for sending messages. The PICAXE system uses the Sony protocol, but the Raspberry Pi Pico uses the NEC protocol.

Receiving is a much more complicated affair. Many years ago I remember building a system with an infra-red photo-diode along with a reasonably involved circuit which needed a variety of capacitors, an integrated circuit and some resistors. Needless to say, at the time it was quite involved and hard to test. These days, it’s possible to get the receiver and demodulator all in one 3-pin package or, as in this case, ready mounted on a small circuit board.

In my testing, I connected the infra-red diode board to output 15 on one of my Raspberry Pi Pico boards. I wasn’t sure how to tell Microblocks which pin I had connected to, but by showing the block definition (right click) for the infra-red transmit function I was able to see that there was a pin connection variable. I noticed that the transmitter board had a Vcc connection, but it doesn’t require a connection to a power supply since it takes the output power from the pin being used. There is also a small blue LED which helps to monitor the transmission.

For the receiver, I used a ready-made module again. It has three connections which are all used. The module worked fine at the 3.3v levels offered by the Raspberry Pi Pico. The data-out pin was connected to input pin 20 on my circuit board.

Raspberry Pi Pico circuit boards with an infra-red transmitter and receiver.

The programming is straightforward once the correct inputs and outputs are set up. The receiver pin is easily set up as there is a function for that, but the transmitter pin requires the IR_transmit_device function definition to be shown (right click the function and show its definition) and then duplicate the variable setting.

I haven’t had a chance to check the range but these things are pretty efficient. In the past I have experimented with creating a lasertag system (hand-coded in assembly language!) but using a microcontroller such as these would really simplify many parts of the process. If I was concerned about range, I could use a MOSFET as a transducer driver and either an array of Infra-red diodes or a much higher-power single infra-red diode.

The program shown below just sends an alternate code 1 and code 10, while the receiver interprets this and lights one of two LEDs on outputs 2 and 3.

There’s a little video on Twitter at :


Cheerlights on the Raspberry Pi Pico

It has been a long time since I connected with the Cheerlights system, and as we’re heading towards the winter season and Christmas, it seemed appropriate to see what could be done with a WiFi connected Raspberry Pi Pico. Cheerlights is connected to Twitter, and anyone from around the world can send a Twitter message which contains a colour name. Any device can then access this and use it in a number of ways. The current colour is shown on this webpage.

Once again, I’m working with the MicroBlocks programming language and I had noticed that they have a library for connecting to WiFi as well as functions for setting up an HTTP client.

Once the WiFi connection is made, it regularly reads the colour from this link into a variable and then uses that to light up pixels n a NeoPixel grid. To make it more interesting, I flash a random pixel at 100% brightness and then revert to 20% brightness. The current colour is read every 10 seconds or so. I’ve put a video on Twitter so that you can see its sparkly goodness.

The latest version of my program is shown below, and there is a download link at the end of this article.

The Cheerlights program can be downloaded from this link (right click and save to your own computer):

Pseudo 7-Segment Display on a 128×64 pixel OLED

Downloads appear at the end of this post.

Graphic image of a display device showing large and small numbers.
128×64 Pixel OLED showing the time on a simulated 7-segment display.

I’ve mentioned in a previous post that I’ve started to use MicroBlocks ( to write programs for the Raspberry Pi Pico. It comes with an OLED extension library which allows text and numbers to be written to the screen. The commands control the simple 128×64 I2C displays, which can be easily connected to Pins 4 and 5 on the Raspberry Pi Pico.

One thing that I noticed, however, is that the size of the standard text is really a bit small for my eyes now, so I wanted to see if I could write a small set of functions that would change the size of digits on screen, by simulating a 7-segment display.

I remembered that a 7-segment display starts with a simple diagram that names each segment with a letter. In the standard layout, segment “a” is at the top, and then the segments clockwise from here are “b” through to “f”, with the central segment being “g”. In order to store this using MicroBlocks, I needed a list.

It took me a little while to get my head around this. Digit 0 needs all of the segments except the central one. Digit 1 needs segments “b” and “c”. In MicroBlocks however, the lists start at item 1, which meant that I had to remember to take account of this later.

The next step was to create a function that looked that the digit required, decide which segments are turned-on or turned-off and draw these as rectangles on the screen using the OLED library commands. If there is an “a” in the SegmentList, then it is drawn on the OLED pixels, and if not, it is erased. I defer updating the OLED pixels until all of the segments have been drawn so that there is no flicker.

Part of the routine for drawing the segments

Once I had the main functions written, it’s a relatively simple task to use them to show large digits on the screen. I had to use modulo and division mathematical functions to separate out the units, tens and hundreds, and then shift the XPosition of each segment before display.


There are two MicroBlocks programs ready to download:

Counting to 999 on an OLED display (7SegmentDisplay.ubp)

Real-time clock and large simulated display (LargeDisplayClock.ubp)

Pin Connections on the interface board

I wanted to create a board that offered as many different connections as possible. I like to create small robot models and it was really important to offer connections for H-bridges, stepper motors and a whole collection of servos. Sensors are either analogue or digital, and most of them require some sort of power connection.

As a result of all of these decisions, I’ve decided to make the connections based on the pattern set by servo connectors. On these, the centre connection is the positive (+V or Vcc) power supply, one connection is Ground (Gnd) and the final connection is the control signal. On this board, all of the connections face towards the Raspberry Pi Pico.

The pin allocations are based on those given for Microblocks running on the Raspberry Pi Pico at:

Connection diagram for the Raspberry Pi Pico Interface Board
External Pins (Some pins can suit a variety of functions).Used For:
Pins 0-22Digital I/O only (2,3,6,7,8,9 in use for on-board functions)
Pins 0,1Serial UART : Pin 0 – TX Pin 1 – RX
Pins 4,5I2C : Pin 4 – SDA Pin 5 – SCL
Pin 10,11Suitable for an ultrasonic sensor or general I/O use.
Pins 12-19are suitable for servos and have 5v Power Available.
Pins 14-17are also available on the back for connection to a dual H-Bridge for DC motors or Bipolar/Unipolar Stepper Motor driver. A 5V Power Supply is available.
Pins 16-19SPI Pin 16 – SPI MISO Pin 17 – SPI SS Pin 18 – SPI Clock Pin 19 – SPI MOSI
Pins 20-22Digital I/O with 3.3v Power Supply
Pins 26-28Analog or digital inputs with 3.3v Power Supply
Internal Pins
Pin 23(digital output) turn on for better voltage regulation (uses a bit more power)
Pin 24(digital input) detects USB connected
Pin 25(digital output) user LED
Pin 29(analog input) temperature sensor
On-board components
Pin 2 and Pin 3On-board LEDs
Pin 6,7,8,9Tactile Switches
Pin 4,5I2C OLED Display connected to Pin 4 – SDA Pin 5 – SCL and running from 3.3v
Pin Connection List

Lego and Raspberry Pi working together

In a small way, I consider the Raspberry Pi almost like a Lego brick. On its own, it’s an interesting device, but it becomes more useful when combined with other components. What would be more natural then, than combining it with other Lego devices along with a few of my own devising.

In previous posts, I’ve shown how servos can be used to create some pretty whacky Lego devices, but equally I feel that individual bricks are open to hacking. Note… this is pretty gruesome stuff – drilling, cutting and filing Lego bricks. Even something rather similar to “The Kragle” ends up being used!

Rather than steal my son’s Lego, I’ve been using Bricklink as a place to buy specific parts. I’ll try to list their code numbers here so that they’re easy to find on the Bricklink website. Bricklink serves as a market place for people to sell their bricks.

In a follow-up post, I’ll show the current version of my Lego interface.

Lego LEDs

Lego LED

Lego LED in 2×2 brick

I’ve debated at length in my own head how to wire these. Essentially all the device needs is a resistor and LED to be mounted into some kind of transparent brick, or for the LED to be poking out of the top.

A standard 5mm LED can be fitted inside a 2×2 brick if it’s allowed to shine through the top. This does mean that other bricks can’t be stacked with it, but it is a neat solution. These 2×2 bricks are also available in clear (I bought Trans-clear, Trans-Dark blue, Trans-Green, Trans-Red).

To make this, you will need:

  • 2×2 Brick (Part No:3003)
  • 2×2 Plate (Part No: )
  • 0.1″ Female connector cables
  • LED
  • 100 Ω resistor (1/8 Watt is easier to fit in)

Lego switches

Lego tactile switch

Lego tactile switch

These are easily made with a 6mm tactile switch with a long actuator. A blob of hot glue can be used to keep the whole switch central while the rest of the brick and plate is assembled around it.

The switch is connected to a short cable with 0.1″ Female connectors on the end.

To make this, you will need:

  • 2×2 Brick (Part No:3003)
  • 2×2 Plate (Part No: )
  • 0.1″ Female connector cables
  • 6mm tactile switch

4-way tactile switch

4-way tactile switch on a PCB in a Lego frame

I’ve also had success with using 4 tactile switches on a PCB. The spacing between studs is 8mm, therefore it’s a fairly simple job to create a PCB which matches. I’ve linked one side of each switch to a common line to reduce the amount of cables required.


Lego large servo

A Large servo in a Lego framework

Connecting servos into a Lego system remains the biggest challenge. I tried a number of ideas before I settled with two possible solutions.

The micro servos seem to work best glued to a tile. It needs to be something that’s compatible with the plastic of both the servo and plate. Hot glue seems to work well here, although I have had success with some solvent-based cements. Polystyrene cement worked well for a bit, but surprisingly I did have on piece fall apart.

Larger servos require a different approach. I build a framework out of bricks and plates and that seemed to work well, but it does mean that right-angle parts are needed to mount it if the axis of rotation needs to be vertical. The egg-drawing robot used a large servo resting on a tile, with some small axles to centre the spindle within the Lego grid system.

To make a framework that supports a servo on its side, I used:

  • 2 bricks – 1 x 6 (Part no: 3009)
  • 1 plate – 1 x 6 (Part no: 3666)
  • 2 plates – 4 x 6 (Part no: 3032)
  • Optional – Bracket – 2 x 2 with 2 holes (Part no: )

All of the pieces need to be stuck together with solvent and then the servo can be linked into this with hot glue. It’s fairly neat, robust and fits into the Lego system well.

The servo actuator needs a little bit of treatment to make it useful. Small servos can use a Technic axle and pin connector (Part no: 3651) and larger servos will need modifying with a pulley (Part no: 4185) along with some small screws. I used PCB pillars to get the spacing just right.

Lego framework with brackets

Large servo in Lego frame

22mm Pulley for actuator

Servo actuator using a pulley

Lego framework

Largeservo and the Lego framework

Small servo

Small servo on Lego tile with actuator

Mini amplifier – 5v powered stereo modules

PAM8403 stereo amplifier board

PAM8403 stereo amplifier board

I had been looking to create a little monitoring amplifier for the Raspberry Pi for a while, as well as creating an amplifier which our phones could plug into for listening to music. After trawling that well-known internet auction site, I came across these little boards for an absolute bargain price of 99 pence each with free postage and packaging.

The power supply requirements are around 2.5v to 5.5v, which means it is suitable for powering from a USB power supply.

The module is described as a “PAM8403 5V DC Audio Amplifier 2 Channel 3W*2 Volume Control USB Power New Board”. There are a bunch of connections on one side, and a volume control/on-off switch on the other.

The connections (0.1″ spacing) are:

  • Left and right speaker connections (8Ω)
  • Power (2.5v to 5.5v)
  • Stereo audio input (Left/Right/Ground)

I hunted around the parts bins and soon came across an old usb cable and a 3.5mm stereo audio cable. These took a while to strip and tin as the usb cable had really fine wires. I needed a voltmeter to determine which of the connections would give me 5v. To make things more awkward, the colour codes used didn’t match with any of my internet research.

The internal layout. The amplifier module sits between the two speakers.

The internal layout. The amplifier module sits between the two speakers.

On to the CAM router to produce a case. The first one would be for my wife while she goes into labour, so I opted for something a little more interesting than a black box.

The template was generated from some earlier work (It’s the same size as the servo robot) but equally it could be created from the Automatic Case Designer

I use a lot of foamed PVC sheet with the router as its easy on the cutters, gives a little and makes a case that looks professional. The tabs fit the slots perfectly if a 3mm cutter is used. The case tends to hold itself together purely by friction although a glue gun can be used to permanently join the sides together.

The amplifier module comes without a knob, but searching around I found a 6mm splined shaft soft-touch knob which does the job perfectly.

Finished amplifier in its case

The finished product!

Here we have the finished case. The speaker grilles are drilled using the router into a heart pattern. The cables are USB power and a stereo jack.

One advantage of USB power was that the amplifier can also be used with a USB backup battery to make a portable amplifier. Alternatively, I found that the USB sockets on the Raspberry Pi can also be used.

Eventually, I’ll make a similar circuit for the Dalek so that it’s self-contained.

In conclusion, this little amplifier board is a perfect little problem solver. It might be possible to drive it direct from the 5v supply on the GPIO connector, although a pretty beefy power supply might be needed if the full 3w x 2 is required, given that this equates to over 1Amp. I suspect that the Raspberry Pi might crash if the amplifier is driven at high volumes with a particularly weak power supply.

Another alternative might be to create an internet/network media player. Couple one of these to a Raspberry Pi running Kodi, stick in a USB WiFi dongle to pick up network attached storage, and use a mobile phone app such as Yatse (Android) as a remote control.

Construction of the ScratchGPIO Dalek – Invasion part 2

Here’s the second installment of the ScratchGPIO Dalek – the first part can be found here. My apologies for the poor quality of the photos. Our camera was in use elsewhere so I only had my mobile. I’ve discovered that it can’t cope with low light and close up shots. Perhaps I should have used the Raspberry Pi camera?

MostOfTheBitsHere’s what I’m starting with. I’ve got a servo, some LEDs (red and blue), Chromed LED bezels and a few bits of plastic cut on a CAM router. The Dalek is a plastic container originally for bubble bath,but having removed the bottle it seems that there’s plenty of space for a circuit board, a servo and some odd bits of wiring.

EyeballThe eyeball LED is made from a piece of chromed brass tubing removed from an old telescopic aerial. The LED is soldered to the end of stranded wire and carefully sealed with hot glue. A clip-on LED bezel is used to complete the effect and makes for a realistic eyeball. I would have liked to add on some disks half-way along the stalk, but I didn’t really have time and perhaps it can be easily overlooked?

The head lights are made from blue LEDs soldered to the end of stranded wire and then pushed into some chrome LED bezels that were in my parts stock. At first, the LEDs were difficult to see as they are so directional and the bezel tended to shield the light coming out sideways. The solution? Fill the bezel with hot glue (in fact, overfill it) and then let it cool without disturbance. This created a slightly domed translucent light which can be seen from all angles. For such a simple solution, I’ve been really impressed with the result. And I didn’t burn my fingers. The domed lights are then pushed into the head. The slightly rubbery nature of the head means that I’m unlikely to need to put the nuts on the other side of the bezels. I don’t think I’d succeed either!

BufferboardThe bufferboard is one of my own designs (more information here) that I produced a while ago. I use it as I managed to kill a couple of Raspberry Pi computers while experimenting with servos. I’m not sure whether it’s a faulty servo that did it, but ever since I’ve been quite nervous to work without this board in the way. It also level shifts the outputs to 5v instead of 3.3v, making the LEDs (particularly the blue LEDs) able to run at their full brightness. Having said all that, I’ve used a 330Ω resistor in series.

ServoWheelThis part is a simple three-spoke wheel that fits on top of the servo horn. The outside diameter has been chosen to fit the inside hole under the dalek head. The three spokes gives plenty of space for the wires to pass upwards from the base. I had pondered how to get the servo horn to stay attached as I’ve found hot-glue to be a bit unreliable on these and there wasn’t really room for the M2.5 screws that I usually prefer. Cable ties to the rescue! They hold well, especially as I filed a few little slots in the servo horn. Simple and effective.

DalekbaseFitting the servo up inside the base was a bit more tricky. There are quite a few obstructions up inside the base which have to be taken care of. In the end, I cut out the top section carefully and then used added a foamed pvc plate which carries the servo. After nearly exhausting my supply of M3 screws, the servo was mounted and the horn fitted.

TwoPartsOfDalekHere are the final two parts ready for fitting together. The cables will pass down through the wheel into the base where they are then connected to the buffer board with 330Ω resistors. The servo is also connected. I ran a little test routine from Scratch to ensure that the servo can reach both extremes and also find the centre. Once this was done, a few blobs of hot glue ensures that the head and the wheel are joined.

Coming up… programing the Dalek with ScratchGPIO (and Python eventually).

Building a PICAXE controlled rover

P1250840I’ve already shown how a PICAXE can be used to build a simple Robot. I know that this blog is really meant to be aimed at Raspberry Pi users but the techniques would be similar. As a result, I thought it’s worth uploading the photographs that show the robot being constructed. If I can get the technical Lego back from my son, it might be possible to rebuild using the Raspberry Pi, and even extend the functions to make more of it!

The original blog post shows the robot in action.

Chassis parts

The chassis is constructed using a variety of beams and plates along with a couple of gear trains. You’ll need:

  • 8 x 1 beams (4x)
  • 8 x 2 plates (1x)

Chassis parts

Continue reading

Raspberry Pi and L298N motor driver boards

L298 Driver board

A few connections to the Raspberry Pi, a power supply and motors… simple!

A quick search of Ebay revealed these little beauties – L298 motor drivers. There’s a 3-pin terminal block for power (I used the 12v and Ground connection), 4 pins available for connecting to the GPIO and terminal blocks for a pair of DC motors. I didn’t use the 5v connection.

At the end of the 4 pins you will also find the “enable” inputs. This could be used to control the motors from a common PWM signal but I left the jumper links in place so that the motor controllers are always active.

In order to connect the driver board to the Raspberry Pi, a 4-way female-to-female ribbon connector is needed. Also required is a common ground connection and a simple way of doing this is to cut the end off a spare connector cable, strip it and push it into the ground connector for the power supply.

The module specifications state that it can work from a wide range of power supplies(5-35V)  and interfaces easily with the Raspberry Pi. I’ve so far used it with the 9v Fischertechnik motors but my next stage is to connect it to some 4.5v Lego Technic motors. I’ve done similar with the L293 and the PICAXE so I’m not expecting any difference. I haven’t yet found out what the voltage drop across the internal transistors is, so I’ll have to pick my power supply with care.

L298 diagram

These are the basic connections. I left the three jumpers as supplied.

Another use that might not be so obvious is that the module can also drive light bulbs and stepper motors. One board would suit a 2 phase bipolar motor and it would be a straightforward job to write the patterns required to step the motor around. Note, however that this would require four GPIO connections per motor, so it might be convenient to use some sort of port expander if this is the direction chosen.

This particular driver board will probably end up on my disassembled Big Trak. I’ve got a 5v power supply that will run from 7.2v R/C racing packs.

Glockenspiel controller

The component side of the PCB

Top view of the PCB

I managed to find some time to change the Glockenspiel controller from using ULN2803 darlington drivers to a whole bunch of discrete darlington pair transistors (BCX38C). It seemed an ideal way of coping with the huge switch-on surges and spreading the current over a whole load of different devices.

The board is single sided which makes it easy enough to etch and solder up. The power is taken directly into the bottom of the board and the open collectors on the transistors do the switching.

The diodes are 1N4001’s which should help to kill the transient produced when the motor is switched off. It was quite nervewracking to see the spark produced when testing the motors across a power supply, so I guess these motors are really capable of packing a punch. At the bottom, I’ve allowed a space for a polyswitch resettable fuse, although in my version it’s not actually being used.

If I knew a little more, I suppose I should use MOSFETs for the switching, but I don’t and I didn’t. Sorry about that.

The Glockenspiel controller circuit

An example of the basic circuit used. 1 channel shown.

One thing that occurred to me was this little board could be applied to lots of different 12v switching situations. Perhaps a large lighting display using Superflux LEDs wired in bunches.

The board layouts are available for those who may wish to copy it: