Weihnachten 2024 - LED Matrix und ein singender Weihnachtself - AZ-Delivery

The little ones at home already count the days until Christmas and the gifts and the start of the decorative of the house follow with Christmas motifs, especially the tree. Everything is a little messy, but with great enthusiasm.

How about a project we add to our decoration? In this project we decided to use four WS2812B 16x16 panels with 256 LEDs each, a Mini MP3 player DFPlayer Master module and a mini speaker DFPlayer Mini 3 Watt 8 Ohm. All of this is managed with the AZ-ATMEGA328 board microcontroller. With all these components we will show the image of a Christmas elf that will sing a small part of a Christmas carol at every adjustable time. This project serves as a small inspiration and demonstration that can be used to implement more pictures and songs to surprise the little ones in this way. 

There is not much time left until the most beautiful night of the year. We have to design the decoration so that it gives the true protagonist of Christmas a surprise. Let's start with the project.

Hardware

Software components

The libraries can also be installed through the library manager in the Arduino IDE.

Circuit and description of the modules used

Download the circuit

The four RGB LED panels were positioned in a 2x2 formation so that we receive a grid of 32x32 LEDs. To play the song or other songs, we use the Mini DFPlayer module (a 1k ohm resistance must be used in the module to adapt the voltage in the communication line). A microSD card must be used on which the 2.MP3 file is saved. All modules and components mentioned above are controlled by the AZ-ATMEGA328 board microcontroller. As far as the power supply is concerned, according to the data sheet, each panel with all LEDs in white and 100 % brightness would consume 0.3 W, which would result in a total consumption of 76.8 W with the 256 LEDs. However, the good news is that in this sketch the brightness is not to 100 %, but to a value of 7 of 254, so that not all LEDs shine at the same time and not all are white.

Description of the project run and sketch

The course of this project is very simple: First it will be AZ-Delivery Logo for 3 seconds, then the message "Wishes You Merry Xmas" for 3 seconds, then played a small Christmas carol while a Christmas elf is shown. To give the impression that you sang during the song, the small area of ​​the mouth changes with 5 different pictures. When the song ends, it shows a kind of fireworks rocket and wishes the new year with "Happy New Year". When the set time has passed, the microcontroller resigns via its RST port by changing his condition from High to Low on digital port 12 to display all previous images again. Let's start with the analysis of the sketch.

Sketch download

In order to be able to use the modules correctly, the libraries required must always be implemented in the section for the definition of the global variables (at the beginning of the sketch). The first library to be added is Adafruit_gfx.h, This is the main graphics library, which provides the necessary methods for drawing primitive graphics (points, lines, circles, etc.). The second library to be added is Adafruit_neopixel.hthat is required to control the three internal LEDs on the panels. The third is the library Softwareerial.H, which enables the microcontroller to release every digital PIN for serial communication, which is necessary to use the MP3 player module. Dfrobotdfplayermini.h is the library that enables the functions required for the use of the MP3 module.

#include "Adafruit_gfx.h"
#include <Adafruit_neopixel.h>
#include <Software.h>
#include <Dfrobotdfplayermini.h>

Next, a first constant with the total number of the LEDs (1024) of the four panels is created and a second to specify PIN 7 of the microcontroller to which we have connected the data line of the first panel. We only need one data line because the panels are switched into series.

#define Num_Leds 1024
#define Pin 7

The object follows mysoftware To use the MP3 player module via the serial interface. In this project, the digital PIN 10 of the microcontroller is used to receive data from the MP3 module. The digital PIN 11 is used to send data to the MP3 module. To use the module's tax methods and commands, such as: B. the adjustment of the volume or starting the reproduction of an MP3 file will be the object mydfplayer From the library Dfrobotdfplayermini.h created.

Software mysoftware(10, 11);
Dfrobotdfplayermini mydfplayer;

Then that will Picture object the library Adafruit_neopixel.h Implemented with the number of LEDs on the panel and PIN 7. The internal layout is green, red and blue (neo_grb).  The last value of the arguments is the operating frequency (800 kHz).

Adafruit_neopixel picture(Num_Leds, Pin, Neo_grb + Neo_khz800);

A number of colors are defined, but not all colors are used.

uint32_t P_Red = picture.Color(150,0,0);
uint32_t p_green = picture.Color(0,150,0);
uint32_t P_Blue = picture.Color(0,0,150);
uint32_t P_YELLOW = picture.Color(150,150,0);
uint32_t P_Purple = picture.Color(150,0,150);
uint32_t p_light_blue = picture.Color(0,150,150);
uint32_t P_white = picture.Color(150,150,150);
uint32_t P_MAROON = picture.Color(150,51,0);
uint32_t P_black = picture.Color(0,0,0);

After the libraries implemented, created the module objects and the necessary variables have been created, the initial configuration of all modules in the method must set up() be defined. First of all, the digital pin 12 has to DigitalWrite (12, high) be placed on high and with Pinmode (12, output) he is configured as an output. In this way, the digital pin, which is connected to the RST pin of the microcontroller, is set to high and prevents it from being reset.

digital(12, HIGH);
pin mode(12, OUTPUT);

In order to produce communication between the microcontroller and the MP3 module, the Software initialized and the data transfer speed with MySoftwareerial.begin (9600) set to 9600 baud. Communication with the serial monitor is with Serial.begin (115200) Initialized with the speed in brackets. In order to obtain the reports on the initialization status or error of the MP3 module, the speed in the lower right part of the serial monitor must be selected when opening.

mysoftware.Begin(9600);
Serial.Begin(115200);

