Arduino Modulino Pixels Tutorial

What is an Arduino Modulino Pixels module?

The Arduino Modulino Pixels module is a maker friendly module featuring 8 individually addressable color LEDs and a Qwiic interface. The Pixels module (Arduino part number ABX00109) was initially offered as part of a larger Arduino Plug and Make kit. It is a relatively complex module as it incorporates a 32-bit STMicroelectronics ARM microcontroller to handle the communication between the Arduino UNO R4 and the individual Red Green Blue (RGB) LEDs. The ARM Cortex M0 microcontroller is visible in the lower left-hand corner of Figure 1.

This engineering brief explores both the software interface as well as the underlying hardware. The article is limited to basic operations using the default Modulino addressing scheme. It does not include advanced operations such as changing the address for the Pixels module or operating more than one Pixels board on the same I2C network. Please leave a comment below if you are interested in performing these complex operations. These advanced techniques will be increasingly important in the future should Arduino offer individual Modulino boards.

Figure 1: Image of the Arduino Modulino Pixels module. The 32-bit STM ARM microcontroller is visible in the lower left corner.

Software description of the Arduino Modulino Pixels

Arduino provides a simplified library for the Modulino modules. This code is may be installed using the Arduino IDE’s Library Manager as described in the Arduino instructions.

Modulino class structure

The Arduino Modulino board’s software interface is handled using a class structure. The first step is to use the constructor:

ModulinoPixels leds;

This create an leds object that may then be manipulated using a variety of methods including:

  • leds.clear( ); This is an overloaded method used to clear an individual or all LEDs. When called with no parameters, all LEDs are cleared. When called with index N, the Nth LED is cleared.
  • leds.set( ); This is an overloaded method used to set the intensity and color of an LED.
  • leds.show( ); This method transfers the internal data established by the clear( ) and set( ) methods to the physical LEDs.

The modulino Pixels operates like a double buffer. We use the clear( ) and set( ) methods to change registers in the Pixels’ memory. These changes occur in the background and have no effect on the display. It is only when the show( ) method is called that the data are transferred the physical LEDs.

Tech Tip: The double buffer is an essential building block for serial communications. It allows data to be transferred one piece at a time. When all pieces are assembled, they can then be presented simultaneously. For example, it takes time to load the LED index number, color, and intensity data. However, a single event triggered by the show( ) method ensures that all LEDs are updated at the same time.

Simplified example code

To better understand the Arduino Modulino Pixels code, consider this simplified code listing. It shows how to configure the Arduino Modulino Pixels module. It demonstrates how to set the color. Finally, it shows how to blink an individual LED. The physical setup and visual display associated with this code are shown in Figure 2.

#include <Modulino.h>

ModulinoPixels leds;                      // Constructor
ModulinoColor OFF(0, 0, 0); 
int brightness = 10;                      // Set brightness to 10 % as LEDs are very bright	

void setup() {
  Modulino.begin();
  leds.begin();
  pinMode(LED_BUILTIN, OUTPUT);
}


void loop() {

// Example colors including the built in RED, GREEN, BLUE, VIOLET, and WHITE as well as 
// custom colors established using the 8-bit Red, Green, and Blue values

  leds.clear( );
  leds.set(0, RED, brightness);      
  leds.set(1, GREEN, brightness);
  leds.set(2, BLUE, brightness);
  leds.set(3, VIOLET, brightness);
  leds.set(4, WHITE, brightness);
  leds.set(5, 0, 128, 128, brightness);     // teal	
  leds.set(6, 255, 192, 203, brightness);   // pink
  leds.set(7, 100, 100, 0, brightness);     // yellow
  leds.show( );			                    // Transfers data from memory to the physical LEDs.


// Blink the RED LED located at position zero
 while (1) {
    leds.clear(0);
    leds.show( );
    delay(500);
    leds.set(0, RED, brightness);
    digitalWrite(LED_BUILTIN, HIGH);          // Trigger used to visualize communications protocol
    leds.show( );
    digitalWrite(LED_BUILTIN, LOW);
    delay(500);
  }
}

Figure 2: Physical setup and results using the introductory Pixels code listing.

Tech Tip: Several of the Arduino Modulino Pixels methods are overloaded. An overloaded function is easily identified as multiple method definitions share the same name. In this example, calling clear( ) with no parameters clears all LEDs. When overloaded clear(N) will clear the Nth LED. Likewise, the set( ) method will accept the built in color or the individual 8-bit RGB values.

Communications protocol

The primary interface for the Modulino Pixels board is a Qwiic connection. The Arduino Pixels board has two Qwiic connectors allowing multiple boards to be daisy chained together.

As an academic exercise, it’s fun to explore the communication protocol used to communicate across the Qwiic bus. Originally, as implied in the previous part of this note, I assumed each method would send a burst of information. For example, I assumed the set( ) and clear( ) methods would send data to the Pixels module immediately when called.

Not so, in fact, only the show( ) method appears to send data from Arduino to Pixels as shown in Figure 3 with the associated setup as Figure 4. Consequently, the double buffering mentioned earlier in this article occurs inside the Arduino itself. Either way, the data are not displayed until the show( ) method is called. Note that 32 bytes of data are transferred in Figure 3. Presumably, this frame contains the 8-bit intensity data for each RGB LED. Further discovery of the frame is left as a critical thinking exercise.

