Further Pluto PTT issues…

In my last post on the Pluto External PTT I had done some preliminary testing of the external PTT output using a multi-meter before wiring it to the Pluto Charon and confirming it worked. It was at this point things took a jump to the left and then a step to the right…

What I noticed is I would hit the TX button in SDR-Console and there would be a pause, one, two, three, then click would go the transmit receive (TRX) relay. Hmm that’s not going to do, a 3s delay between the PC software PTT and the Pluto Charon external amplifier ain’t going to work on FM/SSB.

However if I hit the TX button in SDR-Console again the TRX relay would click and go off without any delay. Now that was strange and the asymmetric nature of operation required further investigation.

The first step was to rule out the hardware, so with a C.R.O on the Pluto Charon PTT line (connector A1) and another on the ADALM Pluto GPO0 pin (yellow and cyan respectively) we can check that the switching is nice and clean.

Nope nothing to see here, you can see the transistor on the Pluto Charon PTT board pulling the PTT line low and hitting zero volts in no more than 12us. Problem has to be elsewhere.

So now were into firmware and software territory, sigh this is going to be one of those rabbit holes.

I firstly tried the “for the brave” firmware that can be found on the Mini-kits support website, which is an early version of the PlutoDVB firmware. This changed the behavior entirely and there was a delay of 1-1.5s each time the external PTT changed state from ON to OFF. Not what I wanted, but better and perhaps more usable than the 3s ON and instant OFF I was seeing on the PlutoDVB revision 3.0.3 firmware + Rev C/D patch.

Further reading from the analog devices website suggested that the GPO pin connected my external PTT module could be controlled by some ENSM module within the AD9361-phy linux driver, so I tried some experiments with SDR-Console and the Analog Devices stock v0.38 firmware, that didn’t work either. It was clear that SDR-Console was not using this IIO method to switch the Pluto in to TX or RX.

So I revisited the latest PlutoDVB firmware (perseverance 3.0.3 + Rev C/D patch) once again reading and watching more closely this time.

It was while applying the patch I saw something interesting, I’ve highlighted it in red adjacent. I wonder what that script does ?

The whole reason the patch was required in PlutoDVB Perseverance 3.0.3 firmware was to get the PTT working with revision C & D hardware. I wonder if that is where I start ?

So let me log into the Pluto and take a peek at the script.

#!/bin/sh
#https://www.analog.com/media/cn/technical-documentation/user-guides/AD9364_Register_Map_Reference_Manual_UG-672.pdf
source /root/device_sel.sh
ptton()
{
    #PTT on GPIO 0 AND GPIO 2 (GPIO 1 should be not touched)
    echo 0x27 0x50 > /sys/kernel/debug/iio/iio:device$dev/direct_reg_access
    mosquitto_pub -t plutodvb/status/tx -m true
}

pttoff()
{
    echo 0x27 0x00 > /sys/kernel/debug/iio/iio:device$dev/direct_reg_access
    mosquitto_pub -t plutodvb/status/tx -m false
}

echo manual_tx_quad > /sys/bus/iio/devices/iio:device$dev/calib_mode
#Manual GPIO
echo 0x26 0x10 > /sys/kernel/debug/iio/iio:device$dev/direct_reg_access
pttoff

while :
do
inotifywait -e modify /sys/bus/iio/devices/iio\:device$dev/out_voltage0_hardwaregain
gain=$(cat /sys/bus/iio/devices/iio:device$dev/out_voltage0_hardwaregain)
if [ "$gain" = "-40.000000 dB" ] ; then
    echo "SdrConsole PTT OFF"
    pttoff
else
    if [ "$gain" = "0.000000 dB" ] ; then
        sleep 2
        gain=$(cat /sys/bus/iio/devices/iio:device$dev/out_voltage0_hardwaregain)
        if [ "$gain" = "0.000000 dB" ] ; then
            echo "SdrConsole Power Max PTT ON"
            ptton
        fi
        else
            echo "SdrConsole PTT ON"
            ptton
        fi
    fi
done

So reading my way through this script by the time I hit line 24 I had confirmed

  • SDR-Console does not use the ENSM module within the Pluto ad9361-phy driver
  • Instead the script uses the sysfs subsystem to read different values from the IIO driver
  • SDR-Console varies the TX gain within the IIO driver between two limits that the script interprets and drives the relevant GPO pin
  • In an attempt to prevent a race condition, line 31 introduces a 2s sleep function between successive reads of the gain value

