Adafruit_BusIO-ification for prettier, easier-to-maintain Arduino libraries

Ever since we’ve started writing/porting CircuitPython drivers for sensors and displays and such, we’ve fallen in love with `busio` – our generalized I2C and SPI API which takes out the repetitive parts of writing drivers: i2c address scanning, writing registers, reading chunks of data and concatenating it, dealing with repeated-start chips. After doing a bunch of drivers, we started looking at our Arduino libraries with an itchy nose. Sure they worked, but they’d been building up a decade of cruft and low-level interfacing.

So we’re doing a bit of a scrubbing for our older libraries, to ‘busio-ify’ them. Carter has been taking the lead and it is soooooooooo satisfying to look at the pull requests. For example, this one was approved today: https://github.com/adafruit/Adafruit_TCS34725/pull/47/files

(yes we use a stack single-element array for readability. yes we are well aware we could pass in the local’s address. yes its on purpose)

01

Because Adafruit_BusIO now does the annoying “we can only read/write 32 bytes at a time but sometimes we have a larger buffer” management, we have lovely diffs like this one from https://github.com/adafruit/Adafruit_AMG88xx/pull/24/files

02

We’re so happy to see this happen. Adafruit_BusIO handles I2C, hardware and software SPI with fast-io bitbanging. It also can do things like manage ‘registers’ and variable-size/offset bit-fields and will do all the error-prone math for you. There’s more memory used both flash and RAM, but that’s what good reusable-software engineering practice is all about!

Check out the Doxygen docs here https://adafruit.github.io/Adafruit_BusIO/html/annotated.html and our examples here https://adafruit.github.io/Adafruit_BusIO/html/annotated.html

Then, tune in to the Adafruit GitHub repo to see the libraries as they’re updated each week to BusIO.


Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7:30pm ET! To join, head over to YouTube and check out the show’s live chat and our Discord!

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Join over 38,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython – The easiest way to program microcontrollers – CircuitPython.org


New Products – Adafruit Industries – Makers, hackers, artists, designers and engineers! — New Products 11/15/2024 Featuring Adafruit bq25185 USB / DC / Solar Charger with 3.3V Buck Board! (Video)

Python for Microcontrollers – Adafruit Daily — Python on Microcontrollers Newsletter: A New Arduino MicroPython Package Manager, How-Tos and Much More! #CircuitPython #Python #micropython @ThePSF @Raspberry_Pi

EYE on NPI – Adafruit Daily — EYE on NPI Maxim’s Himalaya uSLIC Step-Down Power Module #EyeOnNPI @maximintegrated @digikey

Adafruit IoT Monthly — The 2024 Recap Issue!

Maker Business – Adafruit Daily — Apple to build another chip at TSMC Arizona

Electronics – Adafruit Daily — SMT Tip – Stop moving around!

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !


No Comments

No comments yet.

Sorry, the comment form is closed at this time.