Embedded Rust - RGB LED with Color Rotation

January 4, 2024

Introduction Video:

https://youtu.be/u3pt1_NsIhs

Description:

This project demonstrates how to control an RGB LED with a common cathode using the micro:bit V2 and the Kitronik Breakout Board Edge Connector. The code uses a timer to rotate through the colors Red, Green, and Blue, changing colors every 250 milliseconds.

Project's hardware:

  • 1 micro:bit V2
  • 1 Kitronik Edge Connector Breakout Board
  • 1 830 point solderless breadboard
  • 3 560R resistors
  • 6 M/F 6" Premium Jumper Wires (2 Red, 2 Green, 2 Blue)
  • 1 F/F 6" Premium Jumper Wires (1 Black)
  • 1 RGB Diffused Common Cathode LED - 5 mm
  •    Forward Voltage (RGB): (2.0, 3.2, 3.2)V
  •     Max forward Current (RGB): (20, 20, 20)mA
  •     Max Luminosity (RGB): (2800, 6500, 1200)mcd
Hardware Required for Project

Instructions:

Clone this repository and change/move into the cloned directory in your terminal window.

git clone https://github.com/CodingInGreen/microbit_v2_rgb_led.git

Prepare the micro:bit V2 and Kitronik Edge Connector Breakout Board:Attach the Kitronik Edge Connector Breakout Board to the micro:bit V2. Make sure the connectors are facing each other and that the pins are aligned.

Micro:bit V2 connected to Kitronik Breakout Board Edge Connector
Micro:bit V2 connected to Kitronik Breakout Board Edge Connector

Connect 3 of the 560R resistors to the breadboard so that the resistors can be shared by the RGB LED.

Insert one end of each resistor into the following holes on the breadboard:

  • d27
  • d28
  • d29

Resistors connected to d27, d28, d29 on breadboard
Resistors connected to d27, d28, and d29 on breadboard

resistors connected to d27, 28, and 29 on breadborad
Resistors connected to d27, d28, and d29 on breadboard, zoomed in.

Connect the 3 other ends of the 560R resistors to the breadboard in respective order to match the first insertion instructions above.

These must be placed across the gap of the breadboard (the other side).

  • f27
  • f28
  • f29

Other end of resistor connected to f27, f28, and f29
Other end of resistor connected to f27, f28, and f29 (side view)

Connect the female end of the jumper wire to the anode terminals (Red, Green, Blue) of the LED using Red, Green, and Blue M/F 6" Jumper Wires. These are the three shorter ends (anode terminals) of the RGB LED legs for common cathode RGB LEDS. The word common indicates that this will be the connection to the ground pin (0V). Manufacturers also make commmon anode LEDS, but that's not what were using here for this example.

Red, Green, and Blue Jumper Cables connected to Anode terminals (legs) of RGB LED

The anodes are the positive (+) terminals of the component. For an RGB  LED, the anode terminals the longer legs and are connected to the positive side of the power source. You might be wondering, how do test which anode lights up which color of the RGB Led - Red, Green, or Blue. We take care of that in the final step, step 13. For now, just follow the instructions as they are written.

You'll now have 3 M/F Jumper Wires now with the male ends available. Connect the male end to the breadboard on same hole in the same line just AFTER each resistor for each anode (Red, Green, Blue), respectively.

This is how you match up the holes from the second part of step 2 (the other end of the resistor placed across the gap) to the male ends of the Jumper Wires.

  • f27 (other end of resistor) -> j27 (the male end of the Red Jumper Wire that connects to the Red anode terminal)
  • f28 (other end of resistor) -> j28 (the male end of the Green Jumper Wire that connects to the Green anode terminal)
  • f29 (other end of resistor) -> j29 (the male end of the Blue Jumper Wire that connects to the Blue anode terminal)

Red, Green, and Blue cables connected to j27, j28, and j29, respectively

Red, Green, and Blue cables connected to j27, j28, and j29, respectively (side view)

You'll now get 3 M/F Jumper wires. Using those, connect the male end to the breadboard on the hole in the same line just BEFORE each resistor for each Anode (Red, Green, Blue), respectively.

  • a27
  • a28
  • a29
Second Pair of Red, Green, and Blue Jumper Cables connected to a27, a28, and a29, respectively

You'll now have 3 Female ends to insert into the Kitronik Edge Connector Breakout Board.

Connect the Female end of the Jumper connected to the Red LED cable to the Kitronik Edge Connector Breakout Board, onto Pin 9 of the Kitronik Breakout Board Edge Connector.

For example, in the code:

   //Pin 9 on Breakout Board
   let mut red_led = gpio.p0_09.into_push_pull_output(Level::Low);
   //Pin 3 on Breakout Board
   let mut green_led = gpio.p0_31.into_push_pull_output(Level::Low);
   //Pin 4 on Breakout Board
   let mut blue_led = gpio.p0_28.into_push_pull_output(Level::Low);

This would indicate that the red_led variable has been assigned to Pin 9 on the Kitronik Edge Connector Breakout Board.

Connect the Female end of the Jumper connected to the Green LED cable to the Kitronik Edge Connector Breakout Board, onto Pin 3 of the Kitronik Breakout Board Edge Connector.

Connect the Female end of the Jumper connected to the Blue LED cable to the Kitronik Edge Connector Breakout Board, onto Pin 4 of the Kitronik Breakout Board Edge Connector.

Red, Green, and Blue Jumper Cables connected to Kitronik Breakout Board Edge Connector

Connect a black F/F Jumper Wire, one female end, to the common cathode pin of the RGB LED (the shorter leg terminal).

Black (Ground) Jumper Cable connected to Cathode terminal on RGB LED

Insert the other female end of the Jumper wire into the Kitronik Breakout Board Edge Connector, to one of the 0V pins (Ground pin).

Red, Green, and Blue Jumper Cables connected to Kitronik Breakout Board Edge Connector

Connect the micro:bit V2 to your computer using the micro-USB to USB-A cable.

micro-USB to USB-A cable used to connect micro:bit V2 with Breakout Board to computer

Video on Flashing the micro:bit V2:

https://youtu.be/rYhxKhO8LfU

Build and Flash your micro:bit V2:

Run this command from the root cloned directory:
   cargo build --features v2 --target thumbv7em-none-eabihf
If you have problems with this, check out the Rust Discovery Book:
Then run this command from the root cloned directory:
   cargo embed --features v2 --target thumbv7em-none-eabihf

If you have problems with this, check out the Rust Discovery Book:

The red LED, green LED, and blue LED should all light up respectively with 250 millsecond rotations.

RGB LED rotating colors every 250 milliseconds:

https://youtu.be/EbYrwL-zFQg

You can now test which anode terminal of your RGB LED is red, green, and blue by pulling out 2 of the 3 female Jumper Wires for the anode pins (the longer legs). You can then reconnect the cables in a color coded fashion.

Does your RGB LED alternate colors every 250 millseconds?