Posts

Showing posts from 2022

How to write reliable tests for Python MQTT applications

More and more IoT applications use MQTT. It's a simple and very useful messaging framework which runs on small boards like the Raspberry Pi Pico as well as systems running under Linux, MacOS and Windows. I recently decided to add some extra functionality to Lazydoro using MQTT. The code seemed to work when run manually but I had a lot of trouble getting my automated tests working. It took quite a while to understand the problem, but the fix was simple. Intermittently failing tests are bad In the end-to-end test that was causing the problem, the code simulated the start of a pomodoro session and then checked that the correct MQTT message had been  sent. The test usually failed but sometimes passed. When I manually ran a separate client that subscribed to the message stream I could see that the right messages were being sent. Intermittently failing (or passing) tests are a nuisance. They do nothing to build confidence that the application under test is working reliably, and they are

How can you make your Pico/Pico W project portable?

Image
In this article you'll learn how to solder the Pimoroni Lipo Shim for Raspberry Pi Pico/Pico W and use it to power your project from a single LiPo battery. You'll also discover a problem, and a solution, if you want to check the battery level remotely. Some Pico W projects need to work anywhere. Wi-Fi takes care of the connectivity, but the projects need battery power to make them truly portable. If you're building a portable project you'll find the Pimoroni Lipo Shim for Pico is a great solution. Here's how to attach and use it. Powering the Pico While you're writing the software for your Pico or Pico are you'll be using a USB cable to linking it to your host. Once your hardware and software are working you may want to free the Pico from its umbilical cord. The Pico can be powered from a battery; it's very adaptable, working off an input voltage that can range from 1.8 to 5.5 volts. The Pimoroni Lipo Shim for Pico takes advantage of t

Raspberry Pi PicoW projects on Tom's Hardware PiCast

Image
A few days ago I was asked to present some of my Raspberry Pi Pico W projects on the PiCast from Tom's Hardware . Editor Avram Piltch ( @geekinchief ) was the super-friendly host as usual, and Les Pounder ( @biglesp ) told us about his Pico W-based webserver. Raspberry Pi expert  Ash Hill  added to the fun. Ash edits Tom's hardware's monthly Best Raspberry Pi Projects feature - always worth a read. Pico W projects a-plenty I had to dig out an extra USB hub to drive all the projects I showed! Missed it? Don't worry! You can watch a recording on YouTube :

Connect the Raspberry Pi Pico to an OLED using Grove breakouts

Image
In this short article you'll learn how to make and use a compact, inexpensive adapter that will allow you to connect a Raspberry Pi Pico/PicoW to Grove I2C peripherals. With a Grove to Stemma QT/Kwiic adapter cable, you can also connect your Pico/PicoW to Adafruit and Sparkfun I2C devices. You'll laso learn a useful hack that lets you connect the 2mm spaced Grove adapters to a 0.1" spaced (2.54mm) pcb. Grow with Grove Regular readers will know I love breakout boards. One of the projects that I've been working on is a Raspberry Pi Locator. It reads updates from the @rpilocator RSS feed, and it tells you when and where Raspberry Pi stock is available. The Pico W will sound a buzzer when there's stock around, but it would be great if it could tell you which stores had the Pis. On OLED display would keep things compact, and I thought I'd hook one up. Seeed studios have a great range of Grove breakouts with an easy-to-use connection system, and I knew

Simple, repeatable deployments in a MicroPython environment