The next step is the initialization of the MP3 module. IF statement is used to check the correct initialization. It is checked whether the MP3 module has not been initialized for any reason. The symbol "!" Negrises the condition. So if the module is not initialized, the condition is true and the code within the curly brackets is carried out. The serial console informs that the connections and the insertion of the microSD card must be checked. On the other hand, if the MP3 module is correctly initialized, the condition is not met and the code explained by us is not carried out. The set up()-Methods continue to be carried out and via the serial console with the line Serial.println (f ("correct dfplayer initialization.")) It is informed that the MP3 player module was correctly initialized.

IF (!mydfplayer.Begin(mysoftware)) {
  Serial.print(F("Error Initializing MP3 Module:"));
  Serial.print(F("1. Please check the connections!"));
  Serial.print(F("2. Please insert the microsd memory!"));
  while(true){
    delay(0);
  }
}

Serial.print(F("Correct dfplayer initialization.")); 

After initialization of the MP3 module, the image object created from the Neopixel library is initialized in order to enable the images to be displayed on the LED panels. A break of 2 seconds is taken to ensure that initialization is correct.

picture.Begin();
delay(2000);

As soon as the set up()-Method is ended, the Loop ()-Method with the display of the welcome messages and our elf begins with singing the Christmas carol.

First with picture.clear () All LEDs switched off. This happens in case that one of them has been left for some reason. Next, the brightness of the LEDs is included pictures.setbrightness (7) set. In this sketch it was set to a low value (7 of 254). The display is good, but here each user can set the brightness of the LEDs with greater intensity, if desired by adapting the number to brackets. The maximum value is 254.

picture.clear();
picture.setbrightness(7); 

Next will be the method show_az_logo () called up that AZ-Delivery-Logo indicates the LED arrays for 3 seconds. There are many individual commands. Let's only briefly analyze the called.

Each LED used is configured at the beginning. The logo is in red with Picture.Setpixelcolor (Led Number, Color) displayed. In the arguments you must specify the number of LED (LED number) and the color to be displayed (color). The color is configured at the beginning of the sketch. It should be noted that when using four matrices that are switched into series, each LED has a clear number. The first LED always has the number 0 and the number of the last LED 1023, which results in a total of 1024 LEDs.

If all LEDs that are supposed to display the logo are configured, we use the instructions show() of the image object to switch on the LEDs. The logo is displayed on the arrays for 3 seconds. At the end of this period, all LEDs are switched off and the program returns to the line from which this method was called.

picture.show();
delay(3000);
picture.clear();

The image that is displayed on the LED arrays:

The next line of the sketch is calling the method merry_xmas () on that shows a Christmas message. As you can see, the same steps are carried out as in the previously explained method. First the LEDs are configured with one color. Subsequent lights up for 3 seconds and after this time you will be switched off to the line of the sketch from which this method was called.

That then looks like this:

After the Christmas greeting, the following lines are executed to manage the sound file. First the playback strength is included mydfplayer.volume (15) set to a value of 15 of 30. Then the file to be played is specified, in this case the file 2.mp3that must be saved on the microSD card. The command Yield () is used in processes, the execution of which takes a lot of time.

mydfplayer.volume(15);
mydfplayer.play(2);
yield();

To visualize the goblin on the LED arrays, the method becomes Draw_Goblin () called. The steps are similar again to the two methods described above. The desired color of the LEDs with Picture.Setpixelcolor (Led Number, Color) adjust and then with pictures.show () turn on. The image to be presented is then this:

In order to realize the movement of the mouth of our elf, the execution of various methods is programmed, which change the color of the LEDs in the area of ​​the mouth. Each position is displayed for a number of milliseconds. So it seems that the elf sings the song. Here, too, the commands of the methods look similar to those described above.

  • Draw_mouth_1 ()

       

  • Draw_mouth_2 ()

       

  • Draw_mouth_3 ()

       

  • Draw_mouth_4 ()

       

  • Draw_mouth_5 ()

       

When the song is over, all LEDs will appear a kind of fireworks rocket after the method Fireworks () was executed. Creating the animation is similar to that of the singing goblin. The full picture looks like this:

If then the method show_happy_new_year () the picture appears with the New Year's greetings:

This last picture is displayed for 15 minutes with the execution of Delay (900000). Since 900,000 milliseconds correspond to 15 minutes, this waiting time can be changed in order to adapt this project to the wishes of each user. After the specified time, the digital PIN 12 of the microcontroller will go into the low state with the execution of the DigitalWrite command (12, low) and bring about the restart of the microcontroller. With this reset, the RAM memory of the microcontroller is released in order to avoid saturation and to prevent the sketch from being carried out.

delay(900000);
picture.clear(); 

digital(12, Low); 

You can find the arrangement and numbering of the respective LEDs on the four panels for the above images here Again as PDF files.


If that video is not displayed, please check the cookie settings of your browser!

We hope that you like this family Christmas project and encourage you to create new pictures with the little ones. The imagination is something infinite and has no limits. We wish you a lot of fun, a Merry Christmas and a Happy New Year.

DisplaysFür arduinoProjekte für anfänger

Laat een reactie achter

Alle opmerkingen worden voor publicatie gecontroleerd door een moderator

Aanbevolen blogberichten

  1. ESP32 jetzt über den Boardverwalter installieren - AZ-Delivery
  2. Internet-Radio mit dem ESP32 - UPDATE - AZ-Delivery
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1 - AZ-Delivery
  4. ESP32 - das Multitalent - AZ-Delivery