Daily tips and tricks from the experts at Adafruit!
View this email in your browser

sysfs is dead! long live libgpiod! libgpiod for Linux & Python running hardware

Earlier this year we wrote about the announcement of mainline kernel integration of libgpiod on the Adafruit blog – 2/10/2018.

libgpiod is intended to be a fast kernel-level-supported method for writing/reading/monitoring GPIO pins on various Linux boards, replacing the two main methods we see these days: sysfs file pokin’ and devmem twiddling.

With sysfs style control, you end up with files such as /sys/class/gpio/gpio16 (for pin #16) that you can write and read from to set direction and read values. it works ok, and is very easy to use with shell scripts, but is clunky from C or Python, and is slow and incomplete (for example, pullup/down’s are not supported).

With devmem twiddling, you open up a file, point directly to chip memory, and start poking and prodding at the registers directly. This is somewhat similar to older computer’s ‘peek’ and ‘poke’ commands, or the microcontroller style PORTB |= 0x01. Benefits? it is heckin’ fast. Downsides are that it’s a horrible idea to poke into memory, and you end up having to make register maps for each processor and revisions because the registers move around. You can see some example code here for our DHT driver for Raspberry Pi…

…and then this different code for a BeagleBone (the register map is different).

As you can tell, this quickly becomes hard to support and it’s dangerous – you need to be running as root and its incredibly easy to accidentally poke the wrong location.

With more Linux boards coming out with GPIO (there’s probably 4 more released since we wrote this post), having a consistent, reliable, complete GPIO interface is pretty important to avoid icky unmaintainable code. So we’re pretty psyched about libgpiod. From our experiments, it’s much much faster than sysfs. It’s not as fast as mem twiddling, but that’s not too surprising, there’s still kernel messages and error checking done. A Pi 3 got us 400Khz pin output toggles in a loop in C, 100KHz in Python examples, and that’s pretty good for bitbanging. (For SPI or I2C, use the hardware peripherals, they can go multi-MHz and can be shared between processes!)

We’ve started with a basic ‘collect gpio pulses and store them in a circular buffer program‘, written by Brennen Bearnes.

This is basically code that will replace our Python DHT driver, and it has the benefit of being forward compatible with any other Linux board that runs a 4.8+ kernel. We’ll slowly be replacing other CircuitPython code to use libgpiod, so that we can have broad support for CircuitPython on a Raspberry Pi, BeagleBone or Onion.io.

There’s not a lot of libgpiod code out there, and libgpiod doesn’t come stock on Linux distros yet which may be why its taking a little while to catch on. There’s bindings for C and Python. Here’s a script that can help you get started by compiling it for you.

If you have any controlling votes in a distro, please have libgpiod available through your package manager! The latest code is here, and as you can tell there’s a lot of active development ?.

CircuitPython sounds handy in HackSpace magazine!

Handy Sampler in the latest issue of HackSpace magazine – a sound glove with HalloWing! Create your own wearable audio sampler glove using CircuitPython, by Sophy Wong page 96 – PDF.

News from around the web!

The prototyping workshop held at El Lab Coworking in Cali, Colombia was successfully carried out using CircuitPython – Grafo Labs.

This should put even Darth Vader in a good mood. Just in time for the Holidays. Adafruit Feather M4 + propmaker wing + Neopixel lightsaber via TwitterGitHub.

One of the goodies from the Hackaday Superconference was an Adafruit HalloWing, and @todbot made a Jolly Wrencher case for this skull-shaped circuit board! – YouTube.

Here’s a test of the Crunchable Lunchbox Synth front panel and CV/audio outputs, temporary OLED display for troubleshooting, CircuitPython 3.1.1, Adafruit Feather M4 Express by Cedar Grove – YouTube.

Cool little game being developed in CircuitPython on a NeoTrellis by erist23 on Instagram.

CircuitPython vs MicroPython: Key Differences by Core Electronics – YouTube.

Andreas Spiess published the video “Time to Say Goodbye to Arduino and Go On to Micropython/ Adafruit Circuitpython?” on Nov 17, 2018. There are already 1,039 comments and 139,401 views – YouTube. According to the MicroPython forums, there might be a follow up video soon – MicroPython.org.

More progress on the Feather-form-factor Linux board by Groguard – Twitter.

Is the air quality so bad that you need to wear a respirator outside? Micropython Air Quality Index Crystal ? built using an Adafruit Feather HUZZAH ESP8266, NeoPixel ring, and selenite crystal, by AndrewGitHub.

uPyCraft is an MicroPython programmable IDE – uPyCraft IDE.

PFalcon’s awesome-micropython list has some updatesGitHub.

Concurrency and the Internet of Things. What is concurrency? Why does it matter for Internet of Things applications? – YouTube.

MicroPython on bare metal Raspberry Pi Zero / Zero WGitHub.

Decode Morse Code directly via a microphone connected to an ESP32 microcontroller board – GitHub.

Self-Driving Pi Car is a deep neural network based self-driving car, that combines Lego Mindstorms NXT with the computational power of a Raspberry Pi 3 – GitHub.

RaspiWiFi is a program to headlessly configure a Raspberry Pi’s WiFi connection using using any other WiFi-enabled device (much like the way a Chromecast or similar device can be configured) – GitHub.

µGUI is a free and open source graphic library for embedded systems. It is platform-independent and can be easily ported to almost any microcontroller system – GitHub.

Stop Teaching C++ … as a First Programming Language, via Twitter, by iboB.

By Welcoming Women, Python’s Founder Overcomes Closed Minds In Open Source, by Alexa MoralesForbes.

What do do with your computer science career by Guido van Rossum.

#ICYDNCI What was the most popular, most clicked link, in last week’s newsletter? Fennec Toys at DesignerCon CircuitPython powered art.

Adafruit CircuitPython Weekly for 26 November 2018 diode.zone YouTube

PyDev of the week: Reimar Bauer from Mouse vs Python

Made with Mu Contributor Focus: Zander Brown

An excellent new series on Made with Mu! Contributor Focus: Mu is not a solo effort. Many folks have contributed to Mu, and I will be eternally grateful for their work. With the spirit of recognising the voluntary contributions of others in mind, I’m going to write about some of our most prodigious programmers. First up is Zander Brown – madewithmu.

Mu tries to make it as easy as possible to get started with programming but aims to help you graduate to “real” development tools soon after. Everything in Mu is the “real thing” but presented in as simple and obvious way as possible. It’s like the toddling stage in learning to walk: you’re finding your feet and once you’re confident, you should move on and explore! Put simply, Mu aims to foster autonomy. Try out Mu today! – codewith.mu.

Coming soon

A video with the M4 Grand Central, ATSAMD51P20 with 1 MB of FLASH, 256K SRAM, tons of of pins! Runs ‪CircuitPython and has the‬ same form factor as ‪an Arduino‬ MEGA – YouTube.

New Learn Guides!

NeoTrellis M4 Animated Dice Roller from Dave Astels

Thanksgiving Robotic Turkey Hand with Circuit Playground Express and Crickit from Dano Wall

Adafruit STEMMA Soil Sensor – I2C Capacitive Moisture Sensor from Ladyada

Trellis M4 Beat Sequencers from John Park

Classic MIDI Synth Control with Trellis M4 from John Park

Updated Guides – Now With More Python!

You can use CircuitPython on Raspberry Pi! We’re updating all of our CircuitPython guides to show how to wire up sensors to your Raspberry Pi, and load the necessary CircuitPython libraries to get going using them with Python. We’ll be including the updates here so you can easily keep track of which sensors are ready to go. Check it out!

RGB LCD Shield

CircuitPython Libraries!

CircuitPython support for hardware continues to grow. We are adding support for new sensors and breakouts all the time, as well as improving on the drivers we already have. As we add more libraries and update current ones, you can keep up with all the changes right here!

For the latest drivers, download the Adafruit CircuitPython Library Bundle.

If you’d like to contribute, CircuitPython libraries are a great place to start. Have an idea for a new driver? File an issue on CircuitPython! Interested in helping with current libraries? Check out this GitHub issue on CircuitPython for an overview of the State of the CircuitPython Libraries, updated each week. We’ve included open issues from the library issue lists, and details about repo-level issues that need to be addressed. We have a guide on contributing to CircuitPython with Git and Github if you need help getting started. You can also find us in the #circuitpython channel on the Adafruit Discord. Feel free to contact Kattni (@kattni) with any questions.

You can check out this list of all the CircuitPython libraries and drivers available.

The current number of CircuitPython libraries is 114!

Updated Libraries!

Here’s this week’s updated CircuitPython libraries:

Upcoming events!

TriPython November 2018 Meeting: Tracking State and Events In CircuitPython. Josh Johnson presents: “In building novel human/computer interaction devices using CircuitPython. This Thursday, November 29, 2018, 7:00 PM to 9:00 PM, 1791 Varsity Drive #200 · Raleigh, NC – MeetUp.

May 2019 Cleveland, Ohio! The PyCon 2019 conference, which will take place in Cleveland, is the largest annual gathering for the community using and developing the open-source Python programming language. It is produced and underwritten by the Python Software Foundation, the 501(c)(3) nonprofit organization dedicated to advancing and promoting Python. Through PyCon, the PSF advances its mission of growing the international community of Python programmers – PyCon.

Latest releases

CircuitPython’s stable release is 3.1.1 and its unstable release is 4.0.0-alpha.3. New to CircuitPython? Start with our Welcome to CircuitPython Guide.

20181126 is the latest CircuitPython library bundle.

v1.9.4 is the latest MicroPython release. Documentation for it is here.

3.7.1 is the latest Python release.

Call for help – CircuitPython messaging to other languages!

We recently posted on the Adafruit blog about bringing CircuitPython messaging to other languages, one of the exciting features of CircuitPython 4.x is translated control and error messages. Native language messages will help non-native English speakers understand what is happening in CircuitPython even though the Python keywords and APIs will still be in English. If you would like to help, please post to the main issue on GitHub and join us on Discord.

We made this graphic with translated text, we could use your help with that to make sure we got the text right, please check out the text in the image – if there is anything we did not get correct, please let us know. Dan sent me this handy site too.

jobs.adafruit.com is back

jobs.adafruit.com has returned and folks are posting their skills (including CircuitPython) and companies are looking for talented makers to join their companies – from Digi-Key, to hackaday, Microcenter, Raspberry Pi and more. This week’s featured job is: Engineering Technician – Dame Products.

9,000 thanks!

The Adafruit Discord community where we do all our CircuitPython development in the open reached over 9,000 humans, thank you! Join today! https://adafru.it/discord

ICYMI – In case you missed it

The wonderful world of Python on hardware! This is our first video-newsletter-podcast that we’re trying out! The news comes from the Python community, discord, Adafruit communities and more. It’s part of the weekly newsletter here, then we have a segment on ASK an ENGINEER and this is the video slice from that! – Vide. This video is a recap of last week’s newsletter. The complete Python on Hardware weekly VideoCast playlist is here.

Contribute!

The CircuitPython Weekly Newsletter is a CircuitPython community-run newsletter emailed every Tuesday. It highlights the latest CircuitPython related news from around the web including Python and MicroPython developments. To contribute, edit next week’s draft on GitHub and submit a pull request with the changes. Join our Discord or post to the forum for any further questions.