MAKER LED DISPLAY: EVERYTHING IN ONE PLACE

MAKER LED DISPLAY: EVERYTHING IN ONE PLACE-Uncategorized

Maker Display is a product by e-radionica, crowfunded through the campaign on the Crowd Supply platform in April, 2019. A detailed description of the product can be found on the campaign website, and currently you can get your own Maker Display in the e-radionica.com shop.   

INTRODUCTION

Did you ever want to create a device that will monitor the Bitcoin price in real time or the number of Facebook likes on your favorite post or even display current time and weather forecast? But, you have suddenly realized that making something like this will not be easy, and it definitely will not be so small and compact. The solution is your own PCB or our Maker LED Display that will save you from having to deal with this type of problems. Namely, Maker LED Display is a type of Arduino board which is equipped with an ESP8266 microcontroller that contains WiFi and LED matrix where you can display the data, has a JST connector onto which you can connect lithium-ion battery and power supply the whole board with that battery, and at the same time it has a battery charger so you can even charge it via USB connector.

For starters, let’s find out more details about our new board.

TECHNICAL SPECIFICATIONS:

  • Power supply voltage:
    • USB: 5 VDC
    • JST: Lithium battery: 3.7 VDC (from 3.3 VDC to 4.2 VDC range)
  • Microcontroller: ESP8266 of 80MHz to 160 MHz working stroke (ESP8266-12E modul)
  • The number of free (unused) pins: 4
  • Display resolution: 32×9 for Maker Display 2 and 64×9 for Maker Display 4
  • Greyscale resolution: 256 (8 bit)
  • Dimensions:
    • Maker Display 2: approximately 104mm x 39.5mm
    • Maker Display 4: approximately 185mm x 39.5mm
  • Available LED colors: White, blue, green, purple, orange, red (shown in the image below)

 

HOW TO PROGRAM MAKER DISPLAY?

The boards contain an ESP8266 microcontroller, which is well known and can also be found in Dasduino Connect boards. This microcontroller has WiFi, which allows connecting to the Internet or even to a local network, through which you can control it using your computer or your smartphone. It is programmed using the Arduino IDE interface. But, before that you should install the ESP8266 Arduino Core to your Arduino IDE, and the process is similar to that of Dasduino Connect, so we recommend using instructions from that link. But, in order to transfer the program from your computer to your Maker LED Matrix board, you need a programmer. Our recommendation is using the NOVA programmer which is based on the CP2102 USB to UART integrated circuit. If you want to use the Dasduino Connect programmer, first you have to install the drivers for that integrated circuit. But it is not the only programmer you can use, any USB to UART converter can serve the purpose, so the programming process is the same as programming of the ESP8266 development board (you can again use the instructions from the link for programming Dasduino Connect).

The programmer and Maker LED Display are connected so that the programmer connects to the Maker LED Display’s pins which are located in the upper right corner of the board (6 pin programmer connector). It must be noticed that, on the programmer, the pin from the left has a small circle, which signifies the first pin. That first pin must be connected to the first pin of the 6 pin connector for programming on Maker LED Display, and that is the first pin on the left – just like it is shown in the image.

You can solder the 6 pin female header to that spot on the Maker LED Display, or you can simply press the headers against the pads (as shown in the image). This is a better solution if you will rarely reprogram the board, because it is quick, simple and there are no headers that occupy the space, but the problem is that this type of programming may be unreliable, because the programmer needs to be properly aligned (sometimes it helps if the programmer board is moved to the upper side for better contact). This way of programming is similar to the one of Arduino Pro Mini.

 

 

HOW DOES THE MAKER DISPLAY WORK?

Finally, we can say something about the LED Drivers. LED Drivers (integrated circles controlling LEDs) are IS31FL3731. The principle under which LEDs are controlled is not Multiplexing this time, it is Charlieplexing.

