Apress recently published the book Programming Microcontrollers in CircuitPython. Adafruit asked author Armstrong Subero some questions about both he and the book (and had Armstrong on our SHOW AND TELL too!) –
Is this your first book? What do you do, a little about yourself, etc.
This is actually my third book. My first book was titled “Programming PIC Microcontrollers with XC8” and my second book was entitled “Codeless Data Structures and Algorithms”. I especially like codeless data structures and algorithms as it allows everyone to get a taste of data structures and algorithms, without being tied to any one language. I love Python and C, but many programming concepts that confuse people can be taught without writing any code, so I wrote a book to do just that. So be sure to check that one out as well!
\Well about me. I’m from Trinidad and Tobago, a small Caribbean country just off the coast of Venezuela. I currently work for the Ministry of National Security here. I’m a jack of all trades tech guy but I like to think of myself as a computer engineer. I wear many caps and have broad experience working with everything from writing web apps to working on specialized medical equipment. I think my geographical location has a lot to do with that, the population is just 1.3 million so there really isn’t much space to specialize in any one thing in technology, as the market simply does not exist. You have to be a tech generalist.
My passions are broad, but I love embedded systems development and spend my free time doing side gigs with that. Something about directly manipulating MCU registers and exploring the complexity of these tiny chips just gets my skin tingling. It’s amazing how complex these chips can get, considering they only cost a few bucks. I also enjoy 3D printing and started teaching myself mechanical design and 3D modelling, it’s amazing how easy it is to go from concept to prototype and I think along with microcontroller technology and AI, 3D printing really has the capability to change the world forever. Combining the two has led to me having created some cool projects both professionally and personally. My free time interests these days are spent on robotics, I have a big robotics project I’m working on (so look out for that!) and I recently started learning animation. It’s amazing how much you can learn by being connected to the internet.
How is the maker world in Trinidad and Tobago?
Well, like I mentioned, we have a small population, so the maker community is very limited, but I’m hoping to have the maker culture penetrate here. The good thing is that Trinidad and Tobago is just one country in the Caribbean, so as a Caribbean Community there is a Caribbean Maker Group that started a few years ago that’s gaining traction.
The hardest thing about making here is that simple things are simply not accessible locally and have to be shipped in. When I first started many moons ago, there wasn’t a single retailer I could buy a microcontroller and programmer from locally. When you have to make something almost everything has to be imported. My hope is to push the maker culture here and hopefully make tools and supplies makers will need, more accessible. One of my reasons for beginning to learn animation is to do videos that will help foster the growth of maker culture here.
What inspired you to write a book on CircuitPython?
Well prior to Covid, I was active in a local Police Youth Club here trying to get some kids interested in making and robotics. The aim was to make an obstacle avoidance robot using a PIC microcontroller that the kids could program and make run around, I did finish the course but I spent much more time teaching the programming aspect than I had hoped. I needed to cover programming, electronics and robotics concepts and only had a few weeks to do it so time management was crucial. The thing is the age range I was working with was very vast, from 6 years old to around 19 years old. I love C, but it isn’t exactly easy to learn. Even when I switched to the Arduino, it’s still C based, so it was still difficult to teach these kids, particularly those that did not have much experience with computers, so I knew eventually I would have to rewrite the course using something more accessible.
Then shortly after Covid came and there was the ventilator shortage scare. I saw many local web developers trying to work on ventilators. They were really struggling to do the hardware manipulation stuff and I saw a lot of “magic smoke” coming out of bad designs. I realized it wasn’t just locally or regionally but internationally as well. Many programmers were trying to design embedded systems but were clearly lacking the electronics background, yet alone trying to design a safety critical system like a ventilator. Having a background in medical equipment design and repair, I was genuinely worried. So I wrote an article for Free Code Camp about the perils of designing such systems and tried to give some guiding principles. Well that article was featured on Hackaday and I got bombarded by emails from people wanting to know more.
The thing is after working with microcontrollers for so many years, I forgot how much prerequisite knowledge is needed to understand them. Let’s say you’re trying to explain ADC, then someone is curious about how it works, then you have to explain sample and hold circuits, then capacitors and I/O pins and eventually you find yourself basically giving them a short course in electronics.
The internet has a lot of free content, too much information as a matter of fact and someone starting from absolute zero on the electronics side will be completely confused as to where to start. I already had a book on microcontrollers, but it was more geared to people who had some background in electronics and looking specifically to get started with the PIC microcontroller.
I searched for a solution and realized Python might be the way to go. Both the kids and software developers accustomed to working super abstracted from hardware looking to manipulate hardware could find a common starting ground. I experimented with both CircuitPython and MicroPython, and liked the “all in one place” approach Adafruit had, you can get boards that supported CircuityPthon, tutorials and components all in one streamlined ecosystem. I also really like the Microchip SAM microcontrollers, especially the SAMD21 which is my go to microcontroller for most tasks these days. Most of the Adafruit boards were based on SAM devices so ease of use combined with familiarity of the hardware made me really want to use CircuitPython. There were a lot of great tutorials for CircuitPython, and I tended to recommend those, but as an author many people asked me for a “good book” to get started and still had concerns about lacking basic concepts. I looked around and realized there weren’t any books on CircuitPython that were geared toward an absolute beginner so I decided to write my own.
Who is your target audience? Who do you think will benefit most from this?
I think everyone will benefit from this! Kids who never worked with microcontrollers before, software developers looking to work with hardware or Arduino guys looking to transition to CircuitPython.
My audience in mind are absolute beginners to working with hardware though. Sometimes we forget what it’s like to be a total beginner. For example a lot of tutorials are like “this is an output pin, connect this wire, write this code and light up the LED”, which is great for persons who already worked with some other microcontroller, but it still doesn’t tell you what an I/O pin is or how it works, something that many beginners ask. My hope is to cover a broad base not only showing how to use peripherals, but also explaining them enough so that a reader will know just enough to move forward.
Basically anyone who wants to control hardware with code, but also wants a little peek into “how” will benefit from my book.
Why write a book on CircuitPython when there are so many resources available? Why not blog posts or a video series? Or do you plan on doing some videos and more later for the book?
Well tutorials are great, but many still assume some requisite knowledge, and blogs and videos will simply be too long to cover everything for a beginner looking to get started. I think why I chose a book besides being asked by some readers for a “good book” is the power of structure you get with a book. With a book I can have a clear beginning and a clear end. A book also allows me to put in a little extra. When you look at a tutorial or blog, you kinda don’t want it too long. When you buy a book you expect a little extra explanation on some things.
Well earlier I mentioned I was getting into animation, I actually planned on doing an animated series on robotics using Python and CircuitPython and of course the material taught in the book will be helpful in following along. So look out for that very soon!
Do I need a particular board to follow along? Do you have any recommendations?
The thing I like about CircuitPython is that so many boards are supported that someone who is looking to get into this ecosystem is bound to have an old board from their “mountain of boards” that supports it. An Arduino Zero or an STM32 Nucleo shouldn’t be hard to get. Though of course the boards Adafruit carries have a lot of goodies, I tend to recommend those. In the first chapter I actually talk a lot about that, so look at my book to get started with that. Circuitpython is so portable, look at how quickly it was ported to the RP2040!
If I had to recommend one, I would absolutely recommend the Adafruit Grand Central M4 Express! I cut my teeth on 8-bit, so it’s insane to see a board with 1MB of flash plus 8 MB on board storage out of the box. The board will also allow you to grow. You can do the simple stuff and you have the horsepower to do the more complex stuff as you learn more.
What’s your favourite chapter?
My favorite chapter is definitely Chapter 3 “Embedded Systems Overview”. It’s longer than most chapters in the book, but worth the read. I have read a LOT of books on embedded systems (reading textbooks is a pastime of mine) and they all seem to follow the same structure. Talk about the MCU for that book. Talk about X langage (usually ASM or C) then talk about using X language to access peripherals on that board. So in most beginner books you typically learn the MCU architecture, digital IO, analog IO, communication peripherals and sensor and display interfacing. This is great because it’s the core you need to use MCUs, but sometimes you need to see the forest, not just the individual trees within it. It’s crucial to get that “big picture view”.
Chapter 3 does something I haven’t come across yet, it gives you a broad overview of embedded systems. If you ever wondered how frameworks, HALs, BSPs and Platforms all tie together this is the chapter you want to read. It gives you a holistic view of embedded systems. This is something you learn over time, but isn’t usually explicitly explained, especially in a beginners book. Things like embedded systems constraints, classifications of systems and short discussions on testing and security are usually neglected in beginners books. However in my book these are talked about broadly enough that anyone reading it will be able to understand.
Let’s face it, we all use microcontrollers because we want to build cool stuff. Everyone dreams of playing a video or doing ML on these tiny computers. Some people however eventually build something that someone else is willing to buy. After we have built something, generally there is no condensed information on bringing this product to market. Even if you do a Kickstarter or Indiegogo it is expected that you have something that resembles a finished product. This chapter also breaks down what you do to get a product to market, throwing in industry terms like COTS and TTM all in 7 steps.
What is your favorite board for running CircuitPython?
That is a tough choice. I like running it bare metal on the SAMD21, and of course the STM32F7 boards as well. However, the folks at Microchip Technology sent me the Adafruit EdgeBadge and I am in love! I keep this board on my desk at all times in case I ever get the urge to test something quickly. It’s totally self-contained and that’s something that I really like. LCD, microphone, buttons, accelerometer and 2MB flash plus I added a little speaker. It’s a unique little device and if you really don’t have a lot of space to work with hardware, this little board can work wonders. Plus, when I was younger I wanted a gameboy more than anything but ended up taking one of those 500-in-one electronics sets instead! Now I can experience what it’s like to have my own “gameboy” that I can hack!
This may be off topic, what really piqued my interest in this board is tensorflow lite support of this board out of the box. ARM also has the CSMIS NN library that I’ve been playing around with and loving on the EdgeBadge. The Cortex M4F with floating point and DSP is really good for working with such things. The built in microphone and screen are also CRUCIAL for experimenting with ML on the edge. I saw there was also a camera supported by the MCU powering the board. This board is ideal for working with ML on the edge. If there was more time in the day I would build a lot more projects with this board!
So I’ve finished reading this book, what is the next step? What projects and more do you suggest?
Well after you have finished reading the book you can dive directly in the CircuitPython docs, experiment with the CircuitPython library and work with whatever sensors you like. The last chapter in the book heads toward that as well letting you explore different sensors. The project I suggest would depend on the board you have. Playing audio files, interfacing to a camera and probably doing some matrix LED stuff is something you can look at. There are hundreds of cool projects using CircuitPython and sometimes you just have to marvel at how far we’ve come with microcontrollers. The abstraction provided by python is powerful.since you can focus on testing concepts rather than the esoteric features of the language like you have to in C. Many projects just let you import libraries and require you to write less than 100 lines of code to do really complicated things.
If you really want to challenge yourself though, I would build a small obstacle avoidance robot using CircuitPython. You learn about all the sensors, actuators and syntax of the language in the book to be able to do that so it’s something you can look into. In the future once I have some free time, it’s something I definitely will look at doing a tutorial on, but the information you need is all there!
When would you know it’s time to write another book on CircuitPython?
Well I actually was hoping to do some more work with embedded ML and apply it to CircuitPython. I’ll be writing another one as soon as I have more than the handful of experiments I’m working on, cause I like to give readers at least two practical projects per chapter, but once I’m ready to write another one I’ll definitely let the community know and it wil linvolve ML with CircuitPython and possibly digital signal processing, good DSP books are rare as gold. .
I see a long future for CircuitPython, I think it can be very disruptive to how makers interact with microcontrollers. Instead of having to learn C for low level stuff, having python to do everything with is a really powerful concept. So once the traction keeps going, you’ll definitely see more books on CircuitPython from me.