Skip to content

2 Introduce the screen user interface and external speakers for playing songs

Welcome to the second lesson of learning. I believe that after completing the first lesson, everyone has gained a deeper understanding of our product. Next, I will lead you to the first application case of the Advance series products - connecting to WiFi to play songs.

1 Product Interface Introduction


When you power on the product, you will see the following interface.

The following interface was generated by introducing the official firmware of LVGL, and the specific operation will not be explained in this lesson for now. In the next class, we will mainly explain the LVGL graphics library. You can follow our updates to facilitate your learning.

(The interface has not yet developed any functions and can only be viewed by sliding the interface.)

1

2

3

However, you can choose the theme color you want to use.

4

2 Download Code


Click the link below to download the code you need.

Code link:

CrowPanel-Advance-7-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-800x480/example at master · Elecrow-RD/CrowPanel-Advance-7-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-800x480

position image

Then select the corresponding course code for downloading.

position image

2.1 Using Arduino IDE to Open Code

8

2.2 Code Introduction

You can understand the overall code based on the comments after each line of code.

(If you want to have a deeper understanding of code construction, you can go watch a video explanation.)

9

Before using the code, please change the wifi account and password in the code. The settings in the code are for our company's wifi; you need to set it to the one you are using yourself.

image-20260605180943556

When the program fails to detect the target device, it will send command 250 to address 0x30, which is used to wake up or initialize the onboard control MCU and touch screen circuit. At the same time, a reset pulse is generated through GPIO1 to help the related hardware restart, until the device can be recognized normally.

image-20260612144439640

After confirming that the onboard MCU is functioning properly, the program will send command 248 to address 0x30 to enable the onboard audio amplifier. Only after the amplifier is activated can the audio data output via I2S ultimately drive the speakers to produce sound.

image-20260612144640344

After specifying an MP3 network link through audio.connecttohost(), the Audio library will automatically complete tasks such as server connection, audio data download, MP3 decoding, and PCM data output. Users can enjoy online music playback without having to concern themselves with the underlying audio processing procedures.

image-20260612144732239

The audio.loop() function is the core function for the normal operation of the Audio library and needs to be continuously called within the loop() function. It is responsible for receiving network data, decoding the audio stream, managing the buffer, and outputting audio data to the I2S. It acts as the scheduling center for the entire audio playback task. If this function is not continuously executed, even if the network connection and audio stream acquisition have been successfully established, the sound cannot be played normally.

image-20260612144832016

3 Configure library file


3.1 Select the appropriate library file based on the product screen size

Click the link below to download the corresponding library file.

Library file link:

CrowPanel-Advance-7-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-800x480/example/V1.3_and_V1.4_and_V1.5/arduino/libraries at master · Elecrow-RD/CrowPanel-Advance-7-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-800x480

If you are not sure where to place the library files and how to configure them properly so that the code can correctly recognize these library files, please refer to the operation steps in the first lesson.

4 How to play the song we want to play


Principle:

After the CrowPanel ESP32 Advance HMI is connected to WIFI, it will search for this song through the URL link provided in our code and achieve network playback (this is an external link for a song)

15

Note: The audio stream encoding formats supported by the parameters of the audio.connecttohost function, such as MP3, AAC, FLAC, etc

The reason why people do not use familiar music websites such as Spotify, Apple Music, and YouTube Music to play songs is because most legitimate music streaming services only provide song page links or embedded player code to play music. To protect copyright, not providing direct download links in MP3 format, distributing or obtaining MP3 download links directly may violate the terms of service and copyright laws of these platforms. So we didn't use it. We use Chinese music websites to play music here. If you want to use a music website that you are familiar with, just find a URL link in MP3 format similar to the one in the code and replace it.

First, connect our speakers

16

In NetEase Cloud Music or other music platforms, the ID of a song is usually a unique identifier for each song. So the main thing is to replace the ID number in the URL link in the code

17

Next, I will use NetEase Cloud Music as an example to introduce, searching for an ID number

Use a browser to search for NetEase Cloud Music and open it

18

Play the song you want to listen to

19

Retrieve the ID number from the link and replace it with the ID number in the code

20

This way, you can change the music you want to play. (Remember to re burn the program after changing the ID)
Tips:
1. If the program runs without errors but the song doesn't play, you should check the URL to ensure that the provided link is correct.
2. If the song you want to play is a VIP song, it cannot be played.
3. Before burning the code, remember to configure the environment in which the code will run.

Kind Reminder:

You are currently viewing the 7-inch product of CrowPanel Advance HMI, and the version here is V1.3 / V1.4 / 1.5. (The following content is also applicable to the 5.0-inch V1.2 / v1.3 and 4.3-inch V1.1 / V1.2 / V1.3 versions.)

In terms of hardware, we use a microcontroller (STC8H1K28) to control the screen backlight, speaker on/off, and buzzer.

advance-7-1.3-1

(However, there are other function interfaces that need to be written in the specific code, and you can refer to the complete code provided later.)

Explanation:

  • 0x30 is the I2C address of the microcontroller (STC8H1K28).

  • 0x5D is the I2C address of the touch IC (GT911).

  • sendI2CCommand(0) means sending command 0 to the microcontroller (address 0x30) to instruct it to set the screen brightness to maximum.

For 0 mentioned above, you can replace it with the following values:

  • 0 is the brightest backlight.

  • 0 to 245: The screen brightness will gradually increase to the minimum value

  • 245 represents turning off the screen light

Additional notes:

You can also control the following functions by sending other instructions to the microcontroller:

  • It means sending the 248 command to the microcontroller (0x30) to instruct the speaker to turn on.

advance-7-1.3-2

  • It means sending the 249 command to the microcontroller (0x30) to instruct the speaker to turn off.

advance-7-1.3-3

  • You can also send command 246 to control the buzzer to turn on, and send command 247 to control the buzzer to turn off.

advance-7-1.3-4

Be careful:

For large-sized products, 4.3 inches, 5.0 inches, 7.0 inches.

Before burning the code, be sure to set the switch on the back of the product to MIC&SPK mode.

20-1

5 Attention

If your code compiles incorrectly, you can check if the ESP32 version number is correct. The ESP32 version number we need for this lesson is 3.0.2.

new-1

Secondly, please pay attention to replacing the corresponding size library file.

Please refer to the content of the "Configure library file" mentioned above.