RGB LED Matrix Sketch (micro:bit Version)

by Narongporn in Circuits > Microcontrollers

15394 Views, 143 Favorites, 0 Comments

RGB LED Matrix Sketch (micro:bit Version)

20210902_200118.jpg
20210902_200658.jpg

This project is inspired by "RGB LED Etch-A-Sketch" by Mr. Langford. I love his idea that applying RGB LED Matrix as a display device, enables us to sketch bright colored pictures. Instead of using Arduino board, I decided to use micro:bit as a controller and Microsoft Makecode as a programming platform.

micro:bit is a versatile micro-controller with 19 I/O pins, including analog & digital I/O, SPI and I2C bus. In this Instructable, I will connect micro:bit to RGB LED Matrix (WS2812B), joystick, and potentiometer.

micro;bit uses the joystick to control cursor's movements (up, down, left, and right). We can navigate a cursor to any dots on 16x16 RGB LED Matrix panel. micro:bit can also read analog value from potentiometer to determine cursor's color. There are 9 pre-defined colors in this program (red, orange, yellow, green, blue, indigo, violet, purple, and white).

To plot a dot with a selected color, push a joystick button. To erase a dot (turn-off LED), press a button A on micro:bit.

I also add hide cursor function when we idle more than 10 seconds. Cursor will appear once user moves the cursor or change its color.

This project will provide a good challenge for beginners or less-experience users; moreover, it will help you discover the potential of micro:bit and block-based programming in more complex projects.

Supplies

20210926_152222.jpg
20210926_152251.jpg
20210211_212601.jpg
20210211_212548.jpg
20210926_151041.jpg
20210926_150854.jpg
20210926_151325.jpg
20210926_151506.jpg
20210926_152051.jpg

Electronics

  • micro:bit version 1.x or 2
  • Extension board: IObit
  • Joystick module (for Arduino)
  • 10K Slide-potentiometer
  • WS2812b 5050 16 x 16 RGB LED matrix
  • Female-to-female jumper wire 20cm x 8
  • Female-to-male jumper wire 20cm x 3

Other

  • USB cable + charger (or power bank)

Choosing Expansion Board

20210926_151722.jpg
20210926_151909x.jpg
20210903_140535.jpg

Although micro:bit has 3 large pins (P0, P1 and P2) which can be connected to other devices with an alligator clip, I need more than 3 pins in this project. Therefore, I used a micro:bit expansion board to provide access to all other pins. There are various choices of expansion board in markets, my criteria include:

  • Provide 5V power supply for RGB LED matrix
  • Can be powered via USB cable with On-Off switch
  • Provide access to all pins on micro:bit with 3V and GND (SVG or VCC-GND signal)
  • Have a Low cost and small size

Of all expansion boards that meet my criteria, I choose IObit board for its small footprint (5.5 cm by 4.5 cm), and the cost is just $6.5.

Circuit

Drawing.jpg
Drawing2.jpg
20210926_151535.jpg
20210926_151551.jpg
20210926_152515.jpg
20210926_152549.jpg
20210926_150936.jpg
20210926_151133.jpg

The above diagram has provided information about a circuit. In this section, I will provide more details about each module and how to connect them together.

Expansion board

IObit board has 2 groups of pin headers:

  • The 3 red pins on the left will be used to supply 5V for RGB LED Matrix, and the black pins are GND.
  • 3 rows of pins (yellow, red, and black) - yellow connect to micro:bit pins while red and black are 3V power supply and GND

To power micro:bit through expansion board, you must connect it to the power bank via USB cable and then press a power switch.

RGB LED Matrix

At the back of LED panel, there are 3 groups of wiring. The wires on the right has DIN (or Data In) for connecting pin8 of micro:bit. Also, connect 5V and GND to the expansion board. Use female-to-male jumper wires to connect them.

Potentiometer

OTA is an potentiometer output, you must connect it to pin0 of micro:bit as well as connect VCC/GND to 3V/GND of expansion board.

Joystick

There are 3 main parts in joystick:

  • 2 potentiometers is used for detecting joystick movements on X, Y axis. The outputs are Vx and Vy.
  • 1 push button. When pushed, the switch will connect SW pin to GND

Use 5 Female-to-female jumper wires to connect joystick to expansion board

  • Vx, Vy (joystick) for pin 1, 2 (micro:bit)
  • SW (joystick) for pin 12 (micro:bit)
  • +5V (joystick) for 3V (expansion board) (DO NOT connect to 5V pin on expansion board)
  • GND (joystick) for GND (expansion board)

Important Notes

  • 5V pin on the expansion board is only used for RGB LED Matrix.
  • Even it is labeled 5V on the joystick, the maximum analog input for micro:bit should not exceed 3.6V, so 5V pin of joystick must be connected to 3V instead.

Install Extensions

ext1.jpg
ext2.jpg
ext3.jpg
ext4.jpg
ext5.jpg
ext6.jpg

To write a program, visit Microsoft Makecode for micro:bit and click "New Project". You will be prompted to enter a project name.

The first thing we need to do is to install extensions for Joystick and RGB LED Matrix:

  1. Click "Advanced" to reveal more commands, then click "Extensions"
  2. Enter following URL to locate Joystick extension from Github. (https://github.com/lioujj/pxt-joystick)
  3. Click to Install the Joystick extension
  4. Repeat step 1 to install RGB LED Matrix extension. Change URL to https://github.com/Shorts1999/pxt-smartmatrix

Now, you already have installed 2 extensions. Click on "Joystick" and "SmartMatrix" to explore new commands.

Program

final.png
Project Etch A Sketch

I have published VDO tutorial on YouTube which will guide you through detailed steps to create this code.

After the code is completed, you must save the source code in hex file format to your computer and copy this hex file to your micro:bit via USB cable.

How to Use Etch-A-Sketch

  • Insert micro:bit into the expansion board
  • Connect the power bank to the expansion board and push the power switch to turn on
  • Use the joystick to control cursor movement. The cursor will appear as a bright dot
  • Press the joystick button to lit LED at a cursor position
  • Change the cursor color with a slide-potentiometer
  • Press the button A on micro:bit to delete a dot (turn-off LED at cursor position)
  • The cursor will hide itself if no movement on the joystick and the slide-potentiometer for more than 10 seconds.
  • Any movement on the joystick and the slide-potentiometer will bring the cursor back (turn on)

What' Next ?

20210906_141525.jpg

One of the most requested features is "save/open sketch". Thus, I plan to use EEPROM memory module to store sketches. Each sketch has 256 pixels and each pixel needs 3 bytes for RGB, so one sketch requires 768 bytes. The low-cost EEPROM AT24C256 has 256 Kbit of memory or 32 Kbyte which means it can store approximately 40 sketches.

The new features will include:

  • Load latest sketch on "Start-up"
  • Press a button B to save sketch
  • Press button A+B to load sketch from EEPROM then use the joystick to select sketch
  • Sketch will be named as number 01-40

etc.

More micro:bit projects in my Facebook Page