# PixelDust Digital Sand for CircuitPython

## Overview

https://youtube.com/shorts/zB_uiMnEpnE

There are [several learn guides](https://learn.adafruit.com/search?q=PixelDust) that have demonstrations of simulated sand particles. This makes a great demonstration with an accelerometer and LED matrix or small display. Until now, all of these demos required Arduino or similar lower level compiled firmware, or even a full on Raspberry Pi. With&nbsp;[CircuitPython shifting gears into Turbo](https://learn.adafruit.com/circuitpython-turbo)&nbsp;and the recent addition of&nbsp;[Picogame](https://github.com/adafruit/circuitpython/pull/11199), it's possible to run projects like this in CircuitPython.

Turbo modules, compiled with Viper, are able to crunch numbers super fast. Numbers like the ones used to simulate gravity and collisions for a lot of particles. Picogame is more efficient at rendering canvas-style graphics of this sort than `displayio` which keeps the demo rendering smoothly on the Metro RP2350 + TFT Shield.

### CircuitPython Turbo: Go Blinka! - Overview

[CircuitPython Turbo: Go Blinka!](https://learn.adafruit.com/circuitpython-turbo)
[Overview](https://learn.adafruit.com/circuitpython-turbo/overview)
There are two versions of the hardware for this guide. Use the parts for your version: A Metro TFT or MatrixPortal S3.

## Parts - Metro TFT Version
Featured
### Adafruit Metro RP2350

[Adafruit Metro RP2350](https://www.adafruit.com/product/6003)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town". This train is piled high with hardware that complements the Raspberry Pi RP2350 chip to make it an excellent...

In Stock
[Buy Now](https://www.adafruit.com/product/6003)
[Related Guides to the Product](https://learn.adafruit.com/products/6003/guides)
![Angled shot of black, credit card-sized microcontroller with stacking headers.](https://cdn-shop.adafruit.com/640x480/6003-06.jpg)

Featured
### Adafruit Metro RP2350 with PSRAM

[Adafruit Metro RP2350 with PSRAM](https://www.adafruit.com/product/6267)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town" and a bonus stop at "8 Megabytes of PSRAM village". This train is piled high with hardware that...

Out of Stock
[Buy Now](https://www.adafruit.com/product/6267)
[Related Guides to the Product](https://learn.adafruit.com/products/6267/guides)
![Angled shot of black, credit card-sized microcontroller.](https://cdn-shop.adafruit.com/640x480/6267-00.jpg)

Featured
### 2.8" TFT Touch Shield for Arduino with Resistive Touch Screen v2

[2.8" TFT Touch Shield for Arduino with Resistive Touch Screen v2](https://www.adafruit.com/product/1651)
Spice up your Arduino project with a beautiful large touchscreen display shield with built in microSD card connection. This TFT display is big (2.8" diagonal) bright (4 white-LED backlight) and colorful (18-bit 262,000 different shades)! 240x320 pixels with individual pixel control. It...

In Stock
[Buy Now](https://www.adafruit.com/product/1651)
[Related Guides to the Product](https://learn.adafruit.com/products/1651/guides)
![Brown polished fingers holding a 2.8" TFT Touch Shield for Arduino with Resistive Touch Screen with one hand and a finger from the other hand drawing a heart. ](https://cdn-shop.adafruit.com/640x480/1651-00.jpg)

Featured
### Adafruit MPU-6050 6-DoF Accel and Gyro Sensor - STEMMA QT Qwiic

[Adafruit MPU-6050 6-DoF Accel and Gyro Sensor - STEMMA QT Qwiic](https://www.adafruit.com/product/3886)
I mew, you mew we&nbsp;_all_&nbsp;mew for IMU! The MPU-6050 is what we call "an oldie but goodie" - this popular triple-axis accelerometer plus gyro combo has been a staple of electronic projects for years, and we've finally gotten around to making a breakout for...

In Stock
[Buy Now](https://www.adafruit.com/product/3886)
[Related Guides to the Product](https://learn.adafruit.com/products/3886/guides)
![Video of a white hand moving a sensor around that connected to an OLED and white breadboard.](https://cdn-shop.adafruit.com/product-videos/640x480/3886-06.jpg)

Featured
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
![Angled of of JST SH 4-Pin Cable.](https://cdn-shop.adafruit.com/640x480/4399-00.jpg)

### Part: Mounting Putty
quantity: 1
1x Small Glob

## Parts - Matrix Portal S3 Version
Featured
### Adafruit Matrix Portal S3 CircuitPython Powered Internet Display

[Adafruit Matrix Portal S3 CircuitPython Powered Internet Display](https://www.adafruit.com/product/5778)
Folks love our [wide selection of RGB matrices](https://www.adafruit.com/category/327) and accessories&nbsp;for making custom colorful LED displays... and our RGB Matrix Shields and FeatherWings can be quickly soldered together to make the wiring much easier. But what if we made it...

In Stock
[Buy Now](https://www.adafruit.com/product/5778)
[Related Guides to the Product](https://learn.adafruit.com/products/5778/guides)
![Video of Adafruit Matrix Portal S3 linked up to a matrix displaying the "Adafruit Matrix Portal" in white letters and red, green and blue circles jumping around. ](https://cdn-shop.adafruit.com/product-videos/640x480/5778-06.jpg)

Featured
### 64x64 RGB LED Matrix Panel - 2mm Pitch

[64x64 RGB LED Matrix Panel - 2mm Pitch](https://www.adafruit.com/product/5362)
Wintertime can be rough in the city. The sky is gray. The weather&nbsp;is unpredictable. So slough off those seasonal blues with&nbsp;some&nbsp;Times Square razzle dazzle from this sweet, ultra-high-density **64x64 RGB LED Matrix**. These panels are typically used to make video...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5362)
[Related Guides to the Product](https://learn.adafruit.com/products/5362/guides)
![Video of a person rotating an LED matrix. The animation resembles falling colored sand.](https://cdn-shop.adafruit.com/product-videos/640x480/5362-04.jpg)

Or a 64x64 RGB LED Matrix Panel with 2.5mm, or 3mm pitch.

# PixelDust Digital Sand for CircuitPython

## Metro RP2350 + TFT

This section of the guide covers a version of the Pixel Dust demo that runs on the Metro RP2350 with a TFT shield and accelerometer breakout. It simulates more sand particles than the Matrix Portal version.

This project can run on the Metro RP2350 with, or without, PSRAM. The project uses an MPU-6050 accelerometer breakout to determine the direction that gravity should move within the simulation. It can be easily adapted to other accelerometer breakouts by swapping in a different library.&nbsp;

![Metro RP2350 with TFT shield and accelerometer showing the sand simulation demo](https://cdn-learn.adafruit.com/assets/assets/000/146/390/medium640thumb/circuitpython_metro_rp2350_sand_simulation.jpg?1789572117)

## Parts
### Adafruit Metro RP2350

[Adafruit Metro RP2350](https://www.adafruit.com/product/6003)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town". This train is piled high with hardware that complements the Raspberry Pi RP2350 chip to make it an excellent...

In Stock
[Buy Now](https://www.adafruit.com/product/6003)
[Related Guides to the Product](https://learn.adafruit.com/products/6003/guides)
![Angled shot of black, credit card-sized microcontroller with stacking headers.](https://cdn-shop.adafruit.com/640x480/6003-06.jpg)

### Adafruit Metro RP2350 with PSRAM

[Adafruit Metro RP2350 with PSRAM](https://www.adafruit.com/product/6267)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town" and a bonus stop at "8 Megabytes of PSRAM village". This train is piled high with hardware that...

Out of Stock
[Buy Now](https://www.adafruit.com/product/6267)
[Related Guides to the Product](https://learn.adafruit.com/products/6267/guides)
![Angled shot of black, credit card-sized microcontroller.](https://cdn-shop.adafruit.com/640x480/6267-00.jpg)

### 2.8" TFT Touch Shield for Arduino with Resistive Touch Screen v2

[2.8" TFT Touch Shield for Arduino with Resistive Touch Screen v2](https://www.adafruit.com/product/1651)
Spice up your Arduino project with a beautiful large touchscreen display shield with built in microSD card connection. This TFT display is big (2.8" diagonal) bright (4 white-LED backlight) and colorful (18-bit 262,000 different shades)! 240x320 pixels with individual pixel control. It...

In Stock
[Buy Now](https://www.adafruit.com/product/1651)
[Related Guides to the Product](https://learn.adafruit.com/products/1651/guides)
![Brown polished fingers holding a 2.8" TFT Touch Shield for Arduino with Resistive Touch Screen with one hand and a finger from the other hand drawing a heart. ](https://cdn-shop.adafruit.com/640x480/1651-00.jpg)

### Adafruit MPU-6050 6-DoF Accel and Gyro Sensor - STEMMA QT Qwiic

[Adafruit MPU-6050 6-DoF Accel and Gyro Sensor - STEMMA QT Qwiic](https://www.adafruit.com/product/3886)
I mew, you mew we&nbsp;_all_&nbsp;mew for IMU! The MPU-6050 is what we call "an oldie but goodie" - this popular triple-axis accelerometer plus gyro combo has been a staple of electronic projects for years, and we've finally gotten around to making a breakout for...

In Stock
[Buy Now](https://www.adafruit.com/product/3886)
[Related Guides to the Product](https://learn.adafruit.com/products/3886/guides)
![Video of a white hand moving a sensor around that connected to an OLED and white breadboard.](https://cdn-shop.adafruit.com/product-videos/640x480/3886-06.jpg)

### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
![Angled of of JST SH 4-Pin Cable.](https://cdn-shop.adafruit.com/640x480/4399-00.jpg)

# PixelDust Digital Sand for CircuitPython

## Install CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

Info: This project requires both turbo module support and picogame enabled. On the Metro RP2350 Picogame was enabled in [PR 11474](https://github.com/adafruit/circuitpython/pull/11474) on 9/29/26. It's not in any released versions of CircuitPython yet. The button below links directly to the firmware built from #11474.

[Download CircuitPython Firmware](https://adafruit-circuit-python.s3.amazonaws.com/bin/adafruit_metro_rp2350/en_US/adafruit-circuitpython-adafruit_metro_rp2350-en_US-20260929-main-PR11474-5c54519.uf2)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/655/medium640/install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg?1618943202)

![](https://cdn-learn.adafruit.com/assets/assets/000/135/292/medium800/adafruit_products_boot_reset_btn_highlights.png?1739467365)

To enter the bootloader, hold down the **BOOT/**** BOOTSEL button**(highlighted in red above), and while continuing to hold it (don't let go!), press and release the**reset button**(highlighted in red or blue above).&nbsp;**Continue to hold the BOOT/BOOTSEL button until the RP2350 drive appears!**

If the drive does not appear, release all the buttons, and then repeat the process above.

You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **RP2350**.

&nbsp;

Drag the **adafruit-circuitpython-_boardname_-_language_-_version_.uf2** file to **RP2350.**

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111518.png](https://cdn-learn.adafruit.com/assets/assets/000/132/253/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111518.png?1726067809)

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111742.png](https://cdn-learn.adafruit.com/assets/assets/000/132/254/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111742.png?1726067866)

The **RP2350** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it, you're done! :)

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111843.png](https://cdn-learn.adafruit.com/assets/assets/000/132/255/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111843.png?1726067932)

## Safe Mode

You want to edit your **code.py** or modify the files on your **CIRCUITPY** drive, but find that you can't. Perhaps your board has gotten into a state where **CIRCUITPY** is read-only. You may have turned off the **CIRCUITPY** drive altogether. Whatever the reason, safe mode can help.

Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode _bypasses any code in_ **boot.py** (where you can set **CIRCUITPY** read-only or turn it off completely). Second, _it does not run the code in_ **code.py**. And finally, _it does not automatically soft-reload when data is written to the_ **CIRCUITPY** _drive_.

Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the **CIRCUITPY** drive.

### Entering Safe Mode
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)

### In Safe Mode

If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.

If you connect to the serial console, you'll find the following message.

```terminal
Auto-reload is off.
Running in safe mode! Not running saved code.

CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.
```

You can now edit the contents of the **CIRCUITPY** drive. Remember, _your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode._

## Flash Resetting UF2

If your board ever gets into a really _weird_ state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RP2350. which will do a 'deep clean' on your Flash Memory. **You will lose all the files on the board** , but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.

[Download flash erasing "nuke" UF2 for RP2350](https://cdn-learn.adafruit.com/assets/assets/000/132/526/original/rp2350_flash_nuke.uf2)
# PixelDust Digital Sand for CircuitPython

## Assemble

![Metro RP2350 laid out next to 2.8" TFT shield and MPU-6050 accelerometer breakout, STEMMA QT cable, and a small glob of mounting putty.](https://cdn-learn.adafruit.com/assets/assets/000/146/393/medium800/circuitpython_metro_sand_parts.png?1789575749 )

Assembly for this project is very simple thanks to the plug and play nature of the TFT shield and STEMMA QT connectors for the accelerometer breakout.

First place the TFT shield on top of the Metro RP2350 and gently press it down into place. It should be fully seated and aligned properly on all of the header pins along the two edges and the 2x3 SPI pin connector near the short side, next to the SD card slot and boot button.

Next, connect the accelerometer to the Metro using a small STEMMA QT cable.

Finally, use a small amount of mounting putty to stick the accelerometer to the side of the Metro and TFT shield. Put the putty on the back of the accelerometer breakout, then press it firmly onto the side of the Metro's header pins.

![Metro RP2350 with TFT shield on top and accelerometer breakout stuck to the side of the header pins, connected via STEMMA QT cable.](https://cdn-learn.adafruit.com/assets/assets/000/146/394/medium640/circuitpython_metro_sand_flat_profile.png?1789575810)

![Metro RP2350 with TFT shield connected and accelerometer breakout stuck to the side of the header pins, connected via STEMMA QT cable.](https://cdn-learn.adafruit.com/assets/assets/000/146/395/medium640/circuitpython_metro_sand_standing_profile.png?1789575832)

![Metro RP2350 with TFT shield connected standing up tall ways to show the 2x3 SPI connector on the short side near the sdcard slot.](https://cdn-learn.adafruit.com/assets/assets/000/146/400/medium640/circuitpython_metro_sand_standing_end.png?1789651474)

# PixelDust Digital Sand for CircuitPython

## Code

## Getting the Program's Files

Viper and native compiled .mpy files are on the cutting edge of support in CircuitPython. The Learn project bundler has not yet been adapted to work with them. Use the green button below to download the project files instead of the usual "Download Project Bundle" button embedded with the code contents.

Connect your board to your computer via a known good data+power USB cable. The board should show up in your File Explorer/Finder (depending on your operating system) as a flash drive named **CIRCUITPY**.

Extract the contents of the zip file, copy the **lib** directory files to **CIRCUITPY/lib**. Copy the **code.py** and **logo.py** files to your **CIRCUITPY** drive. The program should self start.

[Download Code Bundle](https://cdn-learn.adafruit.com/assets/assets/000/146/699/original/metro_rp2350_turbo_sand_bundle.zip?1790690114)
After loading the project on your device the **CIRCUITPY** drive should contain these files. The **src/** folder is optional. When the code runs it will use the **.mpy** version in the **lib/** directory. Keeping a copy of the plain source code on the device is nice as well if you've got the flash storage space to spare, it makes it easy if you ever want to modify the code and re-compile it.

![CIRCUITPY drive screenshot showing required project files](https://cdn-learn.adafruit.com/assets/assets/000/146/698/medium800/led_matrices_metro_drive_screenshot.png?1790690029 )

## **code.py**

This is the main code entry point. It initializes the display and accelerometer. It runs the main loop, deferring to **sand\_viper.mpy** to carry out the heavy math for each step of the simulation. This version uses `picogame` to render on the TFT display. It's more efficient than `displayio` for rendering graphics like the ones in this simulation.

If your accelerometer is mounted differently from mine, it may cause the particles to move too much while the Metro is flat. To fix it, you can set `LEVEL` to `None` in the code. Run it while the Metro RP2350 is sitting flat on a desk or other surface. Look in the serial console to find the calibration values printed from the accelerometer. Copy those values and put them in place as the value of&nbsp;`LEVEL`.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Turbo/sand_simulation/metro_rp2350/code.py

## **sand\_viper.py**
This is the code for the Viper module that handles the physics and collision math for the simulation. Viper functions are written as Python, but they are their own weird flavor of Python with an extra set of rules that must be followed.

Local variables and arguments must be&nbsp;`int`, `uint` (32-bit only), `bool`, `ptr`, `ptr8`, `ptr16`, `ptr32`, or `object`. They cannot use `floats` like normal Python numbers do. Parameters get passed to the Viper function as a list of values, and are accessed via their index within that list. There is no overflow protection. Integers will silently wrap, out-of-range indexes can corrupt memory or crash instead of raising a clean `IndexError`. Variables cannot change types. Mixing of typed values with `object` values will fall back to slower runtime calls.

This code gets compiled by `mpy-cross` for the specific architecture of the chip that it will run on. The **sand\_viper.mpy** file, included in the bundle, is compiled for the RP2350 architecture `armv7emsp`. The code cannot be directly copied to another type of board (re. ESP-32 board).

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Turbo/sand_simulation/metro_rp2350/sand_viper.py

Here is the command used to compile the module for the RP2350.

```terminal
mpy-cross -march=armv7emsp sand_viper.py
```

# PixelDust Digital Sand for CircuitPython

## Matrix Portal S3

This section of the guide covers a version of the Pixel Dust demo that runs on the Matrix Portal S3. It's made for a single 64x64 LED matrix. The Matrix Portal has an LIS3DH accelerometer on-board that is used to determine the direction of gravity within the simulation. The only assembly required is hooking up the LED panel to the Matrix Portal with the HUB75 connector and power wires.

This version uses a smaller overall display size and fewer sand particles than the Metro version. I used the 2mm pitch matrix panels, but other sizes would work fine as well.

![Matrix Portal S3 and HUB75 LED Matrix showing the sand simulation as it's rotated](https://cdn-learn.adafruit.com/assets/assets/000/146/391/medium640thumb/circuitpython_matrixportal_sand.jpg?1789573349)

![Matrix Portal S3 connected to a HUB75 LED matrix with the 2x8 connector power and GND wires.](https://cdn-learn.adafruit.com/assets/assets/000/146/405/medium640/circuitpython_matrix_portal_assembled.png?1789652193)

Warning: This code is set to work on a 64x64 pixel LED matrix only. Do not connect other sizes of displays like 32x64, etc. as it likely will not work. Different density 64x64 displays, with different pitches, in millimeters, should be fine.

## Parts
### Adafruit Matrix Portal S3 CircuitPython Powered Internet Display

[Adafruit Matrix Portal S3 CircuitPython Powered Internet Display](https://www.adafruit.com/product/5778)
Folks love our [wide selection of RGB matrices](https://www.adafruit.com/category/327) and accessories&nbsp;for making custom colorful LED displays... and our RGB Matrix Shields and FeatherWings can be quickly soldered together to make the wiring much easier. But what if we made it...

In Stock
[Buy Now](https://www.adafruit.com/product/5778)
[Related Guides to the Product](https://learn.adafruit.com/products/5778/guides)
![Video of Adafruit Matrix Portal S3 linked up to a matrix displaying the "Adafruit Matrix Portal" in white letters and red, green and blue circles jumping around. ](https://cdn-shop.adafruit.com/product-videos/640x480/5778-06.jpg)

### 64x64 RGB LED Matrix Panel - 2mm Pitch

[64x64 RGB LED Matrix Panel - 2mm Pitch](https://www.adafruit.com/product/5362)
Wintertime can be rough in the city. The sky is gray. The weather&nbsp;is unpredictable. So slough off those seasonal blues with&nbsp;some&nbsp;Times Square razzle dazzle from this sweet, ultra-high-density **64x64 RGB LED Matrix**. These panels are typically used to make video...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5362)
[Related Guides to the Product](https://learn.adafruit.com/products/5362/guides)
![Video of a person rotating an LED matrix. The animation resembles falling colored sand.](https://cdn-shop.adafruit.com/product-videos/640x480/5362-04.jpg)

# PixelDust Digital Sand for CircuitPython

## Install CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## Set up CircuitPython Quick Start!

Follow this quick step-by-step for super-fast Python power :)

Info: This project requires CircuitPython version **10.4.0-alpha.2** or newer, because that is when Viper support was added for the Espressif port. As of 9/29/26 version **11.0.0-alpha.1** is the latest development release. Scroll down to the latest development release on the downloads page.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_matrixportal_s3/)
## Further Information

For more detailed info on installing CircuitPython, check out [Installing CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython).

 **Click the link above and download the latest UF2 file.**

Download and save it to your desktop (or wherever is handy).

![led_matrices_Save_to_Desktop.png](https://cdn-learn.adafruit.com/assets/assets/000/095/075/medium640/led_matrices_Save_to_Desktop.png?1601050695)

Plug your MatrixPortal S3 into your computer using a known-good USB cable.

**A lot of people end up using charge-only USB cables and it is very frustrating! So make sure you have a USB cable you know is good for data sync.**

Click the **Reset** button (indicated by the green arrow) on your board. When you see the NeoPixel RGB LED (indicated by the magenta arrow) turn purple, press it again. At that point, the NeoPixel should turn green. If it turns red, check the USB cable, try another USB port, etc.

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

![led_matrices_Buttons.jpg](https://cdn-learn.adafruit.com/assets/assets/000/126/017/medium640/led_matrices_Buttons.jpg?1699492993)

Info: 

You will see a new disk drive appear called **MATRXS3BOOT**.

Drag the **adafruit\_circuitpython\_etc.uf2** file over to **MATRXS3BOOT****.**

![led_matrices_matrix.png](https://cdn-learn.adafruit.com/assets/assets/000/126/018/medium640/led_matrices_matrix.png?1699493436)

The LED will flash. Then, the **MATRXS3BOOT** &nbsp;drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it, you're done! :)

![led_matrices_CircuitPy.png](https://cdn-learn.adafruit.com/assets/assets/000/122/618/medium640/led_matrices_CircuitPy.png?1689369656)

# PixelDust Digital Sand for CircuitPython

## Code

## Getting the Program's Files

Viper and native compiled .mpy files are on the cutting edge of support in CircuitPython. The Adafruit Learning System project bundler has not yet been adapted to work with them. Use the green button below to download the project files instead of the usual "Download Project Bundle" button embedded with the code contents.

Connect your board to your computer via a known good data+power USB cable. The board should show up in your File Explorer/Finder (depending on your operating system) as a flash drive named **CIRCUITPY**.

Extract the contents of the zip file, copy the **lib** directory files to **CIRCUITPY/lib**. Copy the **code.py** and **logo.py** files to your **CIRCUITPY** drive. The program should self start.

[Download Code Bundle](https://cdn-learn.adafruit.com/assets/assets/000/146/700/original/matrix_portal_s3_turbo_sand_bundle.zip?1790690186)
After loading the project on your device the **CIRCUITPY** drive should contain these files. The **src/** folder is optional. When the code runs it will use the **.mpy** version in the **lib/** directory. Keeping a copy of the plain source code on the device is nice if you've got the flash storage space to spare, it makes it easy if you ever want to modify the code and re-compile it.

![CIRCUITPY drive screenshot showing required project files.](https://cdn-learn.adafruit.com/assets/assets/000/146/697/medium800/led_matrices_matrix_portal_drive_screenshot.png?1790688671 )

## **code.py**

This is the main code entry point. It initializes the matrix and accelerometer. It runs the main loop, deferring to **sand.mpy** to carry out the heavy math for each step of the simulation. This version uses `FramebufferDisplay` to drive the LED matrix panel.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Turbo/sand_simulation/matrix_portal_s3/code.py

## **sand.py**

This is the code for the viper module that handles the physics and collision math for the simulation. Viper functions are written as Python, but have an extra set of rules that must be followed.

Local variables and arguments must be&nbsp;`int`, `uint` (32-bit only), `bool`, `ptr`, `ptr8`, `ptr16`, `ptr32`, or `object`. They cannot use `floats` like normal Python numbers do. Parameters get passed to the Viper function as a list of values, and are accessed via their index within that list. There is no overflow protection. Integers will silently wrap, out-of-range indexes can corrupt memory or crash instead of raising a clean `IndexError`. Variables cannot change types. Mixing of typed values with `object` values will fall back to slower runtime calls.

This code gets compiled by `mpy-cross` for the specific architecture of the chip that it will run on. The **sand\_viper.mpy** file included in the bundle is compiled for the ESP32-S3 architecture `xtensawin`.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Turbo/sand_simulation/matrix_portal_s3/sand.py

Here is the command used to compile the sand module for the Matrix Portal S3.

```terminal
mpy-cross -march=xtensawin sand.py
```


## Guide Products

### Adafruit Metro RP2350

[Adafruit Metro RP2350](https://www.adafruit.com/product/6003)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town". This train is piled high with hardware that complements the Raspberry Pi RP2350 chip to make it an excellent...

In Stock
[Buy Now](https://www.adafruit.com/product/6003)
[Related Guides to the Product](https://learn.adafruit.com/products/6003/guides)
### Adafruit Metro RP2350 with PSRAM

[Adafruit Metro RP2350 with PSRAM](https://www.adafruit.com/product/6267)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town" and a bonus stop at "8 Megabytes of PSRAM village". This train is piled high with hardware that...

Out of Stock
[Buy Now](https://www.adafruit.com/product/6267)
[Related Guides to the Product](https://learn.adafruit.com/products/6267/guides)
### 2.8" TFT Touch Shield for Arduino with Resistive Touch Screen v2

[2.8" TFT Touch Shield for Arduino with Resistive Touch Screen v2](https://www.adafruit.com/product/1651)
Spice up your Arduino project with a beautiful large touchscreen display shield with built in microSD card connection. This TFT display is big (2.8" diagonal) bright (4 white-LED backlight) and colorful (18-bit 262,000 different shades)! 240x320 pixels with individual pixel control. It...

In Stock
[Buy Now](https://www.adafruit.com/product/1651)
[Related Guides to the Product](https://learn.adafruit.com/products/1651/guides)
### Adafruit MPU-6050 6-DoF Accel and Gyro Sensor - STEMMA QT Qwiic

[Adafruit MPU-6050 6-DoF Accel and Gyro Sensor - STEMMA QT Qwiic](https://www.adafruit.com/product/3886)
I mew, you mew we&nbsp;_all_&nbsp;mew for IMU! The MPU-6050 is what we call "an oldie but goodie" - this popular triple-axis accelerometer plus gyro combo has been a staple of electronic projects for years, and we've finally gotten around to making a breakout for...

In Stock
[Buy Now](https://www.adafruit.com/product/3886)
[Related Guides to the Product](https://learn.adafruit.com/products/3886/guides)
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
### Adafruit Matrix Portal S3 CircuitPython Powered Internet Display

[Adafruit Matrix Portal S3 CircuitPython Powered Internet Display](https://www.adafruit.com/product/5778)
Folks love our [wide selection of RGB matrices](https://www.adafruit.com/category/327) and accessories&nbsp;for making custom colorful LED displays... and our RGB Matrix Shields and FeatherWings can be quickly soldered together to make the wiring much easier. But what if we made it...

In Stock
[Buy Now](https://www.adafruit.com/product/5778)
[Related Guides to the Product](https://learn.adafruit.com/products/5778/guides)
### 64x64 RGB LED Matrix Panel - 2mm Pitch

[64x64 RGB LED Matrix Panel - 2mm Pitch](https://www.adafruit.com/product/5362)
Wintertime can be rough in the city. The sky is gray. The weather&nbsp;is unpredictable. So slough off those seasonal blues with&nbsp;some&nbsp;Times Square razzle dazzle from this sweet, ultra-high-density **64x64 RGB LED Matrix**. These panels are typically used to make video...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5362)
[Related Guides to the Product](https://learn.adafruit.com/products/5362/guides)

## Related Guides

- [Adafruit 2.8" TFT Touch Shield v2 - Capacitive or Resistive](https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2.md)
- [MPU6050 6-DoF Accelerometer and Gyro](https://learn.adafruit.com/mpu6050-6-dof-accelerometer-and-gyro.md)
- [Adafruit MatrixPortal S3](https://learn.adafruit.com/adafruit-matrixportal-s3.md)
- [Adafruit Metro RP2350](https://learn.adafruit.com/adafruit-metro-rp2350.md)
- [Star Trek Data Dispenser](https://learn.adafruit.com/star-trek-data-dispenser.md)
- [Adafruit Metro M7 1011 with AirLift](https://learn.adafruit.com/adafruit-metro-m7-with-airlift.md)
- [3D Printed Frame for Adafruit IS31FL3741 LED Glasses](https://learn.adafruit.com/3d-printed-frame-for-led-glasses-is31fl3741.md)
- [Adafruit QT Py Activity Timer and Hydration Reminder](https://learn.adafruit.com/qt-py-activity-timer-and-hydration-reminder.md)
- [Adafruit Metro ESP32-S2](https://learn.adafruit.com/adafruit-metro-esp32-s2.md)
- [Adafruit ESP32-S3 Feather](https://learn.adafruit.com/adafruit-esp32-s3-feather.md)
- [Wireless ESP32-S2 Touch Screen Controller for Pure Data](https://learn.adafruit.com/wireless-esp32-s2-controller-for-pure-data.md)
- [Fruit Jam Nintendo Entertainment System and Retro Jam](https://learn.adafruit.com/fruit-jam-nintendo-entertainment-system.md)
- [RGB LED Matrix Cube with 25,000 LEDs](https://learn.adafruit.com/rgb-led-matrix-cube-for-pi.md)
- [QT Py Snap Fit Case](https://learn.adafruit.com/qt-py-snap-fit-case.md)
- [Chip's Challenge on Fruit Jam and Metro RP2350](https://learn.adafruit.com/256-color-gaming-on-the-metro-rp2350.md)
- [Tile-Matching Game on the Fruit Jam and Metro RP2350](https://learn.adafruit.com/tile-matching-game-on-the-adafruit-metro-rp2350.md)
- [Adafruit QT Py ESP32 Pico](https://learn.adafruit.com/adafruit-qt-py-esp32-pico.md)
- [Reading QR Codes with the Tiny Code Reader](https://learn.adafruit.com/reading-qr-codes-with-the-tiny-code-reader.md)
- [Adafruit SensorLab - Gyroscope Calibration](https://learn.adafruit.com/adafruit-sensorlab-gyroscope-calibration.md)
