Making the RedBoard Work on the Raspberry Pi 5

I’ve been using Red Robotics excellent RedBoard for years now, and while upgrading NE-Five to use a Raspberry Pi 5 I discovered breaking changes which means the available libraries wont work.

Basically, the way that GPIO works on the Raspberry Pi 5 is different as it uses its shiny new RP1 chip to wrangle its devices. As such, legacy code that used the old way needs updating. In our case that’s pigpiod, and the develop has said it’s non-trivial and will take time. This is entirely reasonable, it’s an open source project and depends on the good will and free time of the developer.

I’ve been using Approximate Engineering’s RedBoard library which abstracts a lot of the underlying bits away, so I thought I’d take a stab at updating it to use gpiozero instead. I’ve managed to get enough features working for NE-Five, the rest I will revisit when I’ve recovered a few spoons from the effort…

Long story short, you need to specify the pin factory for gpiozero to work in a virtual environment, and for whatever reason lgpio doesn’t work if you install it in a venv from pip. Instead, you need to install it from source, ignoring their instructions… This took an awful lot of trial and error to figure out, hence the spoon defecit.

If you go to my fork, there are instructions on installing everything which hopefully will get you working. Just make sure you’re on the develop branch!

Using The RedBoard+ From Within a Docker Container…

…because why do anything the easy way?

I’ve switched to using the StereoPi image for MacFeegle Prime as it offers the lowest latency for streaming video, the downside is I can’t get ROS to build on it so I’m using Docker which needs to interface with hardware…

I’m using the RedBoard+ by Red Robotics, it uses the pigpio library which can work over a socket or pipe. I’m trying to figure out how to have the pigpio deamon running on the Pi host and access it from a docker container that’s running ROS.

Security Note Of Doom!

The following changes have security implications, only do this if you’re running on a private, trusted network. I don’t really know what I’m doing so assume the worst and double check everything I suggest!

Things To Tweak

Upon some digging, this wasn’t as evil as I thought it would be. For pigpiod you need to change the service definition to remove the “-l” from the start command:

sudo nano /lib/systemd/system/pigpiod.service

Remove the “-l” from the ExecStart line.

This is needed as by default pigpiod runs in localhost mode which means that it’ll only accept connections from the local machine. When connecting from inside of a docker container, it’s considered another host.

In order for the docker container to access the hardware it’ll need to have privileged status, add this to the command when you create your container. Eg:

docker run --priviledged -d ros 

From inside the docker container, and in the same shell instance you’re running the code that calls the RedBoard library, you need to run this:

export PIGPIO_ADDR=[PI IP ADDRESS]

This sets the address used by the pigpio library that RedBoard uses to the host machine.

Conclusion

After doing the above I was able to use the RedBoard keyboard_control.py script to control the robot from inside a docker container. I’ve not tried anything further yet but that proved the concept enough for today!

Raspberry Pi – Docker on USB Drive

As per my last post I’m using Docker on my robot with ROS. The last task is to get docker running from a dedicated USB drive to split resources between that and the SD card the OS is running from. A good guide to mounting a USB drive can be found here.

Note, rather than using umask=000 for mounting you need to mount, then change the permissions of the “host” directory to 777. For example, mount to /media/usb as per the article then chmod 777 /media/usb **WHILE MOUNTED**. This should allow you to mount, then set to automount on boot.

If you are running headless and there is a problem with the fstab file it can get annoying so to test in advance of a reboot run “sudo mount -a” to mount all volumes as per that file. If it succeeds, you can reboot.

I was having a problem mounting with fstab, I could manually mount the usb folder every time but not using “mount -a”. The penny dropped when I did “df -h” to see how much space was free and noticed /media was itself a mount point. I created a new root folder called “docker” and it worked a treat.

Following this answer I moved the location of the docker containers and such to /docker.

I’ve run “docker pull ros” and it’s now happily using the usb drive instead of the SD card. 🙂

StereoPi Image Mods

I’ve been using the Ubiquity Robotics Raspberry Pi ROS image to run both the robot and controller, it seemed the easiest way to get ROS running, but now I’m trying to get low latency streaming working from the cameras it is proving tricky.