Have you ever suffered from "It works on my machine"? Most of us have, as users (well, it doesn't work on mine!") or as developers ("what have I done wrong this time?".  The cause is almost always down to something that's on the developer's machine that they have forgotten about, but make use of. That something doesn't get included in the installation process, so users may not have it installed. There's a great way to avoid that. Testing an installation process if you have an OS If the software you're developing runs under an Operating System, run the installation in a freshly-created virtual machine. That will ensure that you start without  somethings installed. You'll only have the software that's specified in your installation process. If that works, you're in good shape. What about installing MicroPython software on devices like the Raspberry Pi Pico? Testing an installation process for MicroPython projects A comparabl

Seven secrets of the Raspberry Pi Pico's success

Image
The Pi Pico sold well; the Pico W has sold out several times since its launch. With two million units planned for production this year, the Pico shortage will be temporary, but it's a sign that the new Pico W is going to repeat the amazing success of the original Raspberry Pi. Pico W Why is it selling so well? What's the secret? Yesterday I jointed a group of friendly and knowledgeable enthusiasts for  an online meeting of the Melbourne MicroPython Meetup . It's not just a user group. Damien George gave a talk about the Rapsberry Pi Pico W. Damien is the creator of MicroPython, and he was responsible for the MicroPython port with Wifi support. The software was available on the day that the Pico W launched. In the discussion that followed, several of us speculated about the secret sauce that made the Pico/Pico W so successful. We concluded that there was no single factor, but that several features combined to make them so attractive. Seven key features What helped to catap

Make your own strip-board breakout boards

Image
A useful trick for Makers In this article you'll see when you should build your own breakout boards, and you'll learn a useful trick to use when making them. Breakout boards rock Digital Makers can often make projects faster by using breakout boards. A breakout board is a small but useful module that you can use to compose your project. There are hundreds of breakout boards available. Many are based on tiny SMD chips that are tricky to solder. You can save time and reduce the risk of mistakes by buying a ready-made breakout board. Here's an Adafruit breakout board I used in the Raspberry Pi version of Lazydoro. Of course, you can only buy a ready-made board if you can find one that does what you need, If there isn't, consider making one! Why bother with self-built breakouts? Why not just put everything you need on the main project board? There are advantages to a design that uses pluggable modules. You can usually test the module on its own, and th

Ports and Adapters - Struggling back to Beginner's Mind

Image
I have to admit it: I've been struggling over the last two days.  I'm working on a write-up of a Walking Skeleton for Lazydoro, together with sample code for its Ports and Adapters architecture. I often create a Walking Skeleton at the start of an application. Lazydoro is now in its fifth version,  there's already a finished working version, and it's difficult to 'un-know' how it evolved. Trying to create what I might have written at the start has been quite a challenge The process has been valuable, though. I think I understand  Ports and Adapters  better through working on my sample code and explanation, and it's had another benefit. I've set up an automated deployment process which I'll be able to use for future MicroPython projects. Automating deployment Some applications can be deployed as a single file, but small modules are easier to read and test. lazydoro now consists of 9 files in a three-directory tree, and deploying a new version manua

Raspberry Pi Pico W project plans

Image
Please help me choose! The announcement of the Raspberry Pi Pico W has opened up a huge range of fun, exciting projects. Pico W in the cloud I've a long list of candidates, and I'm hoping for advice about which ones have the widest appeal. The first project is a shoo-in, not least because it's almost finished. I'll tell you about that shortly. I have seven other projects pulling for my attention, and I'll give you a quick introduction to each. Then I hope you can help me chose which to do next, or even suggest an alternative. I'll open up polls on Twitter and Facebook, but I'd also welcome feedback on this blog. Project number One If you're a regular reader of the RAREblog you will already be familiar with Lazydoro, my automated Pomodoro timer. The current version is now running well, but it's based on a Raspberry Pi Zero. I'm migrating the project to the Pico W for two reasons: I want to keep a daily log of my Pomodoros,

Lazydoro is working again!

Image
Yesterday things looked tricky. I realised this morning that I could easily fix the problem I've been having with lazydoro and my new chair. Doh! All it took was an adjustment to the distance threshold. Lazydoro is now sitting by my keyboard and keeping a watchful eye on me. lazydoro back at work Next steps: keep a log of Pomodoros completed/broken.

Lazydoro Mk 3 - lots of automated tests for a simple design

Image
At the end of  yesterday's post lazydoro was running on a Pi zero still not working reliably. In November 2021 I worked on Ness Labs ' Write a book in 30 days challenge. I had to rely on a web-based Pomorodo timer, and thought I'd have another try at the lazydoro project. I decided to rewrite lazydoro from scratch. Lazydoro needs to do four things. It needs to know when I arrive at or leave my desk It needs to keep track of passing time It needs to know where I am in a Pomodoro cycle It needs to provide feedback to keep me on track. To make lazydoro easy to test I used a variant of the Ports and Adapters architecture. (Ports and Adapters is sometimes called Hexagonal Architecture). I first came across it in an article by Alistair Cockburn , and it made a lot of sense. It's also featured in the GOOS book: Growing Object Oriented Software Guided by Tests . Simple architecture Here's the architecture for lazydoro: At the centre is the applicat

Lazydoro migrates to the Pi

Image
In the previous blog post I described cushadoro and its successor, lazydoro Mk 1. That was the first version of lazydoro, implementedin CircuitPython and based on the Adafruit Trinket M0. Today I'll describe the next stage of the project, a Raspberry Pi-based version. I made real progress but, as you'll see, lazydoro was still not quite good enough. Lazydoro needed unit tests At the point were we left the project the Python code had become a little complicated. I thought I ought to do more automated testing. It's possible to do that on CircuitMpython devices like the Trinket M0, but it's a lot easier if you canuse the standard Python libraries, including Python's unittest and mock frameworks. I decided to migrate the project to a Raspberry Pi. Moving to the Raspberry Pi Explorer HAT prototype At the time I migrated the project I had just fallen in love with Pimoroni's brilliant Explorer HAT pro . The HAT has loads of useful peripherals, an

The Lazydoro story - Part 1

Image
The Lazydoro Lazydoro is potentially the most useful project I've built. I use the Pomodoro method when I am writing or coding. It keeps me focused, and makes it easy for me to maintain progress. The Pomodoro technique involves working for 25 minutes without interruption, followed by a 5-minute break away from your desk. It helps with productivity, and it's good for your health. There's just one problem. You need to remember to start a Pomodoro timer! Using a timer When I first started using the technique I tried using a web-based app to keep track of time. Sometimes I remembered to use it, but sometimes I forgot. If I was deeply absorbed in what I was doing I lost track of time and failed to take my break. After a few days of that my mood and my knees suffered! I tried building some hardware to make the Pomodoro technique easier to use. Cushadoro Cushadoro I started the project back in 2015. I called that version  cushardoro - an Adafruit trinket a

Technologists: one thing you must know if you use logseq with GitHub

Image
Like many technologists, I use Personal Management Tools to manage information overload. I've been using technology to help me keep track of complex technical material since the 1980s. These days, my favourite tool is logseq . You can use logseq to capture, connect and create technical information. Over the last couple of years I've built up a large, heavily linked knowledge graph - a second brain filled with information and ideas. It's worked well for me but this week I hit a pitfall. Using logseq with GitHub If you use logseq as your PKM system you may be using GitHub to back up and version your knowledge graphs. Logseq has great GitHub integration. Because of that, many users have adopted GitHub as a way of making sure their second brain is secure and easy to access from anywhere they want. If you are using logseq with GitHub, beware - there's a potential pitfall lurking! A trap to avoid Logseq has great support for PDFs and mp4 videos. You c

Three strategies to manage Technology Overload

Image
If you're reading this you're probably a knowledge worker . Your value lies in the knowledge at your disposal and your ability to apply it. There are daily advances in every field of technology, and you are subjected to a flood of new knowledge competing for your attention. It's easy to feel overwhelmed. In this article, you'll read a brief introduction to the flood of information overload and its causes. see three strategies you can use to cope with that flood. see how to avoid getting overwhelmed by the range of tools - otherwise the cure will be worse than the disease! But first - what's the problem? What's the problem? The Explosion of Information Edholm's Law states that Internet traffic now follows the same pace of growth as Moore's Law. That poses a huge problem for knowledge workers. Here's a picture of the problem: The knowledge gap If that worries you, you're not alone. Professor Eddie Obeng explores the Kno

APL and Python go head-to-head

Markdown is great, but... I've encountered a problem. I use Markdown a lot. Since it's pure text-based markup, it's handled well by Git and GitHub. That helps me keep track of versions, and it simplifies text merges if I'm collaborating on a writing project. A lot of my writing features Python code, and I like to work on the code and the article in the same editor. Fortunately there's great support for editing and displaying Markdown in both PyCharm and VS Code . Markdown is supported by lots of FOSS tools which make it easy to convert between Markdown and other formats. I regularly use pandoc to turn Markdown in to pdfs and to publish on Leanpub , and I use the markdown package to convert Markdown files into HTML which I can paste into Blogger. (Pandoc can create HTML but the output is not directly usable in Blogger.) So I have a problem. Much of markdown is standardised but the pandoc and markdown programs handle code blocks differently.

Let the computer test your Python GUI application

Image
Let the computer test your Python GUI application In this article you’ll see how easy it is to write automated tests for Graphical User Interfaces (GUIs) written using the brilliant guizero Python library. I’ll start with a horror story which explains why I’m so keen on automated GUI tests. Next I’ll describe an application that I’m using as an example. The code for the app and the test are available on GitHub; the link is in the resources section at the end of this post. After that, I’ll show how the tests are built up and describe how they enabled me to find and fix a bug. A personal horror story A couple of years ago I presented a Quiz Runner application to an audience of Digital Makers. The Quiz Runner application used a workstation to manage the Quiz. Quiz Contestants used micro:bits to ‘buzz’ in when they thought they knew an answer. The micro:bits communicated via radio using the micro:bit’s built-in radio capability, and everything (workstation and micro:bits) was pro