Notice that the frame is sent with a 100 kHz clock. Consequently, it takes about 3 ms to send the entire frame.

Figure 3: Portion of I2C frame destined for the Arduino Pixels module initiated by the show( ) method The frame starts with the default Pixels 0x6C address.

Tech Tip: The term Qwiic is a playful merger of words “quick” and “Inter-Integrated Circuit” (I2C). The system is indeed quick and easy as many Qwiic boards are available. Click here to learn more about the Qwiic protocol.

Figure 4: Setup used to observe the communication protocol between the Arduino UNO R4 and the Pixels module. The Digilent Analog Discovery Pro is visible in the background.

Tech Tip: It is often necessary to compromise when designing a communications protocol. For example, the Pixels library will send the entire 33-byte packet if a single change is made to a single LED. While this required a high bandwidth, I suspect the one-size-fits all memory scheme was easier to program and implement as an Arduino library and as Pixels firmware.

Parting thoughts

The Arduino Modulino Pixels allow a user to quickly connect and experiment with tricolor RGB LEDs. The hardware connection is very simple via the Qwiic. The object-oriented software may be challenging for novice programmers as it involves constructors and dot-notation accessible methods. I suspect most programmers will quickly identify the patterns. However, it will take considerable time before they grok the structure and even more time to construct their own class-based programs.

Personally, I was surprised to find a 32-bit ARM Cortex M0 on the Pixels board. Also, the data frame was more complex than I envisioned. Instead of sending small messages associated with each method, the Arduino appears to send the entire 33-byte packed (address plus 32 bytes) even when a single LED change is made.

As we conclude, be sure to review the basic and critical thinking questions appended to this article.

Please leave your comments and questions in the space below

Best wishes,

APDahlen

Related Information

Please follow these links to related and useful information:

Questions

The following questions will help reinforce the content of the article.

  1. Contrast and compare a method with a function.

  2. Identify each component in the statement leds.show( );.

  3. Describe the double buffer scheme as applied to the Arduino Modulino Pixels.

  4. What would happen if the programmer forgot to use the show( ) method?

  5. What would happen if the programmer forgot to use a clear( ) method?

  6. Describe the attributes of the Qwiic physical connection. Hint: Can it be incorrectly installed?

  7. What is the purpose of the pull up resistors in an I2C bus? Hint: Open Drain Circuits

  8. Research the schematic for the Arduino UNO R4 and associated Modulino boards. Where are the pullup resistors for the I2C bus? Hint: Nearly every board has provision for resistors, but they are not universally installed.

  9. What are the limitations of the Quiic system in terms of current and distance. Hint: Qwiic Connect System - SparkFun Electronics

  10. Could the Modulino’s Pixels 32-bit microprocess be replaced with an 8-bit microcontroller? What are the advantages and disadvantages of using a smaller 8-bit microcontroller.

  11. Research Electromagnetic Interference (EMI) and the harmonic spectrum of a square wave (Fourier Series). Identify potential EMI issues associate with the Qwiic signals, its 100 kHz clock, and unshielded wires.

Critical thinking questions

These critical thinking questions expand the article’s content allowing you to develop a big picture understanding of the material and its relationship to adjacent topics. They are often open ended, require research, and are best answered in essay form.

  1. The Modulino Pixels library appears to send data only when the show( ) method is called. What are the advantages and disadvantages of this protocol.

  2. Contrast and compare the I2C with the SPI communications protocol. Be sure to identify the protocols in terms of total number of devices, wires, used, and communication speed.

  3. For simplicity, this article did not explore the discover( ) method. Describe the method and when it would be used. Hint: Modulino.h.

  4. Figure 3 implies that 32 bytes of data are transferred from the Arduino to the Modulino Pixels board. Reverse Pixels frame to determine the meaning of each byte. Hint: The brightness is the same for all LEDs. Also, the code listing has the LEDS operating consecutively as red, green, and blue. Finally, it may be useful to toggle a single piece of data and observe the presumably single byte change.

  5. Recommend two new protocols for the Arduino Pixels. Tune your protocols for different user requirements e.g., those who frequently make single LED changes and those who infrequently change all LEDs.

  6. The Arduino Plug and Make product is designed to introduce a variety of electronic modules without the need and complexity of the breadboard. Reflect the utility of this product for both the maker and the higher education user. Be sure to describe the user’s experience and the learning outcomes.

  7. Under what license is the Arduino Modulino software released? What are the implications if you wish to copy and then redistribute the software?

  8. What is a checksum? Would the additional bandwidth be warranted in this application?

About this author

Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (partially interwoven with military experience). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET-accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians. Dahlen has returned to his Northern Minnesota home and thoroughly enjoys researching and writing educational articles about electronics and automation.

Highlighted experience

Dahlen is an active contributor to DigiKey’s Technical Forum. At the time of this writing, he has created over 190 unique posts and provided an additional 600 forum posts. Dahlen shares his insights on a wide variety of topics including microcontrollers, FPGA programming in Verilog, and a large body of work on industrial controls.

Connect with Aaron Dahlen on LinkedIn.