Category Archives: Motor Controllers

Raspberry PI Hat’s

It’s been many Hat’s lately as I am focusing more and more on this as my main core for everything. I still have a load of Hat’s that I want to start on, but I won’t exactly have much spare time the coming year. This is just a summary of projects that I am working on and intend to complete.

XPortHub. Basically a communication Hub With CAN, RS485, RS232, SPI, I2C, USB + Micro SD Card, RTC, Flash etc. This Board is actually assembled and so far working well.

Wifi Hat based on ESP32 to enable a low-cost Wifi/Bluetooth With CAN, RS485 and a few IO ports. I have PCB for this Board, but have yet not assembled or tested it.
32 x IO / Servo Controller.

Not ordered.

8 x DC Motors + 16 x Sensors.
7 x 5-Wire Stepper Driver.
3KW Universal motor driver, Capable of 60V @50A on 3-Phase, DC, Stepper or Solenoids.
NB-IoT/4G Hat.
Light-weight 60V PSU. This is only a test board with the Hat format.
LoRa + GPS Hat. Shown With 12km 1W configuration.
LoRa + GPS Hat. Shown With 6.5km 0.1W configuration.
2A Motor Controller. Can run 6 x 3 Phase, 4 x Steppers, 9 x DC motors or 18 Solenoids/PWM signals. This is still work in progress.
3KW 3Phase Motor Controller. This uses DRV8301 and is designed for 60V@50A. This actually need a revision before it is ordered.
Mini stand-alone 3-Phase Controller for 2A. This is assembled and is working, but the 60V DC/DC needs a revision.
CAN – USB Adapter. Assembled in rev 1.1 and working.
ESP32 Utility Driver – 4 sensors, 8 Servo/IO, 2 H-Bridge, 7 PWM signals. This is assembled and working rev 1.1.
Model Train Cockpit Controller. This is a failure and need a revision + a support adapter. A rev 1.2 is on my list.
STM32FxxxRx Breakout Board. Assembled and tested for F105 and F405.
Breakout for STM32F031F4 or STM32F042F6. Assembled and working.
My SWD Adapter. This will need an upgrade, but it has been one of my most usefully designs. It enables me to use a small 1.27 pich footprint on my designs and deal With ST-Link 2.54 Pitch. Next Version will have Reset and Boot Connectors.
Micro sensors and actuators. I had 4 of these designs and the Temperature, Light, Proximity sensor will be upgraded. More external sensors will be added later.

And more – many of my older designs have either been ditched or evolved into more mature designs listed above. I will be focusing more and more on the new Raspberry Hat format for everything. The exception will mainly be a series of intelligent sensors evolving out of my STM32F031F4 micro designs.



2A Motor Hat – Connectors

Connectors on this board is a challenge because I want to support 3 different usages:

  • 3-Phase that require a 3 pin connector.
  • 4 wire stepper that require a 4 pin connector.
  • PWM that require 1 pin + ground for every signal.

The board above uses 2.54 pitch connectors with space to mount small screw terminals. The ones I show here is just an example with a 18 x PWM and 18 x GND connections. These screw terminals are good, but they require access from top – so an alternative is to use something like the ones below that are right angle.

These are 2.54 pitch – 2 rows with 5.08 pitch apart. A bit big for my taste, but I think I can support them. And they don’t rule out anything as 2.54 pitch is very flexible. Height is an issue because PCB separators are 13mm to fit headers – these are 11mm on the back and a bit taller on the bit that will stick out from the board – I thing they will fit well.I need to make a package and show a 3D with these on a bit later.


I have both 3-phase motors, stepper motors and PWM Hat on my list, so I want to use DRV8313 because this delivers 3 individual Half H-Bridges that are excellent for all of these options then combined together. I am pretty sure I can get 6 of these drivers on a Hat which would give:

  • 6 x 3-Phase Motors,
  • 4 x 4-wire Steppers, 
  • 9 x DC Motors, 
  • 18 x Solenoids/PWM signals. 
  • or any combination of these.

This would actually be a very powerfully Hat.

Looking at STM32F405RG I actually have 26 Timer pin’s with PWM capacity so this looks very doable. What I want to add in addition to DRV8313 is INA193 (or INA194) to measure current on each DRV8313. Ideally I would have this on every PWM, but I am running out of space here, so lets see where we land.

Getting 6 x DRV8313 on a Hat is very doable, but I will need a 60V DC/DC and 6 current sensors as well + a DC-Rail sensor – that is 38 extra passive Components. 

