Notes »

Building a rover

This is a work in progress that I’m documenting as I build it.

Objectives

I would like to build a rover with some fun capabilities:

  • Remotely controlled from a PC.
    • May be using a gamepad!
  • If possible, it should have a camera.
    • Perhaps using a stepper motor to move it left/right.
  • It should be extensible (e.g. add self-driving capabilities, add sensors, a buzzer, etc).
  • It should be reasonably high level so my sons (6 and 8 years old) can help building it.

BOM

Component Cost (inc. shipping)
Raspberry Pi Zero W £19.79
MicroSD card Free*
DC motor driver (TB6612FNG) £3.29
Car chassis kit, wheels x2, DC engine x2, rotating wheel £8.61
Power brick / battery ?
PC Webcam Free*

* see notes.

Notes

MicroSD card

I had a 8GB SanDisk Ultra MicroSD –not sure if it was bought for Pi projects, but it works fine–.

Motors’ power

The vendor of the chassis didn’t spec the DC engines, so I should have bought a different one. Other vendors sell similar looking engines and they are all rated 3v to 12v DC, recommending from 6v to 8v for operation. These seem to work fine with the 5v coming from the Pi Zero W.

The chassis comes with a battery holder for 4 AA batteries –that’s 6v–, but it is too heavy.

Webcam

I had an old Trust WB-6250X lying around that is well supported by Linux –needs testing with the Pi–.

I tried motion but it doesn’t seem to support the webcam, so it is still unclear how are we going to get a video feed from the Pi.

Setup of the Pi Zero W

Using Alpine Linux disk-less because:

  • It is lightweight and easy to setup.
  • Disk-less performs great, although it means we can’t waste too much memory as the Zero W has only 512M of RAM.
  • I have used Alpine for years to deploy containers and I wanted to tinker with it a bit more.

Requirements

The Pi Zero will need at least two dongles / adaptors:

  • Micro USB to regular USB to plug a keyboard to do the setup; later will be needed for the PC Webcam.
  • Mini HDMI to HDMI to do the setup using a screen.

It must be possible to setup Alpine head-less, but I had these dongles when I bought my first Pi Zero some years ago.

The Pi can be powered from one of the USB ports of your PC, you don’t need a special PSU.

I used a regular 8GB MicroSD card with a MicroSD to SD adapter, and a USB card reader for my PC.

Setup notes

These steps require root (if using sudo, try sudo -i).

Check what is your SD device with:

# dmesg

Your system –like mine– may have an auto-mounting feature that could interfere. Once it has been mounted, unmount it with root:

# umount /media/USER/LABEL

Setup the partition:

# fdisk -w always DEV <<EOF
  o
  n
  p
  1
  2048
  -0
  t
  0c
  a
  w
EOF

Refresh the partition information in the kernel:

# partprobe DEV

Double-check with fdisk -l that the partition is W95 FAT32 (LBA) –the Pi Zero won’t even blink a LED if the partition is wrong–.

Make the file-system:

# mkdosfs -F32 DEV1 # e.g /dev/sdb1

Download Raspberry Pi armhf –other Pi models may need a different one–.

Mount the partition and extract Alpine:

# cd
# mkdir m
# mount /dev/sdb1 m
# cd m
# tar xvfz alpine-rpi-VERSION-armhf.tar.gz
# sync
# cd ..
# umount m
# rmdir m

Then insert the MicroSD in the Pi, boot, and run setup-alpine followed by lbu commit -d at the end.

Some of the instructions in the Alpine Wiki are unnecessary, in my experience.

  • The wireless is configured and setup fine on the setup, no extra steps are needed.
  • The system clock seems to be a non issue.
  • I chose Busybox NTP client and openssh during the setup.

I also installed haveged (explained in the troubleshooting part of the wiki page), just in case we need an extra source of entropy; but this is likely to be unnecessary thanks to the wireless card and other devices the Pi will have in the final build.

lbu commit -d is needed to save changes, but it won’t preserve anything on /home. If you create a regular user, it will be able to login but there won’t be home. This can be fixed in different ways, but for now I decided that using root was fine.

Logging with root using password over SSH can be all configured in the setup, just read carefully and choose the right answers –or you will have to tweak /etc/ssh/sshd_config by hand–.

Programming the motors

Seems pretty easy based on this Raspberry Pi TB6612FNG Python Library using RPi.GPIO.

My TB6612FNG came with headers, but not soldered in, so I had to solder them –it is easier to use jumper wires than soldering cables directly to the board–.

Last updated Mar 21, 2024