Smart Poi

Upgrading DigitalOcean Ubuntu Droplet from 20.04 to 22.04

The problem

Recently I found out that PHP 7.4 is going to reach End Of Life at the end of November, 2022. This was an unfortunate situation considering I have several websites running on a couple of Ubuntu Server 20.04 DigitalOcean Droplets. It’s unfortunate because I found out that the only supported version of PHP for Ubuntu Server 20.04 is the soon to be obsolete version 7.4.

The Solution

There are two ways to do this – upgrade PHP via a PPA on Ubuntu 20.04, or upgrade Ubuntu to 22.04. I already upgraded my desktop without any issues, so I went with the latter option.

I will outline the procedure I used below. It went without a hitch, apart from having to do it twice due to a broken WordPress plug-in. I am embarrassed to admit that the plug-in was my own creation (in my defense I am not a PHP developer)

  1. Check all WordPress plug-ins for compatibility with PHP 8.1
  2. Create a snapshot of the Droplet
  3. Use the snapshot to create a new Droplet with the same specs as the old one.
  4. Power on the new server, login and proceed to upgrade to 22.04. I used screen to keep the upgrade process alive in case of ssh dropout.
  5. Once this process is completed, you still need to switch the version of PHP that Apache is using (I’m not sure if this is necessary for Nginx). It was something like:
    sudo a2dismod php7.4
    sudo a2enmod php8.1
    sudo service apache2 restart
  6. In the control panel, switch over your website’s DNS to point to the new domain. Depending on TTL this can take a while to propagate – I did mine one at a time and checked them with the ping command.
    ping circusscientist.com – returns the IP address
  7. If anything went wrong, it’s easy to switch back to the old 20.04, so I left that running for a few days. Worpress.org has some great articles here and here which I sometimes use to help with troubleshooting
  8. Finally, switch off the old 20.04 server and remember to delete it (keep the snapshot, though, just in case!)

Using maps and geocoding to follow the money

I do shows all over Durban and surrounds – but where exactly? And which areas are the most lucrative? To work that out I made an interactive Desktop app using Processing and the Modest Maps library. To get the points on the map I used Google Geocoding api.

Map details page

How it works

The process is quite simple, I create a csv file from our records, with the customer address and total invoice amount in columns (as well as blank latitude and longitude columns).

I created a start screen to choose which csv to use for the visualisation, with an option to fill in the locations using Google geocoding* api.

*geocoding is taking an address and turning it into location co-ordinates.

Menu page

Once the geocoding is done, there are two options, map or details. The details page is basically the same but the points are larger or smaller depending on the amount.

Google geocoding is not completely accurate, so there is a bit of csv editing still to be done – some addresses may appear in different countries for example. Luckily fixing this manually is quite straightforward, you just find the correct location on google maps and then copy the “lat” and “lon” parts of the url from the browser address bar (just after the @ symbol).

The “Modest Maps” library for Processing has many options for tiling – I switched to the satellite view for the screenshots above, to avoid giving away sensitive information. Usually I use a street map view of course.

Purpose and functionality

The purpose of this app is mainly to see where all of our customers are booking us. This information is useful for marketing. When the program is running, two boxes can be drawn around areas on the map, and the text at the bottom compares the total invoice amount within those boxes. The map can be zoomed and panned, and a total for the whole page (with percentage) is shown for reference.

Comparing two zones

More possibilities

Since the pandemic is effectively over and we are back to full strength in terms of bookings, these statistics are now valuable again for my entertainment business. I plan on extending this simple app with more statistical visualisations – perhaps a colour map of distance from my house, and also pairing it with a database and more fields, like dates and type of booking. I could also automate the data entry, although that is rather trivial with a bit of spreadsheet manipulation, and I only really look at this a few times per year.

Speech to Text is finally ready – Whisper review.

Many years ago I developed and published an Android app called “Made Up Stories” which I used to record the bedtime stories I told to my young son. Many of the stories were sanitized versions of movies and novels, but I also had a lot of fun creating my own characters and plots on the fly. Years later, I have a collection of over 300 stories saved, and I started to think that it would be nice to turn some of the original ones into illustrated children’s books – but the time it would take to transcribe these audio files was daunting. I am a reasonably fast typist, but not quite up to the speed of spoken word.

