projects/build-hat
.. | index about projects posts media links

for a robotics project, i have to use lego parts. last year, for a similar project, i had to use the older generation of robotics components (being the nxt/ev3 parts), which had a python and c library already written. this year, i'm using the newer version of lego's motors and sensors, the SPIKE system. they are definitely higher quality and more reliable (to be fair, they're newer too), but unfortunately there is not an established ecosystem of stuff. the raspberry pi foundation (who designed the pi hat that you can plug the sensors and motors into) has released a python library to control the board. however, i am not a fan of python for programs with complicated control flow and a lot going on. it gets really cumbersome to debug and write in the first place. i also had already written a few important utilities in c that i didn't want to figure out how to call from python. i decided to write a c library myself to run the robot.

the board is rp2040 based, and i quickly discovered that the last 0 in 'rp2040' stands for 'zero onboard nonvolatile memory', meaning you have to load firmware through a bootloader program every time the pi power cycles. this made it a little more annoying. i hadn't really done any serial communication in c before. the python library made it possible for me to figure out what i had to do, because build hat's documentation doesn't describe how to actually upload the firmware. it took a bit to get that working, but it's been fairly smooth sailing since. i'm still working on the library to get some other stuff working, but honestly the only part that the average person wouldn't figure out from reading the docs is the firmware uploading so the state it's in right now enables someone to do anything they want through the serial communication wrapper functions i've got.

an update with a better writeup and more info is coming soon.