From retro to smart: DIY Bluetooth Audio System

0 113 Easy

I looked at the online documentation  for DFPlayer Pro and read that this device can also be used as a USB sound card. The idea immediately came to me to build a very simple Bluetooth speaker with UNIHIKER. Since UNIHIKER has already installed all the necessary packages/libraries, I was able to implement the project in just a few minutes without writing a line of code.

STEP 1
OBJECTIVE

In this tiny tutorial, you will learn how to connect your mobile to the UNIHIKER device via Bluetooth and use the DFPlayer Pro connected to a speaker to play music wireless. We will utilize tools like bluetoothctl to establish the connection.

HARDWARE LIST
1 UNIHIKER
1 DFPlayer Pro
1 Speaker
1 USB cable
1 Jumper wires
STEP 2
HARDWARE SETUP

Connect your speaker(s) to the L+/L- and/or R+/R- pins of the DFPlayer Pro. Once this is done, you can connect the DFPlayer Pro to the UNIHIKER via USB.

 

 

Note: I simply mounted my speaker in a cardboard box so that I can't get to the magnets so quickly (with other electronic devices) and so that the bass can be heard a little better.

STEP 3
TESTING THE SETUP

Ensure the DFPLayer is in "slave mode" which is default after start. Do not press the DFPlayer button! You can verify on UNIHIKER if sound card is active.

 

Use SSH or open the terminal directly on the UNIHIKER. If you haven't changed anything in the basic configuration, the user is "root" and the password is "dfrobot".

CODE
# use SSH to open the terminal directly on the UNIHIKER
$ ssh [email protected]

# list all audio devices
$ aplay -l
...
card 2: BR21 [JieLi BR21], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

You can test whether the sound can be heard at all with the following command.

CODE
# set volumne to 80%
$ amixer set 'Master' 80%

# play a test sound
$ aplay /usr/share/sounds/alsa/Front_Left.wav

If you have now heard the test sound, you can carry out the next steps.

STEP 4
BLUETOOTH CONNECTION

Now turn on Bluetooth on your mobile and start the scan on UNIHIKER.

CODE
# scan for Bluetooth devices on UNIHIKER
$ bluetoothctl scan on

Find your mobile in the list of scanned devices and note the MAC address. The next steps are to pair, trust and connect.

CODE
# stop scan for Bluetooth devices on UNIHIKER
$ bluetoothctl scan off

# pair mobile and UNIHIKER
$ bluetoothctl pair XX:XX:XX:XX:XX:XX

# trust mobile connections to UNIHIKER
$ bluetoothctl trust XX:XX:XX:XX:XX:XX

# connect the mobile and UNIHIKER
$ bluetoothctl connect XX:XX:XX:XX:XX:XX

# get information about device (optional)
$ bluetoothctl info XX:XX:XX:XX:XX:XX

Ensure your mobile shows the UNIHIKER as connected in respective bluetooth settings.

STEP 5
START AUDIO STREAMING

Play a track, and ensure the audio is routed to the UNIHIKER (Bluetooth speaker option).

 

Note: If you have disconnected your mobile, and it cannot connect to UNIHIKER at a later time, execute the next two commands on the UNIHIKER.

CODE
# keep bluetooth discoverable 
$ bluetoothctl discoverable on

# keep bluetooth pairable
$ bluetoothctl pairable on
STEP 6
ANNOTATIONS

You have successfully set up your UNIHIKER to connect with a mobile via Bluetooth and play music through the DFPlayer Pro and a connected speaker. This setup is excellent for DIY Bluetooth speaker projects or integrating audio playback into larger systems.

License
All Rights
Reserved
licensBg
0