Transcription software

In 2019/2020 I decided to try out transcription software, so I fed a sample audio file into Mozilla Deep Speech and Google Speech to Text, among others. Unfortunately, due to my South African accent, none of the transcribers I tried had any accuracy, and I shelved the idea. Literally every second word was incorrect. Also, Deep Speech required a very specific audio sample rate, and Google Speech to text isn’t free (I had a free trial). *they may have improved by now, I didn’t check.

Discovering Whisper

Last week I saw an article on The Verge, which was singing the praises of “Whisper“, the new open source transcription engine. It was incredibly easy to set up, and best of all, ran entirely on my laptop, for free. After installation it is a simple one-liner on the command line to get your audio file into text format. Best of all, the thing is really accurate – I read in their paper that the model was trained on a more diverse range of speech, and uses a different approach to others. Well, for me at least, it works!

There is still a lot to do with the transcriptions, which come out as one long line of text – with barely any punctuation.. And don’t get me wrong, there are still some errors (admittedly I was using the “tiny” model – only 350mb, the “Large” model is apparently even more accurate but takes up 5-6GB of space.)

Finishing touches

Well, I have cleaned up the first story, “Pinky the Amazon river dolphin visits the Mesozoic”. My wife is an amazing artist, and has agreed to illustrate, but I wonder, could AI help with that as well?

Dinosaurs on an ancient river bank – Craiyon generator
Underwater cave – Stable Diffusion

Maybe not.. (The dolphin images that I have managed to generate so far have only succeeded in making me feel ill.) I have signed up for “Midjourney” (which is DOWN at the time of writing). Apparently it is the best of the bunch – so who knows, maybe I can automate some backgrounds to save time illustrating the stories.

*Update: I signed up for DALL-E 2.

DALL-E 2 “Dinosaurs on an ancient river bank”
DALL-E 2 “Underwater cave scene”

I’m definitely going to do a more in-depth comparison of all of these image generators in future!

Smart Poi revisited

Magic Poi, with the firmware written in Platform.io and the web interface in Flask is the future. Currently I don’t have a working set*, though, and due to upcoming shows I needed to make some changes to the existing Smart Poi.

*Due to other commitments, the company who are doing the hardware design for me have put the build on hold for now.

Updates:

LiPO batteries instead of NIMH

I have resisted using LiPO batteries for my projects up until now, but since I was already getting some for my K8 equipment upgrade I bought some 1000MAH LiPO batteries for the 32px poi. The voltage regulator I have in the circuit (LM117) is not optimal for these, I believe that it is not using the batteries full capacity – but it does work!

Quick uploading of offline patterns

At the time I wrote much of the Android app which pairs with Smart Poi (in 2017!), I was set on having all of the patterns stream from the smartphone to the poi over WiFi. In the real world unfortunately I found that due to WiFi interference this was not possible at most venues, where the 2.4GHZ spectrum is saturated and the stream stutters. So I made a way to upload and display patterns directly from the ESP8266 flash. Initially this was done with UDP as the streaming was taking place, then I moved over to http post. The latest update to the app disables UDP while the post is being sent, so uploads are really fast. I hope to refine this and port to the 72px version as well in the near future. You can get the apk for the latest version (so far only tested on Android 10) here – any future updates will be made to the same file. *Please note that the text message option still crashes, I am looking at this as a matter of urgency! Also, on first run the app sets up some example images and may need a restart (possibly even a phone reboot) to work correctly.

Magic Poi Lite version

I am working on a ‘lite’ single colour version of “Magic Poi”. The plan is to eventually replace all of my juggling equipment with internet enabled equipment which can sync using a web interface, like “Magic Poi”. The first test page is up here: http://magicpoi.circusscientist.com/lite and includes a colour change function and a really cool “Automatic Poi Simulator” visualisation which was kindly shared with me by Danny Thomas from kaien.com. Eventually this page will have a timeline (to music) function, and ability to download to the equipment. The firmware will also include offline capability, which will disable the WiFi to save power during operation.

Many thanks to all those who continue to support this project. Smart Poi continue be a part of my performance every week. I’m inspired by the thought of enabling more people to make reasonably priced POV poi and other LED equipment which can do as much as, or more than the commercial versions.

