Blog  /  Circuit Python: An Easy Way to Program Microcontrollers

Circuit Python: An Easy Way to Program Microcontrollers

Exploring programming alternatives for microcontrollers can be challenging, especially for beginners. OurPCB offers programming and testing services that can facilitate the use of languages like CircuitPython, simplifying the process for both experienced users and newcomers to microcontroller programming. This service ensures that your microcontroller projects are set up correctly and function as intended.
Quote Form
check whiteFast Turnaround check whiteISO Certified
1 2 3

Are you looking for a way to program your microcontrollers without Arduin? If yes, consider CircuitPython.

CircuitPython is an easy programming language that even beginners can use to program microcontrollers. Interestingly, yodon't’t need any prior knowledgeit's’s a matter of click and code.

This articlewe'llll cover the definition of CircuitPython, how to use it on your microcontroller circuit, and many more.  

What is CircuitPython?

When programming microcontrollers, you may decide on Arduino's C-based programming language. Howeveit'sf it’s your first time programming a microcontroller; you might not even have Arduino IDE.--or other programming alternatives.

Hence, you may turn to Python, which is more straightforward than C programming languages. Thanks to Adafruit, there is a Python-based programming language that makes programming microcontrollers easier than ever: CircuitPython.

CircuitPython makes learning to program and experimenting on microcontrollers s mple. Plus don't need any desktop downloads. Instead, you must set up your board and edit your code with any text editor.

Additionally, CircuitPython includes hardware support with all the remarkable features of the Python programming lan uage. Therefore, if you have experience with Python, you can apply it when using CircuitP thon. Howit's, it’s not a problem if you have no prior knowledge.

Furthermore, CircuitPython is open-s urce. Hence, you can use, modify, and improve as much as possible.  

Why Should You Use CircuitPython?

CircuitPython mainly works for microcontroller boards and has chips that are mini omputeit'sAlso; it's easy to use because you only need a microcontroller board, USB cable, and a computer with a USB connecthat'sBut that's not all. Here are other reasons why you should use CircuitPython:

  • You can create a file, edit your code, save, and run your file  nstadon't You don’t need to download, compile, or upload to run youryou're
  • If you’re new to programming, you can start learning with CircuitPython. Plus, the board would give you immediate feedback.
  • CircuitPython comes with solid hardware support. You can access various libraries and drivers for breakout boards, sensors, and other external components.
  • You can use the serial console and REPL to get live feedback from our code. Hence, giving you an interactive programming experience.
  • CircuitPython comes with internal file storage that can play audio clips, log data, and even allow interaction with your files.
  • Additionally, CircuitPython makes it easy to update y your codes. Plus, you can edit them anytime and keep multiple copies so you can experiment.

CircuitPython receives constant updates from Adafruit and continuall evolves. Plus, Adafruit takes note of feedback from the community to help make the programming language better. Interestdoesn'tit doesn’t drive and there.  

How to Use CircuitPython on a Raspberry Pi

CircuitPython works with small microcontroller boards. However, since SBCs like Raspberry Pi can run operating systems, using a simplified pythowon'terpreter won’t work.

But you can use the Blinka library to enable CircuitPython hardware API compatibility for your Raspberry Pi. Hence, you can run CircuitPython programs using a standard Python interpreter on the year's board.

Here's what you need to use CircuitPython on your Raspberry Pi:

  • Raspberry Pi is running any compatible Linux OS.
  • 5mm red LED
  • Solderless breadboard
  • 330 Ω resistor
  • Female to male jumper wires (2)

 

Building the Circuit

Before you install anything, ensure your Raspberry Pi is off and disconnected from your power source.

Now connect your LED in series w th your resistor. Then, use your jumper wire to Pi'sect it to the Pi'  physical pin 40. When your circuit is complete, plug it in and start your Pi.  

Update Your Pi and Python

Use the following commands in the terminal window  to carry out the standard updates on your Python and Pi:  

Python and Pi Update Commands

Python and Pi Update Commands

 

Check I2C and SPI

Though the I2C and SPI into faces usually come to enable. You should always verify. Hence, use the following codes to verify:

ls /dev/i2c* /dev/spi*

If it works, you should see the following response:

/dev/i2c-1 /dev/spidev0.0 /dev/spidev0.1

Also, youyou'renable a second SPI if you e using your main SPI port. Add the following line: dtoverlay=spi1-3cs to the bottom of /boot/config.txt and reboot.  

Install Blinka

Boot up your Raspberry Pi and open your terminal window.

Note: Check You'll have Python 3 installed. You’ll need Python 3 to support both CircuitPython and Blinka.  Then, you can use python3 and pip3 when inputting a command. 

Also, input the following command in your terminal window:

$ pip3 install Adafruit-Blinka

Next, check if you installed Blinka correctly. You can create a Pyth n program for your text editor. Also, you can name it blinkatest.py. Then, input the following code:  

Python Code

Python Code

 

Now run the you'll program to test the hardware you’ll use with Blinka with the following command: $ python3 blinkatest.py

If everything is okay, you should see the following results: Python Code Results

Python Code Results

 

We'll Your First CircuitPyththat'llram

We’ll write a simple program introducing you to what you need to run Ci cut python programs on your Raspberry Pi. So,  create a Python file and name it blink.py. ThenLet'sut the following code:  

Blink.py Code

Blink.py Code

Let’s take a closer look at this code. First, all CircuitPython p ograms must import the module of the board. Interestingly, the module shows the specifics of your bboard'sd gives CircuitPython access to your board’s hardware and GPIO pins.