The difference between charlieplexing and multiplexing is the fact that with multiplexing (in case of matrix) only one row (or column) turns on at a certain point in time, and then the default LEDs illuminate, remain illuminated for some time, then the row (or column) shuts down, the following one turns on, LEDs illuminate, remain so and the process repeats. This happens extremely fast, so fast that the human eye can not even notice the ignition or extinguishing, but sees a stable image. Charlieplexing is done differently, LEDs are connected in every possible way so that all the combinations are filled in, without some of them repeating, and for each LED to be able to illuminate, without turning another LED on at the same time. Let’s say in an example below, if we want to turn on the LEDs LED1 and LED3, first we will bring VCC onto X1, GND to X2 and X3 in high impendance state, hold it for a while, then convert X1 to high impendance state, set X2 to VCC and X3 to GND. It is visible that this type of approach is more complicated than multiplexing, but allows using a much smaller number of pins. In our case, for the 16×9 matrix (how much does one IS31FL3731 offer) for multiplexing we need 25 pins, and 18 pins for charlieplexing. Turning the LEDs on or off is done by the driver itself, so we do not have to worry about it. The drivers work at 5 VDC, i.e. battery voltage, if it is power supplied by the battery. They use Constant current drivers, which means that the currency through each LED will be regulated, and its amount is regulated using the resistor. The communication is done using the I2C protocol, and the drivers are distinguished by their addresses. They are connected to the pins GPIO4 (SDA) and GPIO5 (SCL) of the ESP8266 microcontroller. The same pins are connected to the easyC connector (therefore, LED drivers share the I2C bus with other I2C devices), but some devices (sensors) can be really picky concerning the devices connected to the I2C bus, so it could happen that the sensor will not work together with LED drivers. In that case it is necessary to use other (unused) pins for communication.

In the end it is important to note that the microcontroller’s ADC is connected via voltage divider, so that it measures the battery’s voltage. This is really convenient in cases when the board is power supplied by the battery, so we could display the warning about low battery or simply the battery status.

 

HOW TO CONNECT IT?

The process of connecting the programmer and Maker LED Display board is previously explained, so we will not repeat it. You should only bear in mind that you should not leave the USB power supply on the Maker LED Display board during programming, because it can damage the programmer. For the first four examples, we do not need anything but the Maker LED Display, programmer and micro USB cable. For the last three examples you will also need the APDS9960 sensor, along with the breadboard, interconnectors, easyC cable and easyC adapter.

For the fifth and sixth example, the sensor and Maker LED Display board are necessary to be connected in the following way (it does not matter if you have the Maker LED Display 2 or Maker LED Display 4).

The last example is a bit more complicated and requires soldering. It refers to the sensors that do not work well enough on the same I2C bus like LED drivers. Therefore this last example shows how to achieve managing to read data from such a “problematic” sensor.

First, you have to find unused pins on the ESP8266 microcontroller, and they are located on the back side of the board.

After that, it is necessary to solder the wires to them using which you will connect your sensor (APDS9960 in this example) with the board.

Then connect the sensor and the board in a way that is shown in the following image. The red wire represents power supply of the sensor (3.3 VDC), the blue is GND, pin 12 is SDA, and pin 13 SCL of the I2C connection. We do not use the INT pin on the APDS9960 sensor.

 

 

 

 

ARDUINO CODE

Before we move onto programming, we must take care of some important things. First, you must open Arduino IDE and adjust it in the following way:

If the port does not appear (it is blackened as in this example), this means that you have not turned the programmer on into a computer or that you have not installed the programmer drivers. If your port is not blackened, but does not write COMX (where X is a number), click on the port and select it (usually COM with the largest number next to it). If the upload of the program on the board is not successful even after a few attempts, try reducing the upload speed to 115200.

After that, it is necessary to download and install the libraries. There are two main libraries using which you can control the LED matrix : IS31FL3731 and Maker Display Arduino Library.

The difference between these two libraries is the following:  Maker Display Arduino Library allows simple control over the matrix, you can display messages, images, even the images in shades of grey, along with different shapes from the Adafruit GFX graphic library, open the text on the Internet and show it on the display, and be able to scroll everything of it (move on the display from right to left) but such library uses software timer Ticker.h which calls the display function for displaying another image on the matrix periodically. Therefore, what is currently going on will be stopped for a moment, and another image will be printed on the display, after which the user program continues. These are called program interrupts. Because of it, this library is a bit slower, so some complicated animations and displays will be done a bit harder using it, and that is why there is another library allowing the user to control LED drivers directly without a timer, that is the IS31FL3731 library. Our recommendation is, if you want to display simple messages you receive from the web or some data from the sensor or you are a beginner in programming, using the Maker Display Arduino Library, and for complicated and more complex things, where you want more control, use the  IS31FL3731 library.

 

If you do not know how to install the library, check our tutorial.

 

The first example uses the Maker Display Arduino Library for displaying a simple message.

