Raspberry Pi I2C dual motor driver

My Raspberry Pi dual motor driver has evolved quite a bit since I last wrote about it. In the original incarnation, I had planned on using the PWM capability straight from the Raspberry Pi to drive the TB6621FNG motor driver. That didn’t work so well due to the fact that Linux on the Pi isn’t a real-time OS, and there is only one hardware PWM.

To get around that, I added a PIC16F1826 to directly drive the motor. The Pi will send commands over I2C to the PIC, which will control the motor driver. It’s almost identical to an older (pre-Raspberry Pi) design I have.

Once I figured out how to reliably use I2C on the Pi, it turned out to be a good route to take. The PIC is inexpensive and plenty capable of doing the job. The Pi doesn’t need to worry about real-time control.

Below, I’ve got the almost complete robot stack: Motor mounting board, USB hub with WiFi adapter, Pi Zero, LiPoly supply, and I2C motor driver board. It’s also got a Sparkfun IMU board that will soon be replaced by my own.


Raspberry Pi dual motor driver

This is only sort of a new design. I’ve used this TB6621FNG dual motor driver chip on a number of my boards prior to this one. I basically just took one of my existing boards and shuffled things around a bit to fit the Raspberry Pi Zero form factor.

In this photo, I’m using it with a Pi A+ while writing some Python code to test it out. Eventually (when I can get more than one Pi Zero), I plan to use this in a stack, with a Pi Zero, my LiPoly battery board, and my USB hub board for WiFi.

Final Pi Zero LiPoly mod

I solved the final issue with my LiPoly board. It was a minor one. The yellow LED is supposed to indicate whether the LiPoly battery is on or off. It was always on. In a Captain Obvious moment, I discovered that it was always on, because I told it to. I had connected both sides of the DPDT switch together. Why? I don’t know.

But, with a lifted pin, one cut trace, and a short mod wire, it’s all set.

I already have the next set of PC boards on the way, so they’ll still require this mod. It’ll be easier to deal with before there are parts on the board. I may not order any more boards, with this fixed. I’ll have plenty for my own uses, so unless I decide to sell it, there won’t be a need. I’m thinking about a Kickstarter for this though…


Poly want a… Poly want a… Poly want a Lithium?

Raspberry Pi Zero stack-up

Not stack-up, as in PC board layer stack-up, but add-on board stack-up…

The LiPoly board is working fine, as detailed in my prior posts. The USB hub board is also working. The stack shown here has the Pi Zero and both boards. As shown the D+ and D- lines from the USB hub aren’t connected to the Pi.

For the moment, I connect them with a cable, but I’ve got a small interconnect PC board on the way. With that, I won’t need extra cables and won’t need to hard solder the boards together. I’ll post pictures when it comes in.


She’ll be coming ’round the mountain when my boards come in

Raspberry Pi UPS

I built up two more of my Raspberry Pi LiPoly battery back up boards today. After doing so, it occurred to me that, in addition to allowing for portable use of a Raspberry Pi Zero, as I had originally intended, the board, with a few minor modifications, will work quite well as a UPS (uninterruptible power supply).

I wired the output from the comparitor to GPIO 21 on the Pi expansion header. I’ll be able to monitor it to detect when the external power is off. I can then gracefully shut everything down.

Without anything else running, a small 150 mAh battery will give me about 40 minutes run time with a Pi A+, and about 20 minutes with a Pi 3. Add in peripherals, and it will go down a bit from there. Regardless, it will have plenty of time for a clean shut down, or to wait out a short power outage.

The cover image here shows my Pi A+, and my Pi 3 with their UPS integrated. I still need to drill a hole in the case lids so I can flip the power switch. Otherwise, I’ll have to pop the lid off if I want to completely shut it down. Not a big deal, but still something I should do.


Pi Zero LiPoly – Final

Pi with my LiPoly board

My Pi Zero LiPoly board was working, but not exactly in the way it’s supposed to. Charging was fine. Powering the Pi from the battery, fine. Th problem came on the net MCP_IN, in the schematic below. I was reading voltage at the test point for MCP_IN, JP4.

Schmatic v1.2Either the comparitor wasn’t comparing properly, or the MOSFET wasn’t blocking all current when shut off. Or, something else was wrong.

That “something else” was a pretty rookie mistake. See if you can find it before looking below…

Error in v1.2Long enough. My comparitor was wonky, because it was unpowered, as you can see in the image below. +5 volts doesn’t actually connect to the +V pin on the comparitor chip.

Fixed that and it works exactly as expected now.

Pi Zero USB

Pi Zero USB hub

I’m far from the first person to put together a Pi Zero USB hub. In fact, mine is loosely based on the open source design from @richardhawtorn, which was based on the design by @MakerBro.

The key difference is that I removed one of the USB A ports in exchange for a reduced footprint. As much as possible, I’d like my Pi Zero boards to have the same footprint. This design allows for a small USB WiFi adapter to be plugged in while remaining within the Pi Zero board outline.

Pi LiPoly charger on Pi day

Pi with Zero charger

I considerably reworked the design, and now have one of those boards built up.. I put a P channel MOSFET on the power line going into the MCP73831 LiPoly charger chip, which is the Pi 5 volt line. The power line out, has a Schottky diode, and then goes to the Pi 5 volt line. I use a comparitor across that diode to switch the input MOSFET on and off.

1-20160314_205324If I’m running from the Pi, and charging the battery, the cathode of the diode has 5 volts, while the anode has the about 4 volts coming out of the charger chip, keeping the comparitor off. When I disconnect the Pi power supply, The anode has the 4 volts from the battery, and the Pi 5 volt line has that, less the voltage drop from the diode. This sets the comparitor, which turns off the MOSFET. That way, I won’t be feeding a low voltage back into the charging chip when running from battery.

After the Schottky diode drop, I get about 3.7 volts on the Pi 5 volt line. That’s enough for the 3.3 volt LDO regulator on the Pi. Most 5 volt peripherals won’t be able to run, but the Pi and 3 volt peripherals will be fine.


This is a bit of a late entry on Pi day, but rounded, today is 3.14.16

Pi Zero In Hand

Raspberry Pi Zero

I own a decent variety of Raspberry Pi models. I’ve got an old B, a Pi 2, an A+, and my Zero came in the mail today. Unfortunately, I wasn’t able to buy the $5.00 version, but had to buy it in a combo pack from Adafruit. I got the “Budget pack, product ID 2817”, for $29.95. See: It’s literally in hand:

Pi Zero in-handDon’t get me wrong. It’s a really handy set of accessories that’s included. It’s just that, in my case, I already have most of it. If you aren’t fully accessorized, buying a combo set like that is the way to go. If I need more later, I can just buy the $5.00 version (if it’s ever in stock).

These things go quickly. When the Zero first came out, Adafruit had the combo packs in stock, but they were out in a few days. Last week, they came back in stock (still no unbundled), but are already out just a few days later.

Pi with my LiPoly boardI’ve seen a number of people lament the limited usefulness, since it’s so connection poor. If your plan is to use it as a stand alone device, they have a point. You would likely be better served with one of the other models. But, that’s not my intention. I’m designing a set of same-size boards that will be the basis of specialized systems. The LiPoly battery charger / power pack shown on the right, is my first. I’ve got an I2C I/O board almost ready for fab, and I’ll follow that up with a motor control or two.

This might be a good way to look at it: The bigger Pi boards are better suited to use in software or OS training, or as stand-alone computers. The Zero is ideal for hardware design training.

Yeah, yeah. I know. Nobody cares about the Zero anymore because the Pi 3 just came out.


I was ionized, but I’m better now.