An early mock-up like the one above is just a quick exercise to place the actual components on the PCB for a reality check – and this does not look like a go to me. It is not just about placing components, but all the lanes I will need between them. And it is still capacitors etc that I would like to place here.

So what can I do?

Firstly – 60V is a bit ambiguous for this board, 36V (meaning 24V) is more workable meaning I can ditch the 60V/3.3V DC/DC. That helps a lot.

The second option is the filters that I have on the current sensors – I can remove these from electronics and do them in software – that will reduce 36 components to 12 and the density of the board is suddenly far more realistic – and less complex.

The capability to remove filters from electronics because I can do them in software is something I often face, and in this case we can due to the raw capacity of the M4 MCU. This last mock-up looks far more doable. And I am happy with a 24V limit on this board because this is for small 2-3A motors that seldom needs higher voltages. Now – lets og and design this one!

MC4X60V50A as a Hat

Updated 3D Model 18.dec.2018

This is a bit more than a mockup since it is almost complete, but adding 15mm to an existing design is a lot of extra space. I turned the Hat so that the Raspberry PI Ethernet would be at right. Basically this is 35mm wider than a normal Hat, so it is still small for a 3KW Motor Controller.

Actually I now have some extra space so I can add in a few things. I ditched a RS485, but I would also like more sensors if I have pins/space available. I have a connector to connect 5V on PI to 5V from Motor. This enables MCU and Driver to have separate PSU. I can also add pins to mount extra capacitors behind on the left side. This will be perfect as they will be left of Raspberry PI or other Hat’s. I actually could remove the large 1000uF capacitors on top to save some Space, but lets see how it works out.

Heavy Universal Motor Hat

This is an unfinished 3D of MC4X60V50A or MC4X for short. I initially stated that I did not want this as a Raspberry PI Hat, but I do have SPI1 available + CAN is already planned. It would make a powerfully module + I could add an isolated GW as an add-on etc. The controller itself is more or less finished and the driver stages are mature design.

Firstly I don’t need to attach a Raspberry PI, but it would be a very powerfully stack to be able to add the 20++ modules I now plan. If I add the 40-pin GPIO at bottom-left I would get the RJ45 and USB’s of Raspberry PI 2/3 at left as an extension. This could work out very well – lets try it out and see where we end up.

Just to remind everyone – this Motor Driver support 60V @50A. It basically does so on all 4 independent drivers, so you can run 4 x heavy PWM/Solenoids, 2 heavy DC Motors, a 3-Phase BLDC Motor or a heavy stepper Motor.


7x 5 wire Stepper Hat

This board is a bit misleading  because I am using the wrong connectors to mock up an early 3D. The actual connectors are right angle and a bit wider, but testing on a paper print it seems that I have just about the size I need. Below is a picture of the Stepper Motor this targets.

These Steppers cost ca 1.- USD and they took me completely by surprise. As I started one of them it was moving slow, smooth and absolutely soundless far more powerfully than I expected. You get a lot for 1.- USD on these to be honest.

8 x DC Motor Hat

Revision 1.1 of my 8x DC Motor Hat. Basically this is 8 x DC Motors and 16 x IO/Servo, but the IO ports are 5V only. Differences from revision 1.0 are;

  • STM32F405RG 168Mhz 32 bit ARM M4, 192Kb SRAM, 1Mb Flash.
  • CAN bus
  • Removed addressing.
  • USB
  • Separate power connector.
  • 8 x DC Motor ports 5-12V with separate PSU.
  • 16 x IO ports. 5V.

This module was basically created because I wanted to control a robot arm I have around. This is a toy with 5 x DC motors, but using the IO I was hoping to create some position or end-stops so I could control it better. Just fun.


Updated RPI Hat Base

This rather boring drawing represent my new base for a Hat. Notice that I have removed the addressing scheme from the old ones, added USB and CAN as standard as well as Raspberry PI Hat form and SPI to communicate with the PI.

F405 is so fast that we can use higher SPI speed (ca 45Mbps) and I think we can achieve ca 30Mbps full duplex data, which basically is 60Mbps comparable to other standards. I can soft-switch on a SPI bus sending to one device and receiving from another creating a true device to device data stream. Removing the address scheme means that any device can become “Network Master” controlling this. I will return to the Software design tricks here in a different article.

I have one challenge here – how to identify a device? F405 have a Random Number Generator allowing me a safe way to guarantee that two devices behave different. Each of the F405’s also have a unique 96 bit ID. Using this in combination I can manage to tell the network master that we have a new device and get it allocated a time slot. I know F405 is up for the job, but I am more concerned about Raspberry PI due to the Linux core. The SPI on the Broadcom do not have the same support as you have on a F405, but lets see what we can achieve.