#include "Maker_LED_Matrix.h" //Attaching the Maker LED Matrix library to our program
//Making a class object made in our library, and as an argument in the constructor we supply the data of which version of display we have (Maker Display 2 or Maker display 4)
//It is necessary only to comment the version of display we have:
//Maker_LED_Matrix matrix(MAKER_LED_MATRIX_2);
//Maker_LED_Matrix matrix(MAKER_LED_MATRIX_4);
void setup() {
 Serial.begin(9600); //Start serial communication with 9600 baud
 matrix.begin(&matrix); //Initialization of our library. As an argument, the address of our object is sent from the library. This is very important and has to be done, otherwise moving the photo on the display will not be possible!
 matrix.brightness(25, 1); //Adjust the new display brightness. Set the font brightness to 25 of 255 and backgrounds to 1 of 255 (this will create an effect of the background brightness, if you do not want that, set it to zero).
 //Display the message with a pause of 75 milliseconds between the steps and with a step of 2 pixels, and repeat the message 3 times.
 //If the message needs to be constantly repeated, the last argument should be -1, and if we want it to be static, we must write zero.
 matrix.message("Hello world! This is the message that will be displayed exactly 3 times.", 75, 2, 3);
 delay(60000); //Make a pause long enough for the message to have enough time to display 3 times after which the display will remain empty.
 //Send a new message with a pause of 100 milliseconds between the steps, with a step of 3 pixels and rotate it infinitely (until the new message deletes it).
 matrix.message("This is a Maker LED Display made by the e-radionica team! :)", 100, 3, -1);
 //Now follow how many times has this message displayed and wait for it to display exactly two times after which it continues with the program.
 do{
 delay(100); //Make a small delay for ESP8266 to have enough time to do its tasks (here has to be a delay, otherwise the ESP8266 will crash!).
 }while(matrix.repeatCount() != 2);
 matrix.message("The display is done in the background while we send how many times has this message repeated to the Serial Monitor", 100, 3, -1);
}
void loop() {
 //Display the message on the Serial monitor (UART) while, at the same time, the message is shown on the display.
 Serial.print("The message is displayed");
 Serial.print(matrix.repeatCount(), DEC);
 Serial.println(" puta.");
 delay(1000);
}

The other example also uses Maker Display Arduino Library, but this example, besides displaying the text (message), displays monochromatic image, along with the image in shades of grey (greyscale). To display the image better (better contrast, because small changes in shades at higher intensities are less visible), the Gamma transformation with a factor of 2.2 is used. This value can be changed to Maker_LED_Matrix.h. It also shows that the image during the scrolling can be stopped at the moment, and then resumed by scrolling, calling the stopScroll () and resumeScroll () functions. These two functions are not valid only for images, but are valid for all (message, monochromatic images, greyscale images and Adafruit GFX function).

#include "Maker_LED_Matrix.h" //Attaching the Maker LED Matrix library to our program
//Making a class object made in our library, and as an argument in the constructor we supply the data of which version of display we have (Maker Display 2 or Maker display 4)
//It is necessary only to comment the version of display we have:
//Maker_LED_Matrix matrix(MAKER_LED_MATRIX_2);
//Maker_LED_Matrix matrix(MAKER_LED_MATRIX_4);
//Black and white (monochromatic) image. Sine curve image. It can be any other image, but it is necessary to convert it to the default format.
//Or reset the image to the default resolution (ideal display sizes, but it can also be larger) and convert it using https://www.skaarhoj.com/FreeStuff/GraphicDisplayImageConverter.php
const uint8_t slika[] PROGMEM = {
 0x03, 0xc0, 0x00, 0x00,
 0x0c, 0x30, 0x00, 0x00,
 0x30, 0x0c, 0x00, 0x00,
 0x40, 0x02, 0x00, 0x00,
 0x80, 0x01, 0x00, 0x00,
 0x00, 0x00, 0xc0, 0x03,
 0x00, 0x00, 0x20, 0x0c,
 0x00, 0x00, 0x1c, 0x70,
 0x00, 0x00, 0x03, 0x80,
};
/*
 * 8 bit image in greyscale (256 possible levels of brightness). The image must be converted to a sequence of bytes as shown below.
 * In order to do so, you must follow the instructions:
 *
 * For converting the greyscale image, use the LCD Image Converter program
 * Start the program, New Image-> Enter the name of the image and click OK. Then Image->Import
 * Then pick an image you want to convert (bear in mind that the image should not be bigger than the display resolution). If it is, use Pain to reduce its size.
 * After that, Options->Conversion
 * Preset should be adjusted to Greyscale 8, Type Greyscale, Inverse chosen, Main scan direction: Top to botom
 * Line scan direction should be adjusted to Forward. Then click Image, Block Size should be adjusted to 8 bit and Byte Order should be on Little endian
 * By pressing the Show Preview, the image should be visible and at the same time the sequence (fields) of image data. The colors in this image are contrary to the original. 
 *  Click OK, save it by clicking Save, then File->Convert and save the field data to the file. Open the file and copy it here.
 */