New Plan, use the Stereo Pi image with Docker to host ROS images/containers.

Some Mods Needed…

In order to lower the latency as much as possible the Stereo Pi image is a heavily modified version of Raspbian, this includes custom partitions and the file system set to read only. Here are the steps I followed to get it to a state where I can restart development.

1. Get and Modify the Image

Head here and follow the steps to get and install the image, follow the steps to get it on the wifi and under the Advanced section you’ll see details on how to SSH to the Pi afterwards. Once logged in you’ll need to temporarily set the file system to read/write then edit the fstab file.

Under the “SLP Structure Details” section you’ll find this command:

 sudo mount -o rw,remount /   

This will set the file system to read/write, at which point you can open the fstab and edit it to make this permanent by changing the ro to rw for the root.

nano /etc/fstab

2. Resize the Partitions

I was trying to figure out how to do this on Windows then realised I could just install gparted on the controller and remote to it… I put the micro-sd card in a USB card reader and followed these instructions. The 1.8G root partition was expanded to around 25GB and the recording drive slimmed down accordingly.

screenshot of gparted with the final sizes of the partitions

3. Install Docker

This next bit is trivial, run this command, as taken from the Raspberry Pi blog:

 curl -sSL https://get.docker.com | sh 

4. Get ROS Images

Next bit is easy too:

 docker pull ros

Considerations

One of the reasons StereoPi is very quick is because it is tailored not to use the filesystem on the SD card, to that end it may be worth moving all of the docker containers and images over to a USB drive. There’s more information on how to do that here but I’ve not tried it yet:

https://stackoverflow.com/questions/32070113/how-do-i-change-the-default-docker-container-location

Next Steps

The next things I need to do is convert my code to work in a docker container, this shouldn’t be too tricky but as the RedBoard library will need to talk to the hardware there will likely be complications.

Docker, A Reverse Proxy, This Site and LetsEncrypt!

The site was migrated to SSDNodes last year as my previous host was becoming less reliable and I fancied something more versatile.  I’ve not covered it on here but here is how my site runs, now with added HTTPS thanks to LetsEncrypt!

A bit of history.  This is a WordPress site and has been since it was migrated from Windows Live Spaces which shows it’s age!  There is an official Docker container available so I thought I’d give that a go.  I may want to host more than one site on the same virtual server at some point so looked in to my options for a reverse proxy and jwilder had the perfect solution it turned out.  Building on an example I found I managed to get the site going behind the proxy but wanted to secure it.  Unsurprisingly this problem had already been solved too…

Follows are my Docker Compose files that work a treat, as much as examples for others as to help me in the future if I need to set up a new site or rebuild this one if something goes wrong.  When the container for the site is fired up for the first time it creates, and maintains, a Lets Encrypt certificate automatically.  Neat!

One thing for VaultPress users to be aware of is that you’ll need to follow the steps here under the reverse proxy section otherwise the service won’t be able to connect to your site to back it up.

If I need to host a new site, I just need to create a new site definition file and it should sort itself out.  Please note, the formatting may be screwy if you copy and paste these so you may need to manually tweak them.

neave-eng.yml

version: '2'

services:

neaveeng:
 depends_on:
 - mariadb
 image: wordpress
 links:
 - mariadb:mysql
 environment:
 WORDPRESS_DB_PASSWORD: [YOURDBPASSWORDHERE]
 WORDPRESS_DB_NAME: wp_neaveeng
 APACHE_RUN_USER: wp-neaveeng
 APACHE_RUN_GROUP: wp-neaveeng
 VIRTUAL_HOST: neave.engineering
 LETSENCRYPT_HOST: neave.engineering
 LETSENCRYPT_EMAIL: my.email@domain.com
 volumes:
 - ./neaveeng/code:/code
 - ./neaveeng/html:/var/www/html
 - /etc/passwd:/etc/passwd:ro
 - /etc/group:/etc/group:ro
 restart: always

mariadb:
 image: mariadb
 environment:
 MYSQL_ROOT_PASSWORD: [YOURDBPASSWORDHERE]
 MYSQL_DATABASE: wp_neaveeng
 volumes:
 - ./neaveeng/database:/var/lib/mysql
 restart: always

