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 : https://twitter.com/IRoulson/status/1598823854641586177

Advertisement

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 (https://microblocks.fun/) 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.

Downloads

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: https://wiki.microblocks.fun/boards/special_pins

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

Development Board for the Raspberry Pi Pico

I’ve been experimenting with the Raspberry Pi Pico for a little while now and I found that I kept coming back to the same issues – sensors need power, servos need power, I2C devices need power and the SCL/SDA connections. While there are plenty of Ground connections, I had to make up Y-leads so that the 3v3 connections went to other devices.

I also wanted to link this board to some handy little servos, piezo elements and LEDs, as well as having a few switches and an OLED display.

A bit of tinkering with Fritzing and I ended up with this board. Actually, this is version 2. The first was missing a few connections and I’d put the switches 90 degrees around, meaning that the connections were permanently short-circuited.

Pico PCB with Laser Cut Front Panel and 3d printed case.

I’m happy to make the files available and I’ve uploaded them to my webspace. I haven’t got my head around the whole CC-BY-SA thing, so use them. I’d love to hear from you if you have success though!

Files for the Raspberry Pi Pico circuit board:

Gerber files for the PCB are here: http://roulson.net/PiPicoPCB/Gerber.zip

STL files for the top and bottom layers of the sandwich are here: http://roulson.net/PiPicoPCB/TopSpacer.STL and here: http://roulson.net/PiPicoPCB/BottomSpacer.STL

DXF files for the top and bottom of the case are here: http://roulson.net/PiPicoPCB/TopAcrylic.DXF and here: http://roulson.net/PiPicoPCB/BottomAcrylic.DXF

You will also need a 128×64 i2c OLED display, a bunch of 0.1″ pin headers, two 5mm LEDs, four 6mm tactile push switches (with fairly long actuator around 12mm) and two 150ohm resistors. On the back is a longer pin header which is handy for a stepper motor controller or H-bridge.

Assembly

At some point I’ll do a little photo-shoot of the board being assembled. Not much to it, although some things need fitting in the right order as other parts cover up the joints.

Programming

Programming of the board seems to work really well using Microblocks, which runs either in a browser or (in my case) as a download to my Raspberry Pi 400. Microblocks is at https://microblocks.fun/

It is also possible to use BIPES or MicroPython directly with the board.

Raspberry Pi Pico

Well.. it has been a long time since the last post here. I’m still using Raspberry Pi computers and in particular I’m writing this on my pi-topCEED.

I recently bought a couple of Raspberry Pi Pico boards. I didn’t know what to expect, particularly as I have no experience of micropython, but the first impressions are very good. I can’t fault the price – it comes in at less than a Pi Nano and for much of the basic control that I wanted, it looks ideal. It supports NeoPixel style LEDs, LED arrays, a little RTC board that I’d acquired a while back and servos. Cheaper than my usual microcontroller go-to IC, with on-board USB socket for power and download.

I’ve used “Thonny” with the add-in for the Pico, and that works fine, but I’m also experimenting with “BIPES” https://bipes.net.br/beta2/ui/ which seems to offer a good range of facilities. I’m having a couple of issues with variables, but I’m sure that it will soon be sorted.

BIPES is a Blockly-type of programming language, which suits anyone who has learnt Scratch, with the advantage that it supports all sorts of inputs and outputs connecting to those rows of holes or pins down the side of the board.

Watch this space for my experiments!

ASCII selfies

selfieI’ve been experimenting, after a long break, with jp2a again, converting captured images into ASCII representations, which are then sent to a local printer. I remember, long ago and as a child, having my face printed onto a t-shirt in Blackpool. The ASCII character set made up the individual “pixels”.

With this experiment, I’ve used an old Deskjet 930c printer and a cheap USB web cam.

From a software point-of-view, I’ve installed the following:

  • CUPS – The Unix Printing System
  • jp2a – Takes a jpeg image and turns it into ASCII text
  • GUVCVIEW – captures images from a webcam
  • Figlet – to create the text for an interesting banner at the bottom of the page

“lp” is the command that sends this text to the printer. There are loads of command line options available. I’ve wrapped this all up in a bash script and set it to run from the command line by making it executable.

To make this all work, I capture an image and it gets saved as my_photo.jpg. I then run the script shown above, typing ./printphoto.sh and the printer spews out a rendered version of whoever is in front of the camera. Neat… and I’ll demo it at the next Raspberry Jam.

Future options would be to use a big button to start the whole process off. I’ve done it before, but there’s not enough time remaining for that.

Minecraft Molehills?

Here’s a little program for generating random holes in the landscape and automatically putting a candle at the bottom. The idea is that this could be run on the Raspberry Pi running as a server so that other players can have a little fun hunting for them.

I’ve discovered that candles don’t like being put underwater… no surprise there!

Hole generated in Python with a candle at the bottom.

Watch your step – a deep hole created by the python program.

Screenshots have been created following the instructions at Raspberry Pi – Spy.

from mcpi import minecraft
import time
import random
mc = minecraft.Minecraft.create()

mc.postToChat("Python is now in control!")

def Molehole(x,y,z,depth):
    mc.setBlocks(x,y+40,z,x+0,y-depth,z+0,0) #clear the space first
    mc.setBlock(x,y-depth,z,50) #Put a candle at the bottom of the tunnel  


for loop in range(20):
    startx = random.randint(-120,120)
    startz = random.randint(-120,120)
    starty = 0
    Molehole(startx,starty,startz,20)

Poundland Universal Remote Control

I’ve been experimenting with the infra-red input commands on the PICAXE for some simple remote control Lego robots. There is an official remote control for the PICAXE – in an eye-catching blue case, but for economy I’ve bought a bunch of Poundland universal remote controls.

They don’t give the same hardwearing impression that the official ones give – the cases are a little more flimsy, but they do seem more than adequate to remote control a PICAXE and can therefore add a whole new dimension to PICAXE circuits. An infra-red receiver is an easy thing to add and it means that one input can effectively pretend to be many switches – all present remotely on the handset.

To program the remote, press and hold the TV remote for 5 seconds. The LED will light at this point. Type in the code 0495. When this is completed, the LED will go out and the remote is ready to use.

The command to receive the remote signals is to use:

irin [100],3,b0

Assuming that you’re using input 3. I often use the 08M2 Picaxe, and this is fine. The value is dumped into byte variable b0.

Often I use the following program:

main:
    irin [100],3,b0
    debug
    goto main

to see the effect of pressing different buttons in the debug window.

I’ve discovered the following codes  (File: PoundlandUniversalRemote as a PDF file):

PoundlandUniversalRemote