Update 10/20/2021 2:45 AM PT:
This review was updated based on information received from Raspberry Pi program manager Richard Hayler about an episode of The Pi Cast. Although the cost of complete Lego kits with the sensors, motors and other components is still quite high, individual elements can be bought much cheaply. Hayler also covered alternative power supplies for the Build HAT and a Lego-designed maker’s plate, the first Lego part designed for use with an SBC. All this information has been added to the review and the score has been adjusted upwards based on the new information.
Original article
We knew Raspberry Pi would use its RP2040 in a product, but we never imagined it would be this. The $25 Build HAT is an interface between the Raspberry Pi’s 40-pin GPIO and products from various Lego educational kits. So where does the RP2040 fit into this? The RP2040 is used as an interface, controlled via a serial interface (via the GPIO) using a nice Python module that simplifies working with the components.
Raspberry Pi’s Build HAT is the result of two years of work between the Raspberry Pi Foundation and Lego Education. Build HAT is designed to go further with Lego’s block coding language and provide a Python module that allows learners to continue using the rather expensive Lego kits with a more powerful and extensible language.
Build HAT focuses on specific Lego kits, namely Spike Prime, Mindstorms, and Technic, all of which have their own hubs. We have experience with Lego’s Spike and the hub used in that kit is already a powerful piece of hardware. Powered by an STM32 microcontroller, the Spike Prime Hub has six ports for Lego’s LPF2 connectors and is primarily for use with the Spike block coding language, but all we need is a USB cable and a serial connection to run a version of MicroPython to run that in the board.
With Build HAT, the hard part of creating a serial connection in Python is done for us and we can start building Lego powered projects. We tried Raspberry Pi’s Build HAT, learned how to use the Python module, and found that we can use it with other HATs and Raspberry Pi add-ons.
Build HAT Specifications
SoC | Onboard Raspberry Pi RP2040 manages low-level control of devices |
Supported Raspberry Pi Models | All 40-pin models are supported. |
Supported Lego Products | Lego Technic, Lego Spike, Lego Mindstorms, other Lego devices that use an LPF2 connector. |
connections | 4 x LPF2 Connectors |
1 x DC 5521 Cylinder Sleeve (5.5 x 2.1 x 11mm) | |
Flow | 8 – 10V DC power supply via barrel jack. |
7.5V battery pack | |
5 x AA batteries | |
Raspberry Pi is powered via Build HAT | |
Dimensions | 65 x 56.5mm |
Using Build HAT
As you can guess from the name, Build HAT is a regular standard HAT add-on designed to work directly on top of the GPIO† Before dropping this board on your Raspberry Pi, make sure to use the included M2.5 9mm spacers or else the DC jack will be dangerously close to the Raspberry Pi’s audio/video jack. If you plan to use another HAT on top of Build HAT, please use an extended GPIO header, which is unfortunately not included in the kit.
To use a HAT along with Build HAT I used M2.5 12mm spacers that keep the board level and the GPIO connections secure. A cutout just above the camera (CSI) connector on the Raspberry Pi means we can easily use the official Raspberry Pi camera in our builds. Adding traditional electronic components is possible, The Build HAT has room to fit a small breadboard in its place, but this blocks access to the camera slot.
Using the Build HAT with motors and sensors requires an external DC power source and Raspberry Pi has exactly what you’re looking for. The Build HAT power supply, available for an additional $15.00, provides 8 V, 6 A (48 W max. power), which is enough to power both the Raspberry Pi and the Build HAT. Build HAT controls the power supply to the Raspberry Pi. Mobile projects require the use of a 7.5V battery similar to those found in RC vehicles or you can use five AA batteries. You can use your own DC power sources, just make sure they meet the DC 5521 (5.5 x 2.1mm) barrel jack. It is possible to use Build HAT without the Build HAT PSU as it likes to be powered from the 5V GPIO pin. But by doing this we are limited to using the Force Sensor (push button) and using the motors as input devices (rotary encoders). The extra power of the Build HAT PSU is needed for sensors and motors.
We used a Raspberry Pi 3B with the latest Raspberry Pi OS release as our test machine, but you can use the Build HAT with any 40-pin models of Raspberry Pi. The Raspberry Pi 400 requires a breakout board/extension cable due to the placement of the GPIO.
After installing the Build HAT Python 3 modules, we started with a simple motor test with a set of Lego Spike Prime motors. The Python library is relatively simple and within a few minutes we had motors running and variable speed control working. But what else can we do?
The Build HAT Python library is compatible with a range of Lego sensors, and when we looked through our box of Lego Spike Prime parts, we found sensors compatible with ColorSensor, DistanceSensor, and ForceSensor. The Lego Spike Prime color sensor uses reflected light to determine the color of an object and output the corresponding RGB/HSV color values. The ColorSensor Python class has an interesting function that can return a named color, useful in the classroom for students unfamiliar with RGB/HSV.
The distance sensor works in much the same way as an HC-SR04 ultrasonic sensor. It sends an ultrasonic pulse from a “trigger” transmitter and then waits for the reflected pulse to be received by an “echo” sensor. If we use a little math, we have the distance. These kinds of sensors are mainly used in robots, which is an easy way to detect and navigate.
The last sensor we tested was the force sensor, a simple plunger that can register quick taps or long presses. The force sensor can be used for simple digital on/off input, or the analog force sensor in the device can measure up to 10 Newtons of force. We chose to test a simple on/off input and had no problems using it as a simple trigger. Going a little further, we can measure the force applied to the sensor and use that input to control the speed of a motor.
The Build HAT has a passthrough GPIO header that allows GPIO extension headers to extend through the board, allowing the use of another board. We tried a handful of boards and had mixed results, all of which came down to which GPIO pins were used. If you plan to use Build HAT with other cards, see: pinout.xyz to make sure there are no pin conflicts. We read through the Build HAT guide and noticed that it uses GPIO 0/1, 4, 14 and 15. GPIO 14 and 15 are our serial connection to control the built-in RP2040.
We tested two of Pimoroni’s NeoPixel boards, Unicorn HAT and Unicorn pHat, and they didn’t work. They both use GPIO 18 to communicate NeoPixel control data, and we note that this isn’t one of the pins used by Build HAT, so there must be something else going on behind the scenes. If we were to use an array of NeoPixels instead of a board, we could specify which GPIO to use.
We were determined to light up some RGB LEDs, so we used Pimoroni’s Blinkt which uses APA102 (DotStar) LEDs and built a setup to detect the color of an object. Pressing the force sensor turns on the color sensor, takes a reading and stores the value in three variables (r,g,b) which are then passed to Blinkt, which shows the color across all eight LEDs.
Using cases to build HAT
The Raspberry Pi Build HAT is designed for those who already have compatible kits, mostly educational institutions and outreach organizations. Lego components are not cheap. a full Lego Spike Prime kit costs about $340 (opens in new tab) or you can buy one Lego Spike Expansion Set for $110 (opens in new tab) which comes with a single motor, a color sensor and lots of Lego bricks. Build HAT is compatible with Lego Mindstorms, which is another hefty investment. In a conversation with Richard Hayler, program manager at the Raspberry Pi Foundation, we learned that most LPF2 components should work with Build HA. These components can be picked up much cheaper than full sets, for example Lego Technic motors at $40 each, more expensive than a typical DC motor but much cheaper than a full set.
Build HAT only has four LPF2 connectors, two less than the official Spike Prime Hub. This is not a deal breaker. With four LPF2 connectors, we can connect two motors and two sensors, enough for a basic robot. But given the plethora of Lego components compatible with this connector, it would have been great to match the Spike Prime Hub’s number. It would also be great if there were Lego compatible studs that we could attach Lego bricks to as well. This omission isn’t a deal breaker, as we can buy Lego-compatible Raspberry Pi cases for around $15, as we did to integrate our test project into a Lego build. Lego has released its first “element” (a Lego term for a part/piece), a “maker plate” designed for use with SBCs with mounting holes for the Raspberry Pi. Currently, this makerplate is only available in a Spike Prime expansion set (opens in new tab)sells for over $100.
Lego has its own block-based coding language, Spike, which works with Lego’s hub device to communicate with sensors and motors. While powerful, the Spike language is limited, so including a Build HAT Python module is a smart move. The module extends the range of Lego kits to more advanced programmers, while enabling the vast ecosystem of Raspberry Pi HATs, including many of the best Raspberry Pi HATsand Python projects for use with Lego.
So what can we make with Build HAT? With the power of Lego’s interlocking bricks and the ease with which we can interact with sensors and motors, we can create robots, M&M sorting rigs and even automate our existing Lego models (we’ll be happy to look at our Lego R2-D2) .
Bottom Line
At $25, the Raspberry Pi Build HAT is a good investment, but only if you already have or can get the compatible Lego kits at a good price. The Python module, which increases the ease of use of Lego, is easy to use and provides an advanced path for students to follow. If you are careful with your choice of HATs, Build HAT can easily be used to extend your Raspberry Pi projects.