proxy.yml

version: '2'

services:
 nginx-proxy:
 image: jwilder/nginx-proxy
 ports:
 - "80:80"
 - "443:443"
 volumes:
 - /var/run/docker.sock:/tmp/docker.sock:ro
 - "/etc/nginx/vhost.d"
 - "/usr/share/nginx/html"
 - "/etc/nginx/certs"
 restart: always

letsencrypt-nginx-proxy-companion:
 image: jrcs/letsencrypt-nginx-proxy-companion
 volumes:
 - "/var/run/docker.sock:/var/run/docker.sock:ro"
 volumes_from:
 - "nginx-proxy"

whoami:
 image: jwilder/whoami
 environment:
 - VIRTUAL_HOST=whoami.local
 restart: always

Nerf Gun Shooting Gallery

This is a work in progress as it has turned out to be far more complicated than I thought it would be! I’ve learned a lot about how to design parts for my 3d printer and how to use the laser cutter at Reading Hackspace too though so already winning!

Over the passed few years my friends in the Reading Beer Festival Games Team have been talking about building a shooting gallery using Nerf guns to keep things nice and safe.  This year I offered to give it a go and the spec quickly escalated/became more fun!

As I’m building this more for the team than the players it needs to be easy for them to use while dealing with the festival punters who are typically moderately inebriated…  Resetting the board easily, keeping track of the score and setting up for the next game seems like the three things to concentrate on.

The game works, or will work, as follows:

  1. Press the start button, the counter should reset along with the targets
  2. Give the player a Nerf gun and a clip with 12 darts
  3. The player shoots the targets, which reset once hit, and the score is tallied

Having a bunch of clips that have 12 darts and a button that resets the game means resetting should be a lot easier than having to do it manually so that’s easy win, enter the Arduino!

I bought a bunch of hobby servos of eBay to use to reset the targets and designed a hinge with a magnet to hold up the target and a switch of some kind to track when a target is hit.

I’ve got a design working for the hinge but need to replicate it for all five targets.  More details once it’s complete but here’s an incredibly satisfying video of the mechanism in action!

Project Bumblebee

Bumblebee?

 

Bumblebee is my Roomba, so named as long ago he lost his voice.  About a year ago his logic board started playing up and though he was still able to clean, at the end of each cleaning cycle he wouldn’t go into standby and his battery would drain in no time.  At that point he stopped actively gathering dust and started doing it passively as he sat behind my sofa.

Bumblebeee MK2

Since a kid I’ve always wanted to build a robot and figured I’d kill two birds with one stone and use Bumblebee as a chassis for a mobile robot, he already is one after all, but also have the aim of returning his base functionality of being a robot hoover.

The Plan

Bumblebee is an original model Roomba from 2002, he was a gift from a friend who knew I loved to tinker and gave me him broken.  If I could fix him I could keep him, thankfully an easy fix as the battery was dead.  This model is very simple in it’s function and behaviour, it has no mapping capability, no dock or wireless control.  It apparently can be controlled using IR but I’ve never had a remote.  It also lacks the diagnostics port that the newer models have that make hacking a Roomba really easy now so this is going to be a bit trickier, a lot more education and most importantly more fun!

The parts I’ve used to partially resurrect him are a Arduino Leonardo and an Adafruit Motor Controller Shield.  I’ve also a Raspberry Pi 3 to add into the mix, for Wifi control and more processor intensive tasks.  The idea is to use the two to thier strengths; the Arduino will control the motors and read the sensors allowing for real time override in case of collision and the Pi will be able to sit back and give out the orders.  It’s a classic split for mobile robots but thankfully very cheap to implement now.

Current State

As I said I’ve been working on this for a while, I’ve a load of notes to type up and a loads of “learning experiences” to share.  Mostly when I made a rookie error and burnt out one of the motor controllers…  I’ve now got the motors under control over serial, I’ve also a simple console application that lets me drive him around and toggling the sweeper/vacuum fans on, here’s a video of him in action:

Next Steps