Guess where the 3s delay I’ve been searching for comes from !?!

So a quick bit of hacking on this script, changing line 31 to read “sleep 0.1” or 100ms, then restarting the “watchconsoletx.sh” process increased the speed of the external PTT to the point where the delay between SDR-Console and the TRX relay on the Pluto Charon activating is nearly imperceptible. I’m not sure if using a fraction of one second is valid in this shell, it may have been ignoring it, but it proved my point.

However what I’ve done to this script and the way in which SDR-Console works I’m not convinced will work 100% of the time. The other problem is any changes that are made to these script files are not permanent they are only kept in RAM, so as soon as you reboot they revert to those stored in volatile memory (flash).

So it looks like I may have to reverse engineer the “pluto.frm” file and see if I can hack together a better script to make this work how I want. At least I now know where the 3s delay has come from and that there are possibilities to fix it.

That however will have to wait until the next post.

Pluto PTT and PlutoDVB Firmware

The next step in the process of using the ADALM Pluto is sorting out a press-to-talk output to drive the Pluto Charon. In this instance I’ve followed the tried and trodden path of adding a small transistor output to one of the GPIO pins and updating the firmware. There are some interesting articles on the ADI website that discuss how to do this via the FPGA, but I decided to learn to walk before I ran.

When I ordered my Pluto Charon kit I also purchased the separate PTT module which you can see here (click). This is very easy to install, just make sure you observe good ESD practices when you remove the Pluto from it’s case and handle it on the bench.

Here’s the photo’s of how I installed mine.

I decided to use a small two pin right angle KK 0.254″ molex connector for the PTT output, as I’d like the capability of unplugging Pluto and Charon boards for service/changes/updates etc.

Now for the hairy scary part of the process. On the Mini-kits website is a URL to some custom firmware written by Evariste F5OEO that can enable a PTT function on a GPIO pin. I was at first a little alarmed by the comment “for the brave”, but it turns out this firmware is part of the PlutoDVB project. You can find later software from 2022 on Christian F5UII’s website (click) and you’ll see some comments about fixing the PTT on the Pluto Rev D boards to work with the latest versions of SDR-Console. I have a Pluto Rev C, which is the same as the Pluto Rev D, so I had no choice but to use this newer firmware and work out what to download.

So after reading most of Christians Website I discovered I had to do two things. Firstly I had to swap from the official ADI Pluto v0.38 firmware to the custom PlutoDVB 3.0.3 firmware. Secondly patch the 3.0.3 firmware to account for the Rev D hardware. This wasn’t obvious where to start.

Below is a summary of the steps I used to swap the firmware.

  • Connected the Pluto to my PC, checked it had presented a removable drive
  • Download the firmware from Christian F5UII”s website, I used the PlutoDVB perseverance firmware 0303 (26.6M)
  • Extracted the pluto.frm from the downloaded zip and stored it on the Pluto removable drive created on my PC (don’t get confused or alarmed by the file name “patch.zip” as this is indeed the entire firmware)
  • Ejected the Pluto and waited for it to finish doing the upgrade and reboot, once done it reconnected to the PC
  • Used a web-browser to point to http://192.168.2.1/index.html, confirmed it presented the “Lets go to PlutoDVB” welcome screen, not the ADI reference material.
  • Then clicked on the “Lets go to PlutoDVB (USB connection)” button which launched into the system setup.php page
  • From the menu across the top, selected “System ” then “Maintenance” where I found the patching and upgrading firmware mechanism.
  • For my hardware (Rev C/D) I needed to download and apply the “Patch for PlutoSDR Rev. D hardware”
  • Applied the patch, saw that within the “Delete Patch” window the updated files were displayed once done
  • Success !

Now I could configure the PlutoDVB firmware to do what I wanted, which in my case was to use SDR-Console. So from the “system” menu at the top I clicked on the “Pass-through” option and hit apply. That should be all I needed to complete.

There is an error message displayed across the top of the screen about a datv text file not being present. If you enter your call-sign in the respective field on the setup page and your name in the DVB provider field, hit “apply settings” and this will create the right file and the error message disappears.

Once all of this was done, I was able to setup and configure SDR-Console and test that the PTT worked with a multi-meter. Below you can see SDR-Console listening on 23cm ready for me to hit the TX button. The Pluto is sitting right up against the PC, so I’m not surprised there are some birdies in the shack, I’ll only panic once the Pluto and Charon and boxed up together.