const uint8_t vatra[288] = {
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x69, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x93, 0x93, 0x93, 0x00, 0x00, 0x00, 0x93, 0x69, 0x69, 0x93, 0x93, 0x93, 0x00, 0x93, 0x93, 0x69, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x93, 0x93, 0x93, 0x93, 0x69, 0x93, 0x93, 0x93, 0x93, 0x69, 0x69, 0x69, 0x69, 0x93, 0x93, 0x93, 0x69, 0x69, 0x93, 0x93, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x93, 0x93, 0x93, 0x93, 0x69, 0x69, 0x3f, 0x69, 0x69, 0x69, 0x69, 0x3f, 0x3f, 0x69, 0x69, 0x69, 0x69, 0x3f, 0x69, 0x69, 0x93, 0x93, 0x93, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x93, 0x93, 0x69, 0x69, 0x3f, 0x3f, 0x0f, 0x0f, 0x3f, 0x3f, 0x3f, 0x0f, 0x3f, 0x3f, 0x3f, 0x0f, 0x3f, 0x3f, 0x69, 0x69, 0x69, 0x93, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x93, 0x69, 0x69, 0x3f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x3f, 0x69, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
 Serial.begin(9600); //Start serial communication with 9600 baud
 matrix.begin(&matrix); //Initialize our library. As an argument, the address of our object is sent from the library. This is very important and has to be done, otherwise moving the photo on the display will not be possible!
 matrix.brightness(25, 1); //Adjust the new display brightness. Set the font brightness to 25 of 255 and backgrounds to 1 of 255 (this will create an effect of the background brightness, if you do not want that, set it to zero).
 //Display the message with a pause of 75 milliseconds between the steps and with a step of 2 pixels, and repeat the message once.
 matrix.message("The image will be displayed soon", 75, 2, 1);
 delay(10000); //Make a pause long enough for the message to have enough time to display once after which the display will remain empty.
 //Display the monochromatic sine curve image of 32x9 dimensions with a 100 milliseconds pause between steps, step of 1 pixel and repeat it two times 
 matrix.picture(slika, 32, 9, 100, 1, 2);
 delay(4000);
 matrix.stopScroll(); //Stop the image moving
 delay(3000); //Hold it for 3 seconds
 matrix.resumeScroll(); //Continue scrolling the image
 //Wait for the message to be displayed two times, and then the program continues.
 do{
 delay(100);
 }while(matrix.repeatCount() != 2);
 //Now display the static image in greyscale, 32x9 pixel dimensions, 75 millisecond pause between the steps with one pixel step (although the image is static, we have to hand in the data for pause and motion)
 matrix.picture8Bit(vatra, 32, 9, 75, 1, 0);
 delay(5000); //Holds the image on the screen for a while
 //Before the image is displayed, it is necessary to shut down the "background lighting" or there will be a black frame around the image (made out of extinguished LEDs).
 //Adjust the new image brightness to 128 of 255 immediately
 matrix.brightness(128, 0);
 //Now make the image move constantly
 matrix.picture8Bit(vatra, 32, 9, 75, 1, -1);
}
void loop() {
 //Display the message to Serial monitor (UART) while the message is shown on the display at the same time.
 Serial.print("The image is displayed ");
 Serial.print(matrix.repeatCount(), DEC);
 Serial.println(" times.");
 delay(1000);
}

The third example uses the Maker Display Arduino Library and shows which way you can use Adafruit GFX functions during scrolling (moving). Here the situation is a bit more complicated. Namely, everything you want to be display, and it is related to the Adafruit GFX functions, should be in a separate function. This function must not be neither loop() nor setup(), but some user function. This function must be of void() type and must not have a single argument. Then this function is sent as an argument scrollAll() function which then executes scrolling through the content on the display.

