• 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: Raspberry Pi 5 DSI SIM8260G M2 3G/4G/5G/GNSS/GPS Sub-6G PCIe M.2 Moudle For LTE-A/NSA/SA For DFOTA /VoLTE For SIMCOM English Character Display Principle Raspberry Pi 1.54inch OLED 1.38MP Global Shutter Camera ISG1321 For Luckfox Pico Zero USB TO 4CH RS485 User Guide NVIDIA Jetson spotpear 7.5 inch Passive NFC e-Paper BW Display 7.5inch E-ink Screen No Need Battery Wireless Powered Data Transfer Core1121 LoRa LR1121 HF LF SPI For Sub-GHz and 2.4GHz Raspberry-Pi-Game-1.54inch-LCD-touchscreen-display-ST7789 Spotpear Raspberry Pi CM5 IO BASE B Mini Board a Base Development Platform Compute Module 5 IO Board with EEPROM And Encryption chip Serial UART Bus Servo TTL ST3235 30KG.CM Magnetic Encoder 360° High Precision And Large Torque Raspberry Pi UGV Beast ROS2 PT AI OpenCV Robot Car MediaPipe Raspberry Pi 15.6 inch QLED Quantum Dot Display 1920x1080 Capacitive Touchscreen For Computer PC/Jetson/Game $167.99 X1200 Raspberry Pi 5 UPS Board Uninterruptible Power Supply For 18650-Li-Battery (NOT includ) Raspberry Pi Pico 2 Tiny RP2350B RP2350-Linux Mini Development Board with PSRAM-8MB Or Without PSRAM PI5 Case Rasperry Pico 2 RP2350 7.3 inch e-Paper Ink Display E6 Full Color Electronic PhotoPainter 800x480 For Calendar/Quotes/Paintings/Posters