Mecanum Car

My son loves cars. Our favorite part of Discovery Day at Oracle Park was the Robot Zoo. It showcased dozens of robots built local robotics clubs. All the robots used mecanum wheels. Building a mecanum car to drive around our living room seemed like a fun idea.

Parts

My online searching came up with this basic Mecanum kit for $36.99. I tried searching AliExpress, but for a single order, including shipping, Amazon Prime had the best deal. Other BOM items were:

The selection and prices on Amazon surprised me.

Assembly

Assembling the car is straightforward. This was a fun project with my son. Pre-cut acrylic parts slot together, held in place by metal screws and nuts. There are lots of pre-cut holes to mount sensors, electronics, etc.


Wiring

The motors in the mecanum car kit have short copper leads. I soldered two wires onto each motor. I added heat shrink tubing around each solder joint for strength and electrical insulation. This part wasn’t too complex, just laborious.


Driving Motors

I was initially thinking of using TIP-120s to drive the motors, but I need the ability to drive the motors forward and back. H-Bridges seemed like a perfect solution. ITP has a useful tutorial on how to drive a motor in a microcrontroller using an H-Bridge. I ended up purchasing the Adafruit L9110H H-Bridge and following their tutorial.

Following the tutorial worked fine, and I got all four wheels moving off of a power supply easily.

Systems Diagram

The plan for the entire system is in this basic MS Paint diagram:

GRPC

The first step of the controls software was setting up a GRPC connection between the PI car and a desktop computer. The final plan is to use a USB GameStop XBox controller to control the car. The first step is to get a console application on a Ubuntu desktop talking to the Pi over GRPC.

Building and installing GRPC on the Pi was somewhat straightforward according to this tutorial: https://grpc.io/docs/languages/cpp/basics/ though there were some quirks:

  • Building GRPC worked fine with -j4, but when linking the examples, I got a link error running -j4 (ld terminated with signal 9), which worked fine with no multithreading (maybe something to do with running out of memory?). Basically you have to build the projects with “make” not “make -j4.
  • ifconfig wasn’t working, or maybe not installed on Raspian. I have to check the local IP with hostname -I .
  • You have to open a gRPC port, in my case 50051. The easiest way to open it was with UncomplicatedFirewall - ufw. This initially worked fine with a simple “sudo ufw allow 50051” and “sudo ufw enable”. However, I forgot to open port 22 after installing ufw. This meant I mysteriously wasn’t able to SSH back into the Pi when I went back to work in the evening. The only way to get ssh working again was to set up a monitor, keyboard, and mouse on my workbench, and run “sudo ufw allow 22” and “sudo ufw enable”
  • gRPC by default builds all the libraries as static (.a files). I’m was trying to keep this project simple so am not using CMake or Bazel, building with a one-line shell command. gRPC generates over 112 libraries, and determining the correct order to include them as links (-l) in g++ was harder than I thought.
  • Bazel seems to be a more modern build system. I was able to install bazel by building and installing from source from this helpful github project: https://github.com/koenvervloesem/bazel-on-arm/blob/master/README.md . Bazel built and installed fine on my Pi. Unfortunately, building gRPC with bazel ran into problems. Running ‘bazel build :all’ gave the error “ERROR: An error occurred during the fetch of repository ‘go_sdk’ Error in fail: unsupported platform linux_arm”
  • I was able to use the gRPC CMake examples as a scaffold for the car server. After general cleanup, the only key change was adding the pigpio library to the target_link_libraries function in CMakeLists.txt

Testing

After getting the basic wiring working on a breadboard, I soldered the H-Bridge assembly onto a prototyping broadboard. For power, I bought a VGE 4000mAh battery pack on Amazon. I decided to drive the motors directly from the 5V pin on the Raspberry Pi. Without doing too thorough research, I found a three posts that suggest that if you keep the power under 1A you should be fine. Measuring the current of a full forward / reverse movement of the car showed the current to be about 0.62A.

For this testing, the car is connected to Wifi, and the move instructions are being sent wirelessly. The car is now remote without a tether.

Enclosure

We build a simple enclosure for the car out of cardboard, and threw all the electronics in it.

The video of it driving is on Youtube.

Pi Train

We have an old Lionel train that we’ve kept around it the hopes of fixing it up one day. The last time my son and I were playing with it, the motor stopped working. I promised to fix it and get it running again.

Stepper Motor Engine

Servos operate on PWM signals. pigpio seemed a natural choice to generate PWM signals from my Pi. The Servo Pulse Generator seemed like a good starting point until I realized only certain servos can rotate continuously (with a bit of hacking).

I instead shifted to a stepper motor, in particular a 28BYJ-48 that I had laying around. This tutorial by Ben Akrin got me going, though when I wrote and built the script on the Pi, nothing happened. After a bit of minor debugging I figured I could re-write it in C++ (which had worked before). Soon, the stepper motor was stepping. I set it to what I thought was a “medium” speed, which ended up being slow. I could hear the internals buzzing in a way that did not sound sustainable. It also got hot. I don’t think the 28BYJ-48 is the right motor choice.