My next item to look at is getting sensor data into the Arduino, first up the encoders.  Encoders are devices that allow you to measure the movement of a wheel, you’ve likely used a rotary encoder on a hifi to control the volume, and the Roomba has one is each wheel.  Right now I can control how much power goes to each wheel but because of differences in the state of the gearboxes, carpet and who knows what other factors, the wheels spin at different speeds.  By measuring the speed from the encoders we can compensate for this, we can also use them to calculate the distance we’ve travelled.

After that is the rest of the sensors, those I’ve found so far are;

  1. Cliff sensors – these are under the bumper and detect drops to prevent him falling down stairs, I think there are four of them and they appear to be IR distance sensors
  2. Bumper sensors – these detect collisions, I think there is one at either end of the bumper so I’ll know if I’ve hit something to the left or right
  3. Wall sensor – another IR distance sensor mounted on the right of the bumper, this allows for wall following behaviour
  4. Wheel up/down switches – One on each of the drive wheels and one on the caster at the front.  They detect if the wheels are up or down and can be handy for detecting when we’ve beached ourselves.
  5. Wheel encoders – these were IR LEDs and a light dependant resistor.  I blew one of the LEDs by accident so replaced them both with red LEDs.
  6. Beacon IR Reicever – Not sure how this works yet, it’s a 360 lens on the top that receives a beam from the virtual wall, a device you place by your door to stop him escaping, I’m hoping to add more sensors to make this redundant.
  7. Buttons – there are three buttons for room size to start different cleaning cycles.  They could be useful though I may not bother with them.

Once I’ve all the sensors connected I’ll be able to hook up the Raspberry Pi to start working on reproducing his original behaviour.  After that I’ll be able to build up his capabilities over time and add a load of new ones too.  I’m not intending this just to be a hoover but a mobile robot platform that happens to be able to hoover.

If you’ve got this far, kudos!  That’s it for now, more posts will trickle out as i write up my old notes.  I’m going to carry on having fun building things and write posts in the order they happened.  Hopefully I’ll catch up fairly quickly!

Satellite Applications Catapult Inventorthon – Bring Your Own Disaster

Videowall – (Operations room) 18 1080p screens, eight dual monitor workstations

The Satellite Applications Catapult are very lucky to have the facilities they have and believe they have the potential to help save lives. To that end they’re opening their toy box for everyone to play with to try and do just that at their next hackathon. The premise is simple; in a disaster scenario, how would you use their facilities to best help those in need?

They have some data from the recent Nepal earthquake to work with but if you have a scenario of your own then feel free to being your ideas with you. Some of the ideas we’ve had are so far include;

  • Earthquake/natural disaster response
  • Coordination of people/aid
  • Search and rescue

They have a great range of kit at their disposal including;

  • Two videowalls, both with 24 cores, 256GB RAM and at least three NVidia Quadro K6000 graphics cards each. One has 28 720p monitors at 9562×3072 and the other a whopping 18 1080p monitors to a resolution of 11512×3240! These graphics cards have 12GB RAM and 3072 processing cores EACH!
  • An Oculus Rift DK1 – a virtual reality headset
  • Two Kinect 2 for Windows sensors – These are the new sensors based of the Xbox One design, each can track six people with full colour and depth support, they also have an excellent microphone array.
  • A Leap Motion sensor – this enables incredibly fine gesture tracking to help create more natural gesture based control systems.
  • Multiple large touchscreen devices – These include a number of electronic whiteboards with pen support and two four screen mini-video walls.
  • A Microsoft Surface Table – The SUR40, not to be confused with a tablet! This is a table PC that supports not only 50 simultaneous touches but also tag support, a great example of what it can do is NUIverse
  • A Microsoft Gadgeteer Kit – including loads of modules, this platform allows for rapid prototyping of hardware devices and includes GPS and GPRS (2g mobile data) support.
  • A van decked out with sat coms kit (I’m calling shotgun for the Zombie Apocalypse)
  • Raspberry Pi and Arduino devices – small microcontroller boards that can be programmed to perform functions without need of a full PC
  • 3D HD Dual Projection Facility – A large (5.5m x 1.9m) 3d HD projection system that can be used by up to 34 people simultaneously
  • Ovei Multimedia Pod – a multimedia pod that includes a surround sound system
  • AIS transceivers, a safety of life at sea transponder system
  • 3D screen
  • Parrot AR Drone – This can be controlled via wifi and has GPS and cameras on board
  • A transparent rear projected touchscreen

 

