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


You can click the link below to download the corresponding version of the code for this lesson.

Code link:

3.5-inch V1.0

https://github.com/Elecrow-RD/CrowPanel-Advance-3.5-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-480x320/tree/master/example/V1.0/Arduino/lesson-02/OnlineAudio_small

3.5-inch V1.2、V1.3 、V1.4

CrowPanel-Advance-3.5-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-480x320/example/V1.2_and_V1.3_and_V1.4/Arduino_Code/lesson-02/OnlineAudio_small at master · Elecrow-RD/CrowPanel-Advance-3.5-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-480x320

2.1 Using Arduino IDE to Open Code

This is the code for the 3.5-inch V1.0 version.

8

This is the code for the 3.5-inch V1.2 / V1.3 / V1.4 version.

Compared with V1.0, the control of the speaker only uses pin 21.

8_1

2.2 Code Introduction

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

This is the code for the 3.5-inch V1.0 version.

9

This is the code for the 3.5-inch V1.2 / 1.3 / 1.4 version.

9_1

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.

35_image_2_01

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

Version 1.1

V1.1 upgraded, optimized the amplifier circuit, better sound quality, and use IO21 to control mute. i2s_mic changed to two pins IO9 and IO10 control.

Version 1.2 / 1.3 / 1.4

Only the button component has been updated. All other hardware and I/O pins remain the same as in the previous version.

3 Configure library file

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

Click the link below to download the relevant library files.

Library file link:

CrowPanel-Advance-3.5-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-480x320/example/V1.2_and_V1.3_and_V1.4/Arduino_Code/libraries at master · Elecrow-RD/CrowPanel-Advance-3.5-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-480x320

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

This is the connection diagram for the 3.5-inch V1.0 speaker.

16

This is the connection diagram for the 3.5-inch V1.2 / V1.3 / V1.4 speaker.

(Compared to V1.0, the volume control knob has been removed here.)

16_1

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.

Before burning the code, remember to configure the environment in which the code will run.

For small sizes, there is no need to dial the code and it can be directly burned.

5 How to adjust the size of the sound output from the speaker


Note: The V1.2 / V1.3 / V1.4 version does not have this volume control knob.

When an external speaker is connected, this is the power consumption that our built-in amplifier chip can provide

21

5.1 The volume can be adjusted by adjusting the knob

22

If you are using the V1.2 / V1.3 / V1.4 versions of the 3.5-inch products, please note that these two versions have removed the onboard volume adjustment knob. Therefore, it is no longer possible to adjust the speaker volume through the knob.

Meanwhile, in the V1.2 / V1.3 / V1.4 versions, we have optimized the audio power amplifier circuit. While enhancing the audio quality, we have simplified the mute control method. Now, the mute control of the speakers can be achieved simply by using IO21.

Furthermore, the pin configuration of the I2S microphone (i2s_mic) has also been adjusted. In the new version, the control is achieved using IO9 and IO10 pins. Therefore, when porting or running the sample code, please confirm the correctness of the relevant pin configuration based on the hardware version you are using to ensure that the audio function works properly.

5.2 Adjustment principle

This refers to the 3.5-inch V1.0 versions.

Open the schematic diagram we provide

CrowPanel-Advance-3.5-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-480x320/Eagle_SCH&PCB/1.0/ESP32 Display 3.5 inch V1.0.pdf at master · Elecrow-RD/CrowPanel-Advance-3.5-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-480x320

By changing the resistance of the R51 adjustable resistor, the volume can be adjusted.

24

6 Attention


6.1 OnlineAudio_small

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.

Select the appropriate library file based on the product screen size

You can refer to the third point mentioned above, "Configure library file".