As always, if you haven’t already, head on over to the Smart Poi Overview page and sign up to the newsletter for occasional progress updates. Feedback is welcome.

PS: did you know that every time someone visits my website, an LED flashes on my desk? I made an online service and open source firmware for the D1 mini which means that almost anyone with a website can have the same functionality. Check out https://www.circusscientist.com/led-website-indicator/ if you are interested!

Emulating Poi Spinning patterns in software

Several years ago I read an amazing scientific paper on the mathematics of Poi patterns, by DrexFactor – you can have a look at the web version here.

So recently I was thinking about it again and managed to plug some of the formulas into a Processing sketch:

Poi spinning emulation – first attempt.

I have always enjoyed emulation software for juggling, it’s amazing what you can do – juggle 100 flaming swords for example (or make an LED juggling emulator, like this one I made) Anyway, it turns out that there isn’t anything similar for poi spinning.*

Seems like there should be one.

*UPDATE: turns out there are quite a few. Thanks Reddit! Here is one of my favourites, done in Processing: http://www.kaiein.com/poi_auto_sim/

**UPDATE 2: Danny Thomas from kaien.com kindly let me use the code for my own emulator – I’m using this as the base for a new single colour version of “Magic Poi”, “Magic Poi Basic”. See the demo here: http://magicpoi.circusscientist.com/basic

Upgrading K8 IR RGB Clubs

I love K8. Their reasonably priced LED equipment is the basis for my favourite solo juggling act, the “Electric Glow Juggling Show”. I bought my K8 clubs over 7 years ago, and last month they finally died.

Emergency!

Since the pandemic finished (or at least since we all learned to live with it) I have never been busier. People want to book my shows. Luckily, a friend has some working K8’s I can borrow for now, but long term I need to sort this out. I’m not changing manufacturer so the choice is to either purchase a new set or fix the ones I have. The pandemic also had the effect of limiting my finances for the past two years, so new purchases are on hold for now – so I opened up my K8’s to see what can be done.

Inside the K8 clubs and balls

First impression: these things are well put together. It took me the better part of an hour to get the electronics out without destroying the club in the process. I found the problem: a really fat lithium battery, completely finished.

Then I found something really interesting. The actual circuit is pretty straightforward and is running on a replaceable Attiny chip. So a few years ago I made some code for Arduino which was an attempt to emulate the K8 IR RGB internal workings. With a few adjustments this old code actually works inside of my favourite clubs – it was as simple as matching the alignment and dropping in my own chip. Thank you K8 for not soldering your chips on, and using a header instead!

The plan

First priority is to get the replacement batteries – I ordered these ones on Amazon: the same size as the original but bigger (>2x) capacity. Should be great if they work!

In the meantime I am working on the code, with upgrades such as variable strobe (like Aerotech equipment), and timed record and playback of settings for my show*.

*I understand that K8 have implemented a method of record and playback functionality in their latest equipment, as well as more new settings – if you need LED equipment I highly recommend going there and getting some. Also, their customer service is brilliant. https://k8malabares.com/

Here is a sneak preview of a new setting running on the bare circuit – Red/Blue with variable strobe!

If anyone is interested, the code is up on Github here – most of it is from many years ago and not very good, but I am working on it, need to have everything working without bugs by the time I receive the batteries. After I upgrade I don’t want to have to open the clubs again! When I get everything working I will do an “instructables” style tutorial – even if you aren’t interested in the firmware upgrade, the battery replacement is worth doing to extend the life of this amazing equipment. By the way, one of my K8 balls stopped working ages ago – I just opened it up and the battery is replaceable too!!

The Circus Scientist Show

In my day job I often do circus shows at schools, for fun days and end of year events. Having had this experience over many years, I am proud to introduce a new school show focusing on technology.

The Concept:

This is a motivational show aimed at school kids. The purpose of the show is to showcase some amazing tech with the goal of inspiring children to consider a career in technology.

Topics:

Fun with electronics and programming, featuring WiFi controlled LED’s, a full-screen projector display and interactive audience participation.

Technologies:

I plan to demonstrate the Raspberry Pi (with Scratch and Processing), Makey Makey (Banana piano and some of my own creations) and some Android apps for WiFi control, as well as Arduino programmed electronics projects.

It’s becoming easier to be a programmer but at the same time there is so much choice – I will be showcasing some of the most accessible learning technologies I have found in a fun, interactive way, via a live stage show.