For my next trick I intend to hook this up to my CRO and see how long before or after the PTT line is asserted does RF appear at the transmit port. However that will have to wait for the next post.

Boxing a Pluto Charon – the Heatsink

For the past couple of weeks I’ve been giving some thought as to how I’d box up the Mini-kits Pluto Charon. As with any problem the first step it to work out how I want to use it.

I’d like to be able to use the Pluto Charon both in the field and in the ham shack. The ADLAM Pluto connects to a PC via a micro USB and presents itself as a USB Ethernet device.

Further reading suggests that the ADLAM Pluto USB OTG port can host an external USB-Ethernet adapter or USB-WiFi adapter, making it possible to un-tether the Pluto from a PC or use standard IT infrastructure. In my situation an external Ethernet port is of interest, since I could easily build all of the Mini-Kits Pluto boards into their own enclosure and simply network them together and into the same PC without having to count on multiple USB ports. This again fits with my field and shack mode of operation.

The output power of the Mini-kits Pluto Charon, Pluto Styx and proposed Pluto Nix kit is in the region of one to two watts. This is more than enough transmit power to jump from hilltop to hilltop over quite a path with some antenna gain and short cables. If however you want to lift the antennas up to the top of mast, external in-line amplifiers up behind the antennas would be required to keep losses under control. If the external amplifiers also included a separate mast head amplifier, then losses of up to 6-8dB at any of these microwave frequencies could be accommodated without significantly impacting performance. I’ll be exploring this further once the first Pluto Charon kit is completed.

So, the first step of course is to get the Pluto Charon kit operational, to do that I needed to test it. The kit came with a small 40x40mm heatsink that I could attach to dissipate the heat from the final amplifier IC1. I mulled this over for a while before deciding I’d prefer to put a much larger heatsink on the top of a die cast box and mount the Pluto Charon to that. A good example of what I’m thinking is how I built my Rubidium reference (here). My main reasoning is I’d like to stabilise the heat within the die cast box so the Pluto does not need to work so hard on keeping the frequency stable. Did I mention the Rubidium reference, one would say this started these shenanigans.

To get the heat out of the Pluto Charon final amplifier the layout dictated a small copper block to be made. There are components on the top and bottom of this board, so one needs to pay attention to clearances etc. So it was off to see a good friend with a lathe ;thanks Peter it was a fun afternoon and some good machining Zen !

It is no coincidence that the copper block is 10mm thick, this is perfect for three 10mm hexagonal spacers to be placed under the remaining three sides of the PCB for support.

The hole in the middle of the copper block is what transfers the heat from IC1, so this was tapped to accept a M3 hole. The PCB had a plated 2.5mm hole and was reamed out slightly to accept the larger M3 screw. The M3 screw used was tin plated copper, not tin plated steel/stainless which is a poor conductor of heat.

The remaining four holes in the PCB that hold the heatsink were left M2.5 and the holes through the copper block drilled 3mm for clearance. When this is attached to the heatsink, four M2.5 x16mm screws through these holes in the heatsink, washers and split washers will be used to sandwich the assembly and keep everything held tight.

So I don’t forget and for anyone following along at home I’ve included the drill pattern. This was the only information conspicuously absent from the assembly instructions. This drawing is drawn from the top of the PCB looking down. The hole in the middle of the heatsink is referenced from the center of the copper block. For some reason I can’t get LibreCAD to show a mark for the origin yet. I hate having to measure PCB’s to get hole locations, a combination of transfer punches, vernier calipers and gauge pins were used to establish and check that these locations were close enough.

Now it’s time to carry on with the Testing and Alignment of the Pluto Charon !

So after two years ?

For quite some time I’ve been promising my eldest son his own bedroom. However like everything, this is somewhat complicated and has taken far longer than expected. To make this happen, I’ve had to make more shelving in the shed, move stuff stored in the garage out into the shed, clean out the garage and move my office, which was in the 3rd bedroom of the house out into the garage soon to become my new man-cave. I’ve felt like I’ve been playing musical chairs with storage boxes for quite some time. Then there is the time required to renovate said 3rd bedroom back into a teenagers retreat, so much work, so many weekends, I still hate painting.

