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 :


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)