#include "Maker_LED_Matrix.h" //Attaching the Maker LED Matrix library to our program
//Making a class object made in our library, and as an argument in the constructor we supply the data of which version of display we have (Maker Display 2 or Maker display 4)
//It is necessary only to comment the version of display we have:
Maker_LED_Matrix matrix(MAKER_LED_MATRIX_2);
//Maker_LED_Matrix matrix(MAKER_LED_MATRIX_4);
//Black and white (monochromatic) image. Sine wave image. It can be any type of image, but it is necessary to convert it to the default format.
//Or modify the image to the default resolution (ideally to the display size, but it can be larger) and convert it using the
 https://www.skaarhoj.com/FreeStuff/GraphicDisplayImageConverter.php
const uint8_t slika[] PROGMEM = {
 0x03, 0xc0, 0x00, 0x00,
 0x0c, 0x30, 0x00, 0x00,
 0x30, 0x0c, 0x00, 0x00,
 0x40, 0x02, 0x00, 0x00,
 0x80, 0x01, 0x00, 0x00,
 0x00, 0x00, 0xc0, 0x03,
 0x00, 0x00, 0x20, 0x0c,
 0x00, 0x00, 0x1c, 0x70,
 0x00, 0x00, 0x03, 0x80,
};
void setup() {
 Serial.begin(9600); //Start serial communication with 9600 baud
 matrix.begin(&matrix); //Initialize our library. As an argument the address of our object is sent from the library. This is very important and must be done, otherwise moving the image on the screen will not be possible! 
 
 //Adjust the new display brightness. Set the font brightness to 25 of 255 and the background to 1 of 255 (this will create a background lighting effect, if you do not want it, set it to zero).
 //When using the Adafruit functions, color parameters (brightness) take precedence and are sent when drawing different shapes, and then the brightness used with brightness() function.
 //"Background brightness" can be adjusted
 matrix.brightness(64, 1);
 //It is necessary to create a function that will call all Adafruit functions Potrebno je napraviti funkciju u kojoj ce se pozivati sve Adafruitove funkcije.
 //Therefore, to this function we enter everything that is supposed to be displayed u tu funkciju se upisuje ono sto treba biti ispisano na displayu.
 //In this example, into the function oblici() we enter all Adafruit functions (drawLine(), drawRect, drawCircle(), itd...). U ovom primjeru, u funkciju oblici() upisujemo sve Adafruitove funkcije (drawLine(), drawRect, drawCircle(), itd...).
 //DO NOT CALL ADAFRUIT FUNCTIONS FROM THE MAIN PROGRAM (LOOP) OR FROM THE SETUP, they must be in a separate function! NE POZIVATI TE ADAFRUIT-OVE FUNKCIJE IZ GLAVNOG PROGRAMA (LOOP-A) ILI IZ SETUPA, one moraju biti u posebnoj funkciji!
 //The function has to be of void type and must not contain any arguments. Funkcija mora biti tipa void i ne smije sadrzavati niti jedan argument.
 //After this function is made, we will send it as an argument to the (callback) function which will send a record to the display
 matrix.scrollAll(oblici, 150, 3, -1); //Send everything from the function shapes to the display and move it from right to left, with a 150 milliseconds pause between the steps, 3 pixel step and repeat it continuously.
}
void loop() {
}
//The function that contains everything we want to display, and it is about Adafruit functions.
void oblici() {
 matrix.setCursor(0,0); //Set the cursor for displaying the text on the beginning
 matrix.print("Adafruit GFX funkcije :)"); //Display the text
 matrix.drawLine(150, 0, 170, 8, 128); //Draw a line from the coordinated point (150, 0) to the (170, 8), brightness 128 of 255
 matrix.drawRect(180, 2, 15, 4, 64); //Draw a rectangle of the starting point coordinates (180, 2), length 15, height 4 pixels, brightness 64 of 255
 matrix.fillCircle(210, 3, 3, 160); //Draw a cirle of center coordinates (230, 3), 3 pixel radius, brightness 160 of 255
 matrix.drawBitmap(230, 0, slika, 32, 9, 40); //Draw a sine vawe image, at the location (230, 0), dimensions 32x9 pixel and 40 brightness
 //These are not the only functions, all standard functions from the Adafruit GFX library are supported!
}

The fourth example this time uses the IS31FL3731 library. This library allows higher flexibility and better control over LED drivers. The example displays a text, different shapes using the Adafruit GFX function, and then displays how long the board works (in seconds) since we have connected it to the power supply (using the function millis()). We should note that the library works so that the whole image generates in RAM, and then calling the display() function the whole content of RAM is sent to display.