Check out http://show.circusscientist.com *concept website, under development. The actual content, duration and pricing is subject to change. ETA early 2023.

K8 Virtual Juggling with working remote

K8 are my favourite type of LED juggling equipment. Recently I updated my virtual juggling web app to include a working remote control – just like the real thing.

The App

So the app consists of an animated juggler, a remote control and “Change your pattern” button.

While the juggler is juggling, you can press buttons on the remote to change the juggling ball colours (accurately emulating the actual K8 equipment settings)

The “Change your pattern” menu is a large list of different juggling patterns, which when selected will change the animation displayed.

How it works: back end

The back end is based on Flask. I am using the beautiful soup library to fetch the menu of juggling patterns from the awesome library of juggling website. Once selected, the gif of the pattern is fetched. It is then processed (a script inverts the colours and makes the juggling balls transparent) – if that hasn’t already been done for the particular pattern.

How it works: front end

The juggling animation and remote control are written with P5.js. The juggling ball colours are implemented as a background which shows through the transparent balls. The button co-ordinates are relative, so work on any size screen (looks best on Desktop)

Magic Poi 2022 update

Current state of Magic Poi – and some ideas for the future.

First of all, an announcement: Magic Poi is now available for ESP32, as well as ESP8266 architecture. This will bring improvements in performance. I plan on continuing support for both, and in the near future a combined code base will be provided.

I am going to list current features here, and improvements I plan to implement.

On-board images:

  • I have partnered with EnterAction, an awesome Sydney based fabrication company who are taking over the hardware development from now on. Improvements will include an SD card add-on for limitless on-board storage. This will require changes to the code, as currently the maximum is 52 images supported.

UDP streaming:

  • this is a defining feature of Magic Poi. The images are generated off-device, and “streamed” via UDP pixel by pixel. I plan to keep improving this functionality but change it to not be the default mode. Due to WiFi interference the UDP stream is sometimes interrupted, making the LED’s stutter, so work is being done to mitigate that.

“Timeline” – images changing in time to music:

  • currently there is a desktop app to generate the timeline (and associated images) and save as a zip file, which needs to be uploaded to the Android app in order to be “streamed” to the poi. I plan on changing this functionality to rather happen in the poi code, thus avoiding the WiFi interference problem. The timeline editor will be made into a web app, with the option to download directly to the poi.

Station mode:

  • poi connected to a router provides more stable WiFi than the current AP mode. I have made a start on providing a way to use this mode.

Online account:

  • like a PlayStation or Kindle, there is a benefit to having a cloud aspect to any product that consumes media. The Magic Poi website is going to be a place where you can upload and share images and timelines, as well as interact with other poi owners. All uploaded images will be private of course, unless shared. I have made a start on this cloud aspect, with an option in testing to download images directly from your cloud account to the poi. The ultimate goal is to be able to sync any two pairs of poi with two clicks!

Android app:

  • Still not working: text to image (stream words directly to the poi).
  • Once the online portal is finished, this will be added to the app, so shared images and timelines can be viewed without need for a web browser.

The above is a small part of the list – thanks to EnterAction taking over the hardware development side, I will have more time to devote to the software improvements. We also plan on adding a battery level indicator, and a higher power battery for more play time.

Thanks for reading!

Keep an eye on this blog, and sign up to the newsletter (if you haven’t already) for more updates as Magic Poi moves forward towards it’s inevitable crowd funder launch!

UPDATES:

Sign up for our update alerts:

Unpacking an inverted index with Python

Lately I have been doing a lot of data processing in my job for UCL. I recently came across a problem which didn’t have a ready made solution, so here is my take on it.

Inverted Index

An inverted index is simply a list of all the unique words in a document, labeled by their position. Something like {‘Hello’: [1], ‘world.’: [2]}. Except that they are rarely in order and there can be multiple instances of any given word in a document.

I was given the task of ‘unpacking’ one of these (actually thousands, but if you can do one..). The inverted index came in the form of a dictionary of words and their positions, returned from an api call. Since I couldn’t find a ready made solution, here is my take on it, in Python 3.

The solution

You can try it out with the included example. I hope this helps someone with a similar problem to solve – do let me know in the comments if you have a different solution.