The globe and Game of Life programs are cool, but this last one might be the best…an interactive “snow globe” that reacts to gravity.

This requires the LIS3DH accelerometer, which is an optional part. Let’s assume at this point that you do have this item, and connected it as explained on the “RGB Matrix Bonnet and LIS3DH Wiring” page.

Start by enabling the Raspberry Pi’s I2C bus and installing some diagnostic software:

sudo raspi-config nonint do_i2c 0
sudo apt-get install i2c-tools
sudo nano /etc/udev/rules.d/99-com.rules

(Substitute your editor of preference in place of nano if you like.)

Look for the following line…it’s in the first few lines of the file:

SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660"

Change the last digit from a “0” to a “6,” like so:

SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0666"

This makes sure our code can read from the accelerometer later on.

Save changes to the file and quit from the editor, then reboot the system:

sudo reboot

Log back in, then enter the following command:

i2cdetect -y 1

If all goes well, you should get a response like the following:

0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

That “18” there is the accelerometer on the I2C bus! This tells you the system can detect and communicate with it.

If you do not see the “18” in the program’s output: The most common culprit is having the SDA and SCL wires swapped. Double-check your connections and re-solder if needed.

Then download and compile our code for the falling sand demo. At the moment, this is using a special branch, so the commands are a little peculiar…

wget https://github.com/adafruit/Adafruit_PixelDust/archive/refs/heads/pb-multiplane.zip
unzip pb-multiplane.zip
cd Adafruit_PixelDust-pb-multiplane/raspberry_pi
make

And if that finishes, go ahead and try it!

sudo ./cube

If you’re testing on a flattened, unassembled cube…the movement of the sand won’t make much sense yet, but that’s okay. The important thing is that the accelerometer and code work! And if you do have an assembled cube, remember to turn it gently to avoid shearing off edge pixels.

As with the other cube programs, Control+C quits.

If you haven’t assembled the cube into its final form yet, now is the time to proceed with that! Do an orderly system shutdown before taking things apart:

sudo shutdown -h now

This guide was first published on May 04, 2022. It was last updated on Mar 08, 2024.

This page (Software Part 2) was last updated on Mar 08, 2024.

Text editor powered by tinymce.