#include "IS31FL3731.h" //Attaching the Maker LED Matrix library to our program
//Making a class object made in our library, and as an argument to the constructor we hand in the data about how much LED drivers we have (two to four maximum) 
//The driver addresses go as follows: the first driver has an I2C address 0x74, the second 0x77, the third 0x75 and the fourth 0x76. If the order does not match, it can be changed in the IS31FL3731.h file.
IS31FL3731 led = IS31FL3731(2);
void setup() {
 led.begin(); //Initialization of the library.
 led.setTextColor(25); //Adjusting the font brightness to 25 of 255.
 
 led.print("Hello"); //Displaying the text in the beginning of the display (0, 0)
 led.display(); //Displaying the buffer content (this function has to be called after all functions for drawing shapes and text are called in order to send the content of the memory to the display itself)
 delay(2000); //Display delay.
 
 led.clearDisplay(); //Clear everything in memory and set the text cursor to the beginning.
 led.print("world"); //Display the text.
 led.display(); //Send content to the display.
 delay(2000); //Display delay.
 
 led.clearDisplay(); //Clear everything in memory and set the text cursor to the beginning.
 led.fillRect(0,0,32,9, 5); //Draw the filled in rectangle at the location (0, 0) in the size of 32x9 pixels, brightness (color) 5 of 255.
 led.drawLine(0,8,32,0, 64); //Draw a line from the coordinated point (0, 8) to the (32, 0), brightness (color) 64 of 255.
 led.drawRect(0,0, 32, 9, 128); //Draw a rectangle at the location (0,0), size 32x9 pixel, brightness (color) 128 of 255.
 led.fillCircle(15,4,3, 20); //Draw a filled in circle with a centre at the location (15,4), 3 pixel radius, brightness (color) 20 of 255.
 led.display(); //Send content to the display.
 delay(5000); //Display delay.
}
void loop() {
 led.clearDisplay(); //Clear everything in memory and set the text cursor to the beginning.
 led.print("T:"); //Display the text.
 led.print(millis()/1000); //Display how long (how many seconds) does the board work.
 led.display(); //Send content to the display.
 delay(100); //Display delay.
}

The fifth example uses the Maker Display Arduino Library and APDS9960 library. This example shows how you can read data from the sensor and display the same data. It is about reading a gesture from the APDS9960 sensor and the recognized gesture is displayed. Maker LED Display and APDS9960 sensor need to be connected according to the image which is under the “How to connect” part of the text. We use the easyC cable and easyC adapter for connecting.

 

IMPORTANT: Some sensors are not compatible with LED drivers which divide the I2C bus. If it is the case, it is necessary to use other pins (unused, on the back side of the Maker LED Display board), and an example of how this type of program looks can be found under Examples -> Maker_LED_Matrix -> Maker_LED_Matrix_sensor_example or in continuation of this tutorial.

IMPORTANT: If the sensor refuses initialization or reads false data, try adding the capacitor of at least 47uF between the sensor’s power supply.