However, while moving things out of the office and into the new man-cave I rediscovered the Pluto Charon kit, languishing in a forgotten project box. My original plan was to use this kit as my 23cm home station, however during the above renovations a member of my radio club offered me a pristine Icom IC-910H with 23cm module which I couldn’t refuse. Needless to say the Pluto Charon priority and urgency was pushed back somewhat.

Fast forward two years and having rediscovering this kit, along with seeing the new 12cm Pluto Styx kit available (click) and a teaser for the 6cm Pluto Nix, well it was time to finish it and continue working my way up through the microwave bands.

BGU8051 are small

This kit requires the usual SMD microwave construction techniques, so fine solder a good iron, a steady hand and optical magnification is an absolute must. The Mini-kits instructions and support page are as usual first class. However one should heed the warning on the website ordering page that “this kit is not for beginners and requires very experienced soldering skills”.

I generally found the majority of the kit straightforward, until I got to IC5 which is a BGU8051 preamp from NXP. You should check out it’s specs on the NXP website. This is one of those “looks big on the computer screen” kind of parts that even designers get caught out with when ordering their first samples. I’ve included a photo, along with a strategically placed steel ruler for scale. That IC is tiny… really tiny !!!

At just two by two by three-quarters of a millimeter with eight pins, it was clear that this was not going to be soldered by any ordinary soldering iron. Thankfully I have a hot-air rework station, so I manually pasted the board with an I-Extruder, used plenty of flux and re-flow soldered the device to the board. Since inductor L7, capacitor C30 and resistor X3 were so close, I chose to leave these off until I had soldered IC5 to give me room and ensure the hot air did not cause unnecessary stress to adjacent components, YMMV. I also typically use a T3 solder paste for the majority of my kit building, but for this board I resorted to using T4 since you could nearly count the number of solder balls dispensed onto each pad of IC5. However I’m happy with the result and with the right tools this kit can be assembled at home. There are many YouTube tutorials on how to solder with hot-air worth watching as well.

Once I had the kit soldered together I then turned my attention to how I was going to put it in a box and begin to test it. However that is for the next post !

Motorola CPS on Windows 10/11

It is no secret that Motorola CPS software does not like to run on modern operating systems. I still have a number of UHF Motorola MTS2000 handhelds which once given new batteries have proven themselves useful time and time again.

However my trusty old Windows XP laptop, with a real serial port fried its motherboard recently never to boot again. My immediate thought was “yikes what do I use now to program these Motorola radios” ?

So rather than go looking for further ancient hardware I started experimenting if Motorola CPS would run on a Windows 10 64-bit platform. I’ll spare you the gory details, but not amount of compatibility mode twiddling or research would result in a working system. There is something fundamental in the RS232 32-bit sub-system within the CPS software that prevents this from ever working. I could not get the CPS software to “read device” instead receiving a timeout. Grrrr….

So the only alternative was to experiment with an older version of Windows in a virtual machine and passing through a serial port. I remember when Windows 7 was first released Microsoft released a version of Windows XP that would run within Microsoft Virtual PC. The Motorola CPS software is from around the same time, so it was an ideal candidate to try. Turns out this was easier than I expected.

Setup Windows XP Virtual Machine

I found the following setup guide very useful from Help Desk Geek website (click). The download link from the Microsoft site has disappeared, but the alternative link from the CNET site was working at the time of this post.

I followed this guide closely, there are a few steps you needed to pay attention too but otherwise this went smoothly. I’m currently using a Windows 10 host and the only trouble I had was with the mouse, where I could not control the mouse within the Guest correctly, but you can temporarily disable the VirtualBox “mouse integration” feature to get around this until the VirtualBox Guest Additions are installed. Once the Guest additions were installed, everything worked as expected.

Activating Windows XP in 2022

The next challenge is since Windows XP support ended there is no way to “activate” this vanilla of windows any more which is right painful. One work around is to snapshot the VM and rollback each time you wish to use it, I wasn’t a fan. So thankfully the “Roger Webb” YouTube channel had a video that shows how to work around this problem, don’t forget to leave a like.

Serial Port Pass Through

Now I’m lucky that my Gen-3 I7 desktop machine has a real serial port on the motherboard. This was one of the very last Intel made motherboards with the legacy IO chipset, so not only do I have a serial port it has a parallel port too.

To allow Windows XP access to the host serial port, one just needs to configure the hardware pass through. Within the VirtualBox settings there is a separate “Serial Port” tab that simply requires mapping between the guest and host systems.

As you can see I’ve simply mapped COM1 on the guest to COM1 on the host, simples !