CAN is the actual control bus here. Can is excellent as it also allow up to 1km cable between devices. It does not cover the same speed as a SPI, but it is a classic in control systems. I am as many of you know a big fan of RS485, but CAN have it’s advantages as well. It is a bit more difficult to wire, but used here as a backbone net on short distances it is excellent.

USB is a bit new to me, but this is basically a high speed 1:1 serial port. It allows me to connect and power the device stand-alone from a PC. 5V from USB is connected to 5V on Raspberry PI, so this will power RPI and the rest of the stack as well.

I use a new 6 pin SWD connector here. I have described this earlier. I am very happy with my old 2×5 pin, but I mostly only used 3 pins and it added a lot of complexity. I tried a JST Micro connector, but will return to a simpler 1.27 pitch header and an external adapter card to convert to ST.Link/V2 with a Boot and Reset button on the adapter. I also had an UART on the old one, but that is expensive (in terms of pins) and I never used it.

This will be my base for a series of board that I plan.

  • 1 – Wifi board based on ESP32. This is intended as a low cost Wifi option compared to Raspberry PI. ESP32 is in most cases sufficient + it offer a CAN and RS485 etc.
  • 2 – Communication Hub. This is covered in my previous article and will soon be ready. Communication options are basically so basic to any system that I find myself doing a lot of these variants. This includes a SD Card, Flash memory, RTC Clock, 2xCAN, 2xRS485, 2xRS232, SPI, I2C and USB making it a very powerfully Hub.

The next ones are an upgrade of earlier Hat’s.

  • 32 channel Servo/IO Hat. This is one of my simplest, but yet most usable designs. STM32F405 is so powerfully that we get 32 ports in Servo format with +/- and a signal to drive a Servo, Digital In, Digital out, Analogue, In, Analogue Out, PWM Out, PWM In etc. I actually planned a GPIO board at one point, but realized that this board is so much more powerfully. And with 3 sides for connectors we should be able to do 32 channels a bit better than my existing board.
  • DC Motor Hat. I made a 8x DC Motor Hat and plan to extend this. My existing board had some IO + 8x DC H-bridges. I will see how many ports I now can make.
  • 3-Phase Motor Hat. DRV8313 is excellent for driving small 3-phase motors, so I want at least 3 motors – maybe more together with some IO. The focus is low speed position systems so the IO options will reflect this.
  • 5-wire Stepper Motor Hat. It is some excellent, low cost (1 USD) stepper motors around that need a decent support board. Using ULN2003 I can support 7 steppers with 4 chips. This board need 2.54 pitch connectors since they come with the motors, but with 3 edges I believe that is doable.
  • 4-wrire Stepper Motor Hat to drive more classic stepper drivers. In this case I plan 3 steppers up to ca 3A – standard for a 3D printer/CNC.
  • High resolution Analogue input board. 8×24 bit ADC w/30Kbps speed ADC’s are available low cost and this needs a Hat.
  • PWM Driver – 24V/1A. In fact this probably can be achieved in combination (or as a variant) of my 3-Phase Hat. Using DRV8313 and 3 x chips I basically have 12 x PWM channels.
  • Heavy Stepper Motor Driver (MC4X60V50A) – I need CAN on this to be able to control it, but I do not want this directly into a stack.
  • Heavy 3-phase Motor Driver. MC3P60V50A is a bit slipper than it’s 4X variant and focus on 3 Phase motors only. It has the same challenges that it can’t be directly connected on the stack.
  • Isolated CAN Hub. Heavy motor drivers and long distances have some challenges where we need to consider isolation. I tested ADM chips just to discover that they get very hot, so I want to explore a different path. Due to size I am happy with 2 x CAN per Hat.

Most of this is consolidation of work I have done on this blog before, so it is not as much work as first impression might suggest. I am in general not scared of Electronics because I find it very easy and relaxing to do an hour now and then, and over time I achieve a lot. Writing SW for all of this is a larger challenge, but I only intend to make the basis so others can start programming this time.

I sadly need to make one assumption – the state of Norway plan to put MVA and handling fee on all import. This means that a small package that now cost me 10.- USD suddenly will cost ca 30.- USD extra in tax and bullshit fee’s. It will become a limiter on what I can afford to do in here. My only alternative is to start selling board so I can afford to continue. Without this I fear the electronics part of this blog will come to an end.

Thanks for reading my Saturday morning ranting 🙂