Satellite Applications Catapult, Harwell Campus

Dual 3D HD projector suite

Videowall (Saturn) – 28 720p screens.

 

 

The rest is up to you!

The event will be held at their office at Harwell Campus on September 12/13th, you are welcome to crash overnight too. To register for the event click here and add yourself to the group and event on Facebook to join the discussion!

Unity UI for DeskCycle Arduino Speedometer

[Updated, see end of article]

Since my last post I’ve improved the Arduino speedo code to respond to requests and also tweaked the gear ration to be a bit closer to my road bike.  I’ve also implemented a simple speedo interface using Unity.

Unity DeskCycle Speedometer
Unity DeskCycle Speedometer

The Unity application also automatically searches the COM ports on the machine until it finds the Arduino speedo, it’s a bit hacky but works and means I don’t have to implement a COM port selection UI.

I’m going to add functionality to save off the readings to CSV log files too, at a later date I’ll add some kind of analysis in but getting the data saved is the important thing for now.

Update:  CSV functionality has been added and I’ve tweaked the interface too.

DeskCycle Arduino Speedo
DeskCycle Arduino Speedo Interface

For the Arduino portion of this weekend long hack, see here.

All code for the Arduino and Unity project can be found here:
https://github.com/kneave/dcspeedo

Arduino Speedometer for the DeskCycle

All my previous jobs were based in the town I live in so I used to be able to cycle to work, with my current job it’s far enough away I can’t reasonably cycle to work.  As such, and as the company is jokingly referred to as the “Cake-apult” for the amount of cake we seem to go through, my weight has inevitably increased.  To try and remedy this I’ve recently purchased a DeskCycle.  I would like to give a walking desk a go at some point but this seems a far easier solution and as sitting down for extended periods is linked to many problems I figured it worth a go.

It arrived earlier this week and I managed to cycle while sat at my desk for over two hours each day, I felt knackered by the end of it so it was certainly having an effect!  The only issue for me is the speedo.  The creators of DeskCycle designed the device such that the speedo is accurate when the resistance is set to maximum, this results in the speed and calories calculated too high if you have the resistance set lower.  They provide a calorie calculator to provide a more accurate set of results once you’ve punched in the values your speedo provides.

On to the how;

Looking at the bike it looked like the speedo works in the same way to the speedo on my road bike, a switch is closed once per revolution of the flywheel.  I connected my multimeter to it in continuity tester mode and it confirmed my theory.  As the bike uses a 3.5mm headphone jack for a cable it was simple enough to make a cable to connect to the header on my Arduino.

DeskCycle/Arduino Speedo Cable
DeskCycle/Arduino Speedo Cable

The cable has a 3.5mm headphone jack at one end, tip and ground in use, and a pair of header pins at the other.  Connected to the Arduino via a bit of breadboard, I’ve connected using pin 7 in pullup mode with the other end of the switch connected to ground.

DeskCycle/Arduino Speedo Pinout
DeskCycle/Arduino Speedo Pinout

Once connected I’ve followed the timer tutorial provided by Amanda Ghassaei to calculate the RPM by counting the interval between revolutions.  One thing I learned is that the millis() function uses timer0 internally so if you want to use that function and a timer interrupt then use timer1 or timer2.

The code can be found on github in the dcspeedo repo.

DeskCycle/Arduino Speedo Debug Screenshot

Next up is a simple application that reads the RPM and calculates speed and distance to display it on my PC to start with.  I’m intending to add some cool functions like map integration to do virtual challenges such as Lands End to John O’Groats and similar which should be good for a laugh.

Also, this same code will be the basis of the digital speedo adapter for my Mini so two birds with one stone!  As practice for my Mini speedo, and more practice for stuff for work, I’m going to write it using C# and Unity 5.

Update:  The Unity part is done, more information here.