Copying Motorola CPS into Windows XP

So for the grand finale we can install the Motorola CPS software within Windows XP. How one gets the software installed can be done a few different ways.

I decided to use the VirtualBox shared folders mechanism. With the guest additions installed I found once I’d configured the shared folders they were automatically mapped as a network drive the next time I restarted the Windows XP guest. It was a simple matter to then double click the executable and install.

There were a few websites with rough instructions, but I found after watching the following YouTube video from Peter Downie I was able to get it working in short order;

The other method I’ve used to pass software through to a guest is to use a USB thumb drive. Copy the files from the host to the USB, pass the USB through to the guest, move the files and eject to pass it back. Both methods work just as well as each other.

The Proof is in the Pudding

So once you can copy the relevant files into the VM, then it’s a simple matter to install and run the Motorola CPS software. Then simply configure it to talk to the serial port you’ve passed through which is COM1 in my case, then try to read a physical radio. Please note that Motorola CPS software is licensed and cost real $$$ to purchase, please do not request copies of said software fro me as refusal often offends.

You will know you’ve got it right when you hear the radio beep, it says PRGM on the radio display and you are greeted with the contents of your code plug.

I was certainly relieved to be greeted with the screen shown above, make my changes and write the config back to the radio. I’m once again in business. I hope that other users of older Motorola CPS software find this useful.

How do you get on 23cm ?!?

I was recently looking at getting some radio gear that would get me up onto the Australian 23cm Amateur Radio Band. My first thoughts was to find some second hand commercial amateur gear, but this was soon dashed when 20 year old radios on eBay were fetching more than A$1000 in less than pristine condition. They are hard to find !

My second thought was of course a transverter. Where I would take one of my 2m or 70cm transceivers and “up-convert” the output onto the 23cm band. This is usually done by a combination of loads, mixers, fixed oscillators and amplifiers that you buy assembled or as a kit. Since I wanted to do both FM and SSB this presented something of a problem as the receive transmit frequency split for Australian 23cm repeaters is +20MHz. This means the radio attached to the transverter IF port has to be capable of wide band receive, which is not very common. So my calculator again suggested after I’d built a transverter, added a dedicated IF radio I’d be somewhere northwards of A$750… sigh that second hand commercial radio looked good again.

One of my local radio club members then introduced me to the Analog devices ADALM-Pluto SDR and the Pluto Charon 23cm module from Minikits here in Adelaide. I was hooked and two new toys were duly ordered and shipped. The cost of both the ADALM Pluto and Charon 23cm module was less than A$450 delivered but I did have to do a little shopping around to get the Pluto at a good price.

I then started researching what exactly you can do with one of these little devices and what exactly I’d just bought. I’m simply amazed at what Analog Devices have stuffed into this little box, better yet I’d received one of the Rev D platforms which has all the bells and whistles. As I discover things about the Pluto, I’m sure to blog them here soon.

I was again pleased to find the ADALM-Pluto was already supported by SDR-Console written by Simon Brown G4ELI. I’ve used SDR Console for many years in all of my HF contesting stations to display waterfall information. Using it for transmit was going to be a new experience.

Now to wait for that postman !

Display a PNG Image on small 128×128 OLED LCD

Now that my small OLED display automatically loads the device drivers on boot, it was time to see if I could display an image on my new frame buffer device.

To start with I went looking for a very basic graphics library that would allow me to experiment on frame buffer devices. There is certainly no shortage of libraries to choose from. The library that I settled on was the “Lightweight C 2D graphics API agnostic library with parallelism support” written by grz0zrg. It had both PNG and JPG routines that could output to a simple frame buffer device, being written in C was also a winner.

Flicking through the various examples the quickstart.c file seemed to have nearly everything I needed to display a PNG file on my OLED. Not so long ago a fellow AREG club member shot me some icon files for our club website; one of these icons was 512×512 pixels in size which made it an excellent candidate for shrinking to 128×128 pixels and using it on my OLED.

Downloading the library was as easy as;

$ cd ~
$ git clone https://github.com/grz0zrg/fbg

If you don’t have git installed use the relevant apt-get command. The example files can then be found in the following directory;

$ cd ~/fbg/examples 

I then copied the quickstart.c file and hacked on it a little, modifying it like so;

#include <sys/stat.h>
#include <stdio.h>
#include <signal.h>
#include "fbgraphics.h"