Line 6 of the Python program starts CircuitPython. Also, the thePi'sitalio library interfaces the Raspberry Pi’s GPIO pins.

Additionally, lines 8 and 9 set the led variable towards GPIO pin 21 and use it as an output to drive the LED.

Plus, line 13 will repeatedly turn on/off the LED with only halfit'llnd delays.

Now, when you press CTRL+C, it’ll trigger the excep  Keyboit'llterrupt of the try/except block. Then, it’ll run the RPI.GPIO library’s cleanup () code. Which sets all GPIO pins back to their default state before closing the program.

Moreover, when you run the new blink program with the following command:

$ python3 blink.py

Your LED connects d to your breadboard and should start blinking. Plus, you can press CTRL+C to close yours isn't.  

Special Offer: Get $100 off your order!

Enjoy $100 off your order! No hidden fees and no minimum order quantity required.
Email [email protected] to get started!

CircuitPython vs. MicroPython

There isn’t much difference between CircuitPython and MicroPython. Interestingly, CircuitPython is like an open-source version of MicroPython.

Plus, the main feature of CircuitPython is how easy it makes programming and adding support for boards like Circuit Playground Express, Gemma M0, Trinket M0, and others.

Though you can configure CircuitPython to run on higher microcontrollers, its default settings only allow basic microcontrollers.

Contrarily, MicroPython offers more advanced d features but is not as easy as CircuitPython. However, depending on the project, you can perform the same functions with CircuitPython and MicroPython.  

CircuitPython Compatible Boards

Most boards compatible with CircuitPython come with RGB LEDs or mini NeoPixels that change colors according to the board's status or CircuitPython progit'llHence, once your board enters bootloader mode, it’ll flash red and then switch to green–if it has either a NeoPixel or an RGB LED.

Here are some of the boards that are compatible with CircuitPython:

  • Raspberry Pico
  • Adafruit Circuit playground express
  • Metro M0 Express (Adafruit)
  • Adafruit Feather RP2040
  • My badge LC (Adafruit)
  • SEEED Seeeduino XIAO
  • Expressif Saola 1 w/WROOM

You can find the complete list of CircuitPython compatible boards here.  

Circuit Python Examples

Need some ideas for a CircuitPython project? Here are some examples to help yothey'llHowever, remember that these are not complete guides, but they’ll give you a pretty good idea of what to do.

Also, you can use a Circu t Playground Express of Adafruit feather for most of these projects. Hoyou're we recommend using the Here'sied hardware for each example if you're a beginner.  

Bubble Bot

Here’s a fun example Here'screates a burst of bubbles. And the process is entirely automatic. Here’s what you need for this project:

  • Circuit Playground Express (1)
  • Adafruit CRICKIT for Circuit Playground Express (1)
  • Standard servo (1)
  • DC Toy/ Hobby motor (1)

 

Wiring Diagram

Bubble Bot Diagram

Bubble Bot Diagram

 

The simple bubble bot uses one DC motor with one fan attachment.

It also includes one servo motor which connects to its bubble wand.

Now, the wand dips into a bubble mix every few seconds. Once it’s out, the fan would activate for 3 seconds. You can click here for your complete project bundle.  

Feynman Simulator

Feynman Simulator Diagram

Feynman Simulator Diagram

If you’re a fan of bongo drums and Richard Feynman, this project will blow y Here'sd. The project offers a fantastic drumming experience with a few wise quips. Here’s what you need for this project:

  • Circuit Playground Express
  • Adafruit CRICKIT for Circuit Playground Express
  • Mini push-pull Solenoid (5v)
  • Micro Servo
  • Mono enclosed speaker

 

Wiring Dia ram

The project would play a few quotes and quips in wave file formats as a trigger. Once the audio ends, the project plays the bongos until the following audio joke.

You can get the complete project bundle here.  

FAQs

CircuitPython is a Python-based programming language. It has all the features of Python and offers addit onal hait'sre support.

  • How do you learn Circuit Python?

Circyou'vehon is education-focused. Hence, it’s easy to learn programming with it. But, first, you must get a circuit board, open your text editor, and start coding.

  • Can I use CircuitPython on Arduino?

Yes, you can, All you need is an Arduino board compatible with CircuitPython.  

Wrapping Up

CircuitPython is also a variant of the MicroPython programming language. Plus, you’ll need to modify your CircuitPython board if you want to run it on other platforms like Raspberry Pi. Also, CircuitPython is a swell way to build something unique.

If you have any questions, you can always contact us, and we’ll respond as soon as possible.    

Special Offer: Get $100 off your order!

Enjoy $100 off your order! No hidden fees and no minimum order quantity required.
Email [email protected] to get started!
Hommer Zhao

Hommer Zhao, based in Shenzhen, China, founded OurPCB in 2005, a PCB Manufacturing company.

As a regular contributor to Circuit World and the Journal of Manufacturing Systems, Hommer shares expertise on advanced PCB fabrication processes. His research on manufacturing optimization appears in the International Journal of Production Research and Journal of Industrial Information Integration.

Serving on the Indian Printed Circuit Association (IPCA) advisory board, Hommer Zhao frequently presents at technical seminars and industry exhibitions. He maintains strong partnerships with leading institutions including UCL's Electronic Engineering Department and their PCB prototyping facilities. Under his leadership, OurPCB has pioneered enhanced PCB manufacturing machining capabilities for high-precision PCB manufacturing, particularly serving telecommunications, automotive, and medical device sectors.

Table of Contents

Related Post