I pushed ahead with the 28BYJ-48, and purchased a set of gears and pulleys from Amazon to transfer the power from the stepper motor to the primary train gear. There were two problems. First, the inner diameter of the small gear did not match the outer diameter of the gear axle. Every attempt at mounting this centered proved futile. Second, getting the pulleys tight would have put too much force on the train gear axle.

I decided to clean by workbench, and go back to the drawing board.

Toy Organ

After my company went bankrupt, I had a lot of time on my hands. I have a 3 year old son and was looking for projects to do with him. I dug up my old copies of Forrest M. Mims III Volume 1: Timer, Op Amp & Optoelectronic Circuits & Projects looking for projects. My son loves to sing, and enjoys playing with our toy xylophones. Mimm’s 555 Toy Organ on page 23 of V1 seemed like a perfect project to get him motivated about building electronics.

555 Toy Organ

My initial approach was to attempt the project with the electronic components in my workshop. I had a 555 and 741 left over from previous projects. I didn’t have (or couldn’t find) the exact resistors and capacitors required, so I swapped out components I thought were close enough. Couldn’t I just swap out R1 100K variable resister with a 2K variable resistor, and make R2 a 333 OHM resistor?

It didn’t work.

Luckily I had a lot of time on my hands, so I headed over to Digi-Key and ordered all the proper materials as required by the schematics, and wired everything together.

It still didn’t work.

I didn’t own an oscilloscope, and don’t have a good sense of debugging circuits. I tried searching around on electronics forums, but the typical response to a post written in the last 15 years to someone asking “why doesn’t my 555 circuit work” is: “lol why are you still using a 555? There are much better ICs available.” I figured it would be easier to buy a Raspberry Pi, connect everything in software. At least I would have a better chance of debugging.

Raspberri Pi Toy Organ

As someone used to working with Arduinos and BASIC Stamps, Raspberri Pis are amazingly simple to use and program. Hats off to the Pi team!

My basic workflow was:

  • Run Raspberry Pi OS on a 64GB SanDisk Extreme microSDXC
  • Connect Pi to wired Ethernet on my workbench
  • SSH into Pi, run GNU Screen + GNU Emacs 26
  • Develop on my main computer with proper screen and keyboard
  • Build and run GDB on the Pi directly
  • Use a Pi Cobbler to connect GPIO to breadboard

I didn’t find a great entry point or tutorials on GPIO on a Raspberry Pi. pigpio seems to be the standard GPIO library for the Pi. Their website has a ton of great examples in C and C++.

My source code is here: https://github.com/ptierney/Pi/tree/master/toy_organ. It was in fact easier to program the logic for a basic organ with pigpio than debug my 555 circuit. The program generally speaking:

  • Sets up pin modes (for input and output) and sets up callbacks for state changes on GPIO pins
  • Waits on an infinite loop calling gpioTick()
  • On a callback, set a gpioWave (a pigpio concept) with a pulse delay in microseconds. My current logic simply creates a square wave. It sets the speaker pin high for 1/2 the time in hertz of the tone. Technically my tones are off slightly because I approximated the hertz timing as integers, which is only true for A440. Wikipedia has a great list here that I referenced. It sounds good enough for my 3 year old though.

The wiring is straightforward. The Pi reads GPIO pins with a current-limiting pull-down circuit. Sound is output on a GPIO pin. I found this video incredibly helpful in describing the proper way to read a button on your Pi.

The proper way to wire your Pi buttons:

I settled on these buttons from Digi-Key. They have an OK key-feel, but are great for the price, and come in lots of different colors. They also slot into a breadboard for easy prototyping.

Everything was looking good though the sound coming out of the Pi was low. I could hear it in my quiet workshop, but organs are supposed to be loud.

Op Amp Woes

Forrest Mims has a whole section in the book on the operational amplifiers. I quickly wired up his suggested circuit in an attempt to get more sound out.

The sound coming out was faint and distorted. I tried swapping out resistors and it didn’t help. Reading a bit on forums, I learned that the 741 isn’t meant for modern use. A more contemporary IC is a TLC271ACP or similar. I bought one from Digi-Key, and updated my circuit. It had the same problem as the 741. Reading a bit more I’ve learned that using these Op-Amps requires careful adjustment of the variable resistor.

I remembered from my Arduino days the TIP120, and a quick google search popped up Adam Meyer’s blog where he has a great post on how to use a TIP120 to amplify your microcontroller’s output. Basically, you just have to make this circuit:
After quickly making the circuit, and playing around with resistor sizes, it worked great! I would recommend this speaker by Adafruit. Very solid and loud.

Final Version

Here’s a video of the working Toy Organ.

Here’s an overview photo of the wiring. My son removed the buttons.