int file_exists( const char* filename )
{
    //define file handle
    FILE *file;

    //attempt to open file read only
    if( (file = fopen(filename, "r")) )
    {
        fclose(file);    // release file handle
        return 1;        // tell someone we found it
    }
    else
    {
        return 0;         //no one home
    }
}

int main(int argc, char* argv[])
{
    const char* framebuffer_name = "/dev/fb1";
    const char* logo_filename = "logo.png";

    //check we have a framebuffer to talk to
    struct _fbg *fbg = fbg_setup( (char *)framebuffer_name, 0);
    if (fbg == NULL)
    {
        return -1;
    }

    // make sure logo file exists
    if( !file_exists( logo_filename ))
    {
        printf("File not found: %s\r\n",logo_filename);
        return -2;
    }

    //draw something on the display
    struct _fbg_img *logo = fbg_loadPNG(fbg, "logo.png");
    fbg_clear(fbg, 0);
    fbg_image(fbg, logo, 0, 0);
    fbg_flip(fbg);
    fbg_draw(fbg);

    //release memory
    fbg_freeImage(logo);
    fbg_close(fbg);

    return 0;
}

Which was built with the following command line from within the examples directory;

gcc ../src/lodepng/lodepng.c ../src/nanojpeg/nanojpeg.c ../src/fbgraphics.c display_logo.c -I ../src/ -I. -std=c11 -pedantic -D_GNU_SOURCE -D_POSIX_SOURCE -Wno-unused-value -Wno-unknown-pragmas -O2 -Wall -lm -o display_logo

Hacking upon the Makefile is also not that difficult, I simply added the relevant lines the SRC and OUT sections, then copied the quickstart section and renamed display_logo. There is lots of information about on how to do this on the internet so I’ll not repeat it again unnecessarily.

All I had to do then was place my 128×128 PNG file alongside the display_logo executable (renamed logo.png) and run it… wallah ! I was greeted by the AREG logo on my small OLED display in all of its 128×128 pixel glory; see the image at the top of this post.

So the next trick is to move this to the boot process… So by the looks the plymouth package might be the go, only one way to find out.

Starting a fbtft_device on Boot

After having woken up my small 128×128 OLED display I was wondering how to get it to start automatically each time my rPi booted rather than having to log in and run the commands manually.

It turns out this is rather easy and just required me to edit two files. I’m also glad that these Waveshare OLED displays are effectively compatible with the Freetronics OLED 128×128 graphics display. A big thanks to the Freetronics team for making this driver available for SED1351 chip sets.

So I created the following file with my favourite editor (as root) /etc/modprobe.d/fbtft.conf with the following contents;

options fbtft_device name=freetronicsoled128

What this effectively does is tell the system how to configure the fbtft_device as it boots, much like if we started it with modprobe from the command line i.e used the following command;

sudo modprobe fbtft_device name=freetronicsoled128

So now the system knows how to configure the driver, we need to tell modprobe to load it by placing an entry in the /etc/modules file. So using your favourite editor (as root) edit /etc/modprobe and append the last two lines.

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

i2c-dev
spi-bcm2835
fbtft_device

It appears that the SPI bus is a little slow to load if it’s called as a dependency of fbtft_device, which is a classic chicken and egg driver problem. So by starting it manually we make sure it’s available by the time the fbtft driver tries to do anything.

The i2c-dev entry in the same file fires up the i2c bus and was already pre-configured in my system by raspi-config way back when. I’m using it in my project, YMMV. All that is left to do is test it, so reboot and login and run the following command;

$dmesg | grep graphics

We should see something like the following;

[6.128978] graphics fb1: fb_ssd1351 frame buffer, 128x128, 32 KiB video memory, 4 KiB buffer memory, fps=20, spi0.0 at 20 MHz

That tells us that the little OLED display has registered as /dev/fb1 and that it’s ready to go. You can use the con2fbmap trick in my last post to test it’s working.

Now to work out how to get it to throw up an image on boot…

Small OLED Display on a rPi

Recently I was searching for a small graphic display that I could connect to a Raspberry Pi and fit within a Phoenix DIN enclosure I wanted to use.

There isn’t much space in the front of the enclosure I wanted to use, but a small 128×128 OLED colour display seemed it might fit.

Trawling through eBay I found what I thought to be a suitable unit and simply placed an order. There was very little information on the eBay site to tell me which display I had purchased so I just waited. When the display arrived it turned out to be a Waveshare SKU:14747 with the SED1351 controller.