#include <Wire.h> //Attaching the Wire library to our program (for the I2C communication).
#include <SparkFun_APDS9960.h> //Attaching the APDS9960 sensor library to our program (you can find the library here: https://github.com/sparkfun/SparkFun_APDS-9960_Sensor_Arduino_Library).
#include <Maker_LED_Matrix.h> //Attaching the Maker LED Matrix library to our program.
//Making a class object made in our library, and as an argument to the constructor we hand in the data about which display version we have (Maker Display 2 or Maker Display 4)
//It is necessary only to comment the version of display we have:
//Maker_LED_Matrix matrix(MAKER_LED_MATRIX_2);
//Maker_LED_Matrix matrix(MAKER_LED_MATRIX_4);
SparkFun_APDS9960 apds = SparkFun_APDS9960(); //Make a class object in the library.
void setup() {
 matrix.begin(&matrix); //Initialization of our library. As an argument the address of our object is sent from the library. This is very important and must be done, otherwise moving the image on the screen will not be possible!
 if (apds.init() ) { //Check if you are able to find the sensor, if everything is fine with it, and if it is, display the message.
 matrix.message("Sensor found!", 100, 2, 1);
 } else {
 matrix.message("Sensor not found! :( Check the connections.", 100, 2, -1); //If the sensor is not found, something is wrong with it or the connections, therefore there is no sense in continuing the program.
 do {
 delay(1);
 } while (true);
 }
 //Wait for the message to display fully.
 do {
 delay(10);
 } while (matrix.repeatCount() != 1);
 //Activate motion detection on the sensor. If it is successfully activated, it displays a message.
 if ( apds.enableGestureSensor(false) ) {
 matrix.message("Wave your hand in front of the sensor :)", 100, 2, -1);
 } else {
 matrix.message("Initialization of the gesture sensor is unsuccessful :(", 100, 2, -1); //If not, inform the user with the message on the display and stop the program execution.
 do {
 delay(1);
 } while (true);
 }
}
void loop() {
 //This is very important! Since the sensor is connected to the same I2C pins as the LED driver, it is necessary to stop scrolling (and thus sending data to the LED display).
 //Scrolling is done using a software (Ticker.h library) that periodically sends data to the I2C according to the display..
 //This stop is done so that the situation does not happen to read the data from the sensor and that at that same moment it is not asked to send the data to the printout. Two communications on the I2C bus are not allowed at the same time.
 matrix.stopScroll();
 if ( apds.isGestureAvailable() ) { //Read if any gesture is detected by the APDS9960 sensor.
 switch ( apds.readGesture() ) { //If it is, read what gesture it is about and display the appropriate message (it is not necessary to transfer I2C to pins 4 and 5, because the display library does that itself).
 case DIR_UP:
 matrix.message("Direction up", 100, 3, -1);
 break;
 case DIR_DOWN:
 matrix.message("Direction down", 100, 3, -1);
 break;
 case DIR_LEFT:
 matrix.message("Direction left", 100, 3, -1);
 break;
 case DIR_RIGHT:
 matrix.message("Direction right", 100, 3, -1);
 break;
 case DIR_NEAR:
 matrix.message("Close gesture", 100, 3, -1);
 break;
 case DIR_FAR:
 matrix.message("Distant gesture", 100, 3, -1);
 break;
 default:
 matrix.message("Unknown gesture", 100, 3, -1);
 }
 }
 matrix.resumeScroll(); //Continue scrolling the message on the display (also for the display and ESP8266 to continue communicating via I2C).
 delay(100); //A short pause between reading new gestures.
}

The sixth example is similar to the previous one. It also shows how to use the sensor (or any other I2C  device), and displaying the read data, but this time we use the IS31FL3731 library. The sensor used is the APDS9960, and it is necessary to connect it using the easyC cable and easyC adapter as in the image which is shown in the “How to connect” part.

#include "IS31FL3731.h" //Attaching the Maker LED Matrix library to our program
#include "SparkFun_APDS9960.h" //Attaching the APDS9960 sensor library to our program (https://github.com/sparkfun/SparkFun_APDS-9960_Sensor_Arduino_Library)
//Making a class object made in our library, and as an argument to the constructor we hand in the data about how much LED drivers we have (two to four maximum) 
//The driver addresses go as follows: the first driver has an I2C address 0x74, the second 0x77, the third 0x75 and the fourth 0x76. If the order does not match, it can be changed in the IS31FL3731.h file.
IS31FL3731 led = IS31FL3731(2);
SparkFun_APDS9960 apds; //Make a class object in the library
void setup() {
 led.begin(); //Initialization of the library.
 led.setTextColor(25); //Adjusting the font brightness to 25 of 255.
 if (!apds.init()) { //Initialization of the sensor library, report an error on the display if it is not possible to find a sensor
 led.print("Err!");
 led.display();
 } else {
 led.print("OK!");
 led.display();
 }
 
 delay(2000); //Keep the message on the display for a while.
 led.clearDisplay(); //Clear buffer (memory) and set the text cursor to the beginning.
 
 if ( apds.enableGestureSensor(false) ) { //Start reading the gesture on the APDS9960 sensor without the interrupt routine. If the initialization was fine, display the message.
 led.print("Ready");
 led.display();
 } else {
 led.print("Fail");
 led.display(); //If not, inform the user with the message on the display and stop the program execution.
 do {
 delay(1);
 } while (true);
 }
}
void loop() {
 if (apds.isGestureAvailable()) { //Keep checking if the right gesture is recognized.
 led.clearDisplay(); //Clear buffer (memory) and set the text cursor to the beginning.
 switch (apds.readGesture()) { //If it is, read what gesture it is about and display the message about it, and repeat it until the next gesture.
 case DIR_UP:
 led.print("Up");
 break;
 case DIR_DOWN:
 led.print("Down");
 break;
 case DIR_LEFT:
 led.print("Left");
 break;
 case DIR_RIGHT:
 led.print("Right");
 break;
 case DIR_NEAR:
 led.print("Near");
 break;
 case DIR_FAR:
 led.print("Far");
 break;
 
 default: //If the gesture is unknown, display the message.
 led.print("????");
 }
 led.display(); //Display the content.
 }
 delay(100); //Pause, necessary for the ESP8266 and the display itself.
}

