• sales

    +86-0755-88291180

Raspberry Pi 1.14inch 1.3inch LCD - CircuitPython & RasPi User Guide

CircuitPython Libraries on Linux & Raspberry Pi

The next obvious step is to bring CircuitPython back to 'desktop Python'. We've got tons of projects, libraries and example code for CircuitPython on microcontrollers, and thanks to the flexibility and power of Python it's pretty easy to get that code working with micro-computers like Raspberry Pi or other 'Linux with GPIO pins available' single board computers.

We are not running the CircuitPython interpreter itself on the Linux machine. But we are running Python code written to use the CircuitPython hardware API (busio.I2Cbusio.SPI, etc.)

We'll use a special library called adafruit_blinka (named after Blinka, the CircuitPython mascot) to provide the layer that translates the CircuitPython hardware API to whatever library the Linux board provides. For example, on Raspberry Pi we use the python RPi.GPIO library. For any I2C interfacing we'll use ioctl messages to the /dev/i2c device. For SPI we'll use the spidevpython library, etc. These details don't matter so much because they all happen underneath the adafruit_blinka layer.

The upshot is that any code we have for CircuitPython will be instantly and easily runnable on Linux computers like Raspberry Pi.

In particular, we'll be able to use all of our device drivers - the sensors, led controllers, motor drivers, HATs, bonnets, etc. And nearly all of these use I2C or SPI!

 

Wait, isn't there already something that does this - GPIO Zero?

Yes! We like and use GPIO Zero a lot, its an excellent hardware interfacing library for Raspberry Pi. It's great for digital in/out, analog inputs, servos, some basic sensors, etc. In particular, one cool thing it does is thread/event management so you can have code run, say, when a button is pressed.

GPIO Zero excels at that, but doesn't cover SPI/I2C sensors or drivers, which is where we got stuck: for each sensor we had we'd write a driver in C/C++ for Arduino, CircuitPython using our hardware API, and then Python using smbus or similar.

By letting you use CircuitPython on Raspberry Pi via adafruit_blinka, you can unlock all of the drivers and example code we wrote! And you can keep using GPIO Zero for pins, buttons and LEDs. We save time and effort so we can focus on getting code that works in one place, and you get to reuse all the code we've written already.

What about other Linux SBCs?

Plus, we're adapting and extending adafruit_blinka to support other boardssuch as Allwinners and BeagleBone, even some smaller linux boards like Onion.io will be able to run CircuitPython code.

If you have a board you'd like to adapt check out the adafruit_blinka code on github, pull requests are welcome as there's a ton of different Linux boards out there! You'll need to add a detection element so we can tell what board you're running on, then the pin definitions into adafruit_blinka above. As long as you're running a modern kernel, you'll have libgpiod for GPIO, smbus for I2C and spidev for SPI all ready to go.

TAG: JETSON-IO-BASE-A user Guid Milk-V Duo S UART Serial Console​ ESP32 S3 4inch LCD Development Board 480x480 TouchScreen Display TVBOX LVGL HMI Sensor CAN RS485 2.13Inch E-Ink 1.83inch LCD TouchScreen Display 240×280 NV3030B Arduino Raspberry Pi ESP32S3 Pico STM32 Raspberry Pi Mini TV X1200 Raspberry Pi 5 UPS Board Uninterruptible Power Supply For 18650-Li-Battery (NOT includ) 8.8inch LCD 1920x480 Computer PC Monitor Display Secondary Screen TypeC USB CPU RAM Attitude Sensor Industrial Isolated Converter RP2040 1.5inch LCD Raspberry Pi 5 PCIe to M.2 NVME SSD And Gigabit Ethernet RJ45 HAT RTL8111H M_KEY For 2230/2242/2260/2280 ESP32 Thermal imaging camera Raspberry Pi 5 D Pi5 Active Cooler Milk-V Duo S eMMC version firmware burning Raspberry Pi 2-Channel Isolated CAN Bus Expansion HAT Dual Chips Solution Built-In Multi Protections SpotPear FT232RNL USB TO TTL Industrial UART Can For Raspberry Pi 5 Terminal Debug Milk-V Duo Camera