A little searching around the web and I found an excellent tutorial written by the Freetronics Team for their 128×128 OLED display. It turns out our displays share the same SED1351 controller, so it was the logical place to start with my small display.

First task was to map the OLED pins to my rPi 3B+ 40-pin GPIO connector. On the rear of the display the pins and their desired function were clearly marked, so I mapped the pins like so;

OLED    | rPi      (pin)
--------+----------------
+5      | 5V       (1)
GND     | 0V       (3)
MOSI    | SPI_MOSI (19)
SCK     | SPI_SCK  (23)
CS      | SPI_CE0  (24)
DC      | GPIO25   (22)
RST     | GPIO24   (18)

I have also included the rPi pin numbers I used, make sure you plug the display into the right pins if in doubt RTFM. Once it was wired I ran the following commands to make sure the rPi was absolutely up to date;

sudo apt-get update
sudo apt-get dist-upgrade
sudo reboot

The latest version of Raspbian Lite I was using (Buster) came with the fbtft frame buffer drivers already installed, so these steps were unnecessary. Since this Raspbian installation was fairly recent I decided that I didn’t need to update the rPi firmware using the rpi-update command like in other tutorials; YMMV.

I had already enabled the SPI bus on my Pi when I was coming to grips with the I2C bus. I found the tutorial at Sparkfun a really good reference and easy to follow. To create the frame buffer for the OLED device I ran the following command;

sudo modprove fbtft_device name=freetronicsoled128
dmesg | tail -20

Fingers crossed we see the following output in our terminal;

fbtft: module is from the staging directory, the quality is unknown, you have been warned.
fbtft_device: module is from the staging directory, the quality is unknown, you have been warned.
spidev spi0.0: spidev spi0.0 125000kHz 8 bits mode=0x00
spidev spi0.1: spidev spi0.1 125000kHz 8 bits mode=0x00
bcm2708_fb soc:fb: soc:fb id=-1 pdata? no
spidev spi0.0: Deleting spi0.0
fbtft_device: GPIOS used by 'freetronicsoled128':
fbtft_device: 'reset' = GPIO24
fbtft_device: 'dc' = GPIO25
spidev spi0.1: spidev spi0.1 125000kHz 8 bits mode=0x00
spi spi0.0: fb_ssd1351 spi0.0 20000kHz 8 bits mode=0x00
fb_ssd1351: module is from the staging directory, the quality is unknown, you have been warned.
graphics fb1: fb_ssd1351 frame buffer, 128x128, 32 KiB video memory, 4 KiB buffer memory, fps=20, spi0.0 at 20 MHz

The output here shows us that the SPI bus is OK and that we now have a frame buffer /dev/fb1 that is expecting to find a SED1351 LCD controller. So now it was time to display something so I used following command;

con2fbmap 1 1

And here is what I see;

w00t it works ! Now it’s time to go and find some graphics libraries that can talk to this frame buffer device… and to work out how to display text in boxes that is wider than 80 columns in WordPress…

MQTT Paho C Library

One of my upcoming “Radio” projects involves MQTT running on a raspberry Pi. I’m more familiar with C than I am with Python so to talk to the MQTT broker I went looking for a C based client.

I eventually settled on the Eclipse Paho MQTT C Client library, however it doesn’t come with an ARM based Linux binary package like you get for all the python peeps. Instead you’ve got to compile this from source, I guess since I’m intending to use C in the first place I should be OK. So back to the command line.

Starting with a bone stock installation of Raspbian Buster Lite I simply used the following commands in a shell;

$ sudo apt-get install git libssl-dev doxygen graphviz
$ cd /tmp
$ git clone https://github.com/eclipse/paho.mqtt.c
$ cd paho.mqtt.c/
$ make
$ make html 
$ sudo make install
$ cd /tmp
$ rm -rf paho.mqtt.c

I found all of the commands above in the git repository README.md file. One thing I noticed was when compiling the libssl-dev library generated a good many “deprecated” warnings about old TLS ciphers being used (ie TLS 1.1, 1.2, 1.3 and SSL 2.0 & 3.0) so if you’re intending to use these it might be best to dig a little further. In my case this wasn’t important so I’ve filed it away here as a note to self for future reference.

So now it was just a question if the library works, the simplest way to do this was to compile the included examples and see if they work. So back off to the command line we go.