The last example shows how to use the sensor which does not work properly when connected to the easyC connector, but it uses other, available pins on the ESP8266 microcontroller for communication. An example shows reading a gesture via APDS9960 sensor and showing the detected gesture on the display. For displaying we use the Maker Display Arduino Library.

#include <Wire.h> //Attaching the Wire library to our program (for the I2C communication).
#include <SparkFun_APDS9960.h> //Attaching the APDS9960 sensor library to our program (you can find the library here: https://github.com/sparkfun/SparkFun_APDS-9960_Sensor_Arduino_Library).
#include <Maker_LED_Matrix.h> //Attaching the Maker LED Matrix library to our program.
//Making a class object made in our library, and as an argument in the constructor we supply the data of which version of display we have (Maker Display 2 or Maker display 4)
//It is necessary only to comment the version of display we have:
//Maker_LED_Matrix matrix(MAKER_LED_MATRIX_2);
//Maker_LED_Matrix matrix(MAKER_LED_MATRIX_4);
SparkFun_APDS9960 apds = SparkFun_APDS9960(); //Make a class object in the library.
void setup() {
 matrix.begin(&matrix); //Initialization of our library. As an argument, the address of our object is sent. This is very important and has to be done, otherwise motion of the image on the display will not be possible! 
 Wire.begin(12, 13); //Set the I2C pins to 12 and 13 now (normally 4 and 5 are the ones which the LED Mtrix is connected to). This must be done before each communication with the APDS9960 if it is connected to pins different than 4 and 5. 
 if (apds.init() ) { //Check if it is possible to find the sensor, and if everything is fine with it, if it is, display the message.
 matrix.message("Sensor found!", 100, 2, 1);
 } else {
 matrix.message("Sensor not found! :( Check the connections.", 100, 2, -1); //If the sensor is not found, something is wrong with it or connections, so it makes no sense to continue the program.
 do {
 delay(1);
 } while (true);
 }
 //Wait for the message to display fully.
 do {
 delay(10);
 } while (matrix.repeatCount() != 1);
 //Activate motion detection on the sensor. If it is successfully activated, it displays a message.
 Wire.begin(12, 13);
 if ( apds.enableGestureSensor(false) ) {
 matrix.message("Wave your hand in front of the sensor :)", 100, 2, -1);
 } else {
 matrix.message("Initialization of the gesture sensor is unsuccessful. :(", 100, 2, -1); //If not, inform the user with the message on the display and stop the program execution.
 do {
 delay(1);
 } while (true);
 }
}
void loop() {
 //This is very important! Since the sensor is connected to other I2C pins (12 as SDA and 13 as SCL), it is necessary to stop the motion (and by that, stop sending data to LED display which is connected to pins 4 and 5 ESP8266).
 matrix.stopScroll();
 //Then shift to the I2C communication, to pins 12 and 13 on the ESP8266 microcontroller in order to communicate with the APDS9960 sensor successfully.
 Wire.begin(12, 13);
 if ( apds.isGestureAvailable() ) { //Read if any gesture is detected by the APDS9960 sensor.
 switch ( apds.readGesture() ) { //If it is, read what gesture it is about and display the appropriate message (it is not necessary to transfer I2C to pins 4 and 5, because the display library does that itself).
 case DIR_UP:
 matrix.message("Direction up", 100, 3, -1);
 break;
 case DIR_DOWN:
 matrix.message("Direction down", 100, 3, -1);
 break;
 case DIR_LEFT:
 matrix.message("Direction left", 100, 3, -1);
 break;
 case DIR_RIGHT:
 matrix.message("Direction right", 100, 3, -1);
 break;
 case DIR_NEAR:
 matrix.message("Close gesture", 100, 3, -1);
 break;
 case DIR_FAR:
 matrix.message("Distant gesture", 100, 3, -1);
 break;
 default:
 matrix.message("Unknown gesture", 100, 3, -1);
 }
 }
 matrix.resumeScroll(); //Continue scrolling the message on the display (also for the display and ESP8266 to continue communicating via I2C).
 delay(100); //A short pause between reading new gestures.
}