This guide for the GlowBit 4x4 Matrix will have you up and running on either a Raspberry Pi or Raspberry Pi Pico (the experience is the same), and introduce you to some useful python code examples to display both static shapes and colours and animations.

Transcript

G'day and welcome to the guide for the Glowbit 4x4 Matrix. To follow along, you're going to need a Raspberry Pi Pico or a Raspberry Pi. Let's get started.

When you first get your 4x4 Glowbit Matrix, it does not have any wires or pin headers soldered to it. So the first thing you're going to have to do is solder some connections to your Glowbit Matrix. The example we're using in this video has had pin headers soldered to the back of the device, but you can also solder wires directly to it if you prefer.

To connect the Glowbit Matrix 4x4 to a Raspberry Pi Pico, you are going to need to make three connections. To make these three connections, I'm going to be using three female-to-female jumper cables.

For the first connection, we'll take our black cable and connect it to the ground on our Glowbit Matrix 4x4 and to a ground pin on the Raspberry Pi Pico. We'll take our next wire and connect our VCC from the VCC on the Glowbit Matrix 4x4 to the VBUS pin of the Raspberry Pi Pico. We're using the VBUS pin just because it can deliver more current than the 3.3V pin. Lastly, we'll take a yellow wire and go from the data in on the Matrix to pin number 18 on the Raspberry Pi Pico.

To make these same three connections on the Raspberry Pi, we'll connect our VCC to a 5V pin, which happens to be the pins in the upper right-hand corner when viewed like this. We'll connect our ground wire to pin 6 of the Raspberry Pi header, which happens to be the third pin down from the upper right corner. And our data line is going to be connected to pin 18 on the Raspberry Pi header. Pin 18 happens to be six pins down from the upper right corner. One, two, three, four, five, six. There it goes.

When setting up the Glowbit library on a Raspberry Pi, the most crucial thing to know is that you must run Thonny as root. To do this, click the terminal icon.If you are using your Glowbit Matrix 4x4 on the Raspberry Pi Pico, the first thing you need to do to install the drivers is plug in the Raspberry Pi Pico and open up Thonny. If you haven't used Thonny with the Raspberry Pi Pico before, you can check out our guide on that.

To install the libraries, you click Tools, Manage Packages. Now, there are two libraries we need to install. The first one is called rpi-ws281x. This one here is the user space Raspberry Pi library for the ws281x LEDs. The Globits use ws2812b LEDs, so we need to install this library. Next, we need to install the Glowbit library. Type in globit, click Search on PiPy, and there's the first result. We click Globit, click Install, and the library is now installed.

To make sure the Glowbit library has been installed correctly, we'll type in "import globit", press Enter, and if we don't get any error messages, we're good to go.

Once the library has been successfully installed, you should see this lib folder with globit.py and petme128.py inside it. Now that the library's installed, it's time to run our first demo. Find the section called Running a Test Demo, and copy the first code example into Thonny. With main.py saved, we can then press Control R.

If you don't have this menu up here, there'll be a little link on the right side. You click that, restart Thonny, and the menu should appear.

To install the libraries, you click Tools, Manage Packages. Now, there are two libraries we need to install. The first one is called rpi-ws281x. This one here is the user space Raspberry Pi library for the ws281x LEDs. The Globits use ws2812b LEDs, so we need to install this library. Next, we need to install the Glowbit library. Type in globit, click Search on PiPy, and there's the first result. We click Globit, click Install, and the library is now installed.To execute the demo. While the demo is running, a series of test patterns will be shown.

The next thing we're going to look at is how to light up individual pixels on the Glowbit matrix. Scroll down to the guide to the heading that says Lighting up Individual Pixels, and copy the first code demonstration into Thonny. For the time being, we'll just replace the code that we had there before.

When we hit Control R again to run this code, you'll see two pixels light up on the screen. This example uses the pixelSetXY function in order to set a pixel at a given XY coordinate to a given color. To index other pixels on the Glowbit matrix, you'll need to know that the X coordinate increases going to the right, and the Y coordinate decreases going down.

So the second call to pixelSetXY, setting pixel 1, 2, sets X coordinate 1 and Y coordinate 2, and turns it into a greenish color. The other thing to note about the second call to pixelSetXY is that it uses another call to a function called matrix.rgbColor. This is a function that takes a red, green, and a blue intensity between 0 and 255, and allows you to choose basically any color you want. Lastly, we call the matrix.pixelsShow function, because this is what actually copies an internal frame buffer to the physical display.

Moving on, let's look at the next section entitled the Color Wheel. This next example is going to use a function called Wheel, which returns an RGB color somewhere on the Color Wheel. We'll copy and paste this code example into Thonny, just like we did before.

If we press Control R again to run this code, we're going to see a nice RGB rainbow spectrum going diagonally across the Glowbit matrix. We can quickly remix this code by changing this number 36 to another number, let's say 5, and pressing Control R, and we'll see that the spectrum on our display now only covers aSmall amount of the Color Wheel. If we change this number to another number, let's say 100, and press Control R again, the color spectrum is going to change much more rapidly.

The next example is going to cover using the pixelsFill function in order to fill the entire matrix display with a solid color. Scroll down to the part in the guide where it says filling all pixels with a single color, and copy the first example into Thonny.

When we run this example, it's going to scroll through all of the colors on the Color Wheel one at a time. This example uses a single for loop to run through the entire Color Wheel, except instead of setting individual pixels, it calls the pixelsFill function in order to fill the entire display with the same color.

The next section of the guide covers drawing basic shapes on the Glowbit matrix. Scroll down to the section that says lines, rectangles, triangles, and circles, and copy the first code example into Thonny.

Running this example, you'll see a rectangle drawn around the edge of the Glowbit matrix display. This particular drawing function allows you to draw a rectangle with a given starting coordinate for one corner and another coordinate for a second corner and draws a rectangle between them.

In this example, we're drawing a rectangle from 0,0, the top left corner, to 3,3, which is the bottom right corner, and so the rectangle goes around the edge of the whole display. The third argument to the drawRectangle function just takes a color. There are several other functions to draw different shapes. You can check them out in the guide.

The last example we're going to look at is how to draw a graph on the Glowbit matrix display. Scroll down to the graph section in the Glowbit matrix guide and copy the first example into Thonny. In order to draw a graph on the Glowbit matrix, you need a Graph1D object.And this object takes quite a few arguments.

The first two arguments are the origin of the graph. Effectively, a graph is just a line of a certain length and the length changes with some input value, so the origin is the start of that line. In this example, the origin is 0,3, so it's in the lower left-hand corner.

The next argument is the length of this graph. We're just going to make a graph of length four pixels because it's a four-pixel tall display.

Next, we have a direction argument. This specifies in what direction relative to the origin the graph will grow. In this case, it's going to grow up, so the graph will start in the lower left-hand corner and move up as the value increases.

Next, we have the minimum and maximum values for our graph. These are the values of the edges of our graph, so a value of 0 will display no pixels and a value of 255 will light up all four.

In order to generate some example data, we're just using a couple of for loops. Pressing Control-R to run this example, we're going to see the left-hand column of pixels slowly go up and then slowly go down. This is happening as a value of 0 to 255 is being plotted, and then from 255 back down to 0.

These graphs are fantastic to plot physical values such as an ADC voltage or a temperature. If you make something cool from these starter projects or just have a question, leave a comment on the article for this video.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.