This is only a preview of the February 2018 issue of Silicon Chip. You can view 37 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "A Water Tank Level Meter with WiFi and More!":
Items relevant to "El Cheapo Modules 13: sensing motion and moisture":
Items relevant to "Highly versatile & accurate dot/bar 10-LED Bargraph":
Items relevant to "The Arduino Mega Box Music Player revisited":
Purchase a printed copy of this issue for $10.00. |
Arduino Mega Box
Music Player
By Bao Smith
Combine an Arduino MP3 player shield with the Altronics Mega Box,
along with our software, to make a neat little music or audio player
with endless possibilities.
W
e introduced the Altronics Mega
Box kit in the December 2017 issue of Silicon Chip. It allows you to
give your Arduino projects a much
more professional appearance and
provides many convenient functions.
In that article, we mentioned that
one possible use of the Mega Box
would be to combine it with the
VS1053 MP3 player shield, which
we used in our Music Player project
in July 2017 (see siliconchip.com.au/
Article/10722).
That project was presented as a collection of boards and modules wired
together. That’s pretty typical for
your average Arduino project but we
wouldn’t say that it gives a finished
product that you can use every day.
Well, that changes now because
we’ve revamped the software to take
advantage of the facilities provided by
the Mega Box.
By using the Mega Box, rather than
just stacking the MP3 Player shield on
an Arduino Uno, we can use a universal infrared remote control rather than
the 4x4 keypad.
That provides several benefits including a larger number of keys and
siliconchip.com.au
buttons, more intuitive user interface
and the fact that you can carry the remote around with you.
We’ve also changed the software so
that you can use at least two of the four
illuminated pushbuttons on the front
panel to control the player.
If you want to use the other two and
the rotary encoder, you’ll need to use
an Arduino Mega instead of the Uno as
the Uno just doesn’t have enough free
I/O pins. The software will auto-detect
if you are using a Mega board and allow
use of the extra front panel controls.
This version of the Music Player also
incorporates the changes we’ve made
to the software since the July 2017 article, to fix some issues reported by
constructors. This includes a fix for
dropouts during recording and an improved menu system.
Now, having mentioned how well
the Mega Box suits this project, we
should add some caveats. The Mega
Box is supplied with a 16x2 LCD,
which is smaller than the 4-line unit
that we used in the original version
of the project.
And since the supplied LCD has
a slightly non-standard pinout, you
Celebrating 30 Years
can’t easily attach an I2C translator
module (but it isn’t impossible if you
want to save four pins). So we need
to use the LCD in 4-bit data transfer
mode which requires the use of six of
the Arduino’s I/O pins (plus an additional PWM pin if you want to control
the backlight).
Also, the way the MP3 player shield
is designed means that the headphone
and microphone sockets face into the
box, rather than out through the hole
provided near the rear of the shield
mounting point.
That means you will need to drill a
couple of holes to mount chassis sockets and wire them up to plugs which go
into the shield sockets. Alternatively,
you can run two 3.5mm male-female
extension leads from the shield to the
rear of the case.
As an alternative, you can use the
SparkFun version of this shield (www.
sparkfun.com/products/12660). It has
the same pin layout but has the headphone jack pointed at the rear, but you
will need to solder your own microphone input socket onto the board.
That shield is a bit more expensive
than the version we used originally
February 2018 83
but it’s also decidedly less dodgy, in
that it uses a proper level translator
between the 5V Arduino board and
the 3.3V audio player IC.
The infrared interface is now the
main means of controlling the unit
and while you could probably use just
about any universal remote, we’ve designed it with the Altronics A1012 in
mind (siliconchip.com.au/link/aaio).
We’re using TV code 170 (see supplied instructions for how to set that).
You can use this to operate the unit
from up to five metres away. The
A1012 TV code 170 button codes are
shown in Table 1.
If you want to use a different remote control, you will need to set it to
produce Philips RC5 codes and then
change the “#define” lines at the top
of the Arduino code to the appropriate code numbers to suit your remote.
The best way to check what commands your remote sends are by running the sample Mega Box program
that Altronics have on their website
and read the values off the serial console in the Arduino IDE: siliconchip.
com.au/link/aais
Assembling the project is fairly
simple if you’ve already built the
Mega Box. If you haven’t, see our December 2017 article for the details
(siliconchip.com.au/Article/10902)
and/or follow the instructions supplied with the kit.
The main difference will be in how
you want to handle audio input and
output. What we did was mount two
3.5mm stereo sockets in a convenient
location on the front or rear panel (eg,
above S1-S4, or to the left of the rotary
encoder); a 6mm drill bit should do.
After this, solder an adequate length
– depending on the location of the
sockets – of stereo shielded cable to
their pins. You can just use one cable
and cut it in two and then strip the
outer sheath.
Next, separate the individual leads
and strip the ends of the red and white
leads before soldering them to the connector; white to tip, red to ring and the
shield wires to ground.
Be careful since some sockets are
switched and will have more than
three pins; you will need to plug an
audio cable in and use a DMM set on
continuity mode to figure out which
is the tip (left), ring (right) and sleeve
(ground) connections.
Wire these up to the two line plugs
using the same pin assignments, so
that you end up with what are essentially two extension leads that can
then be plugged into the MP3 Player
shield.
We also recommend that you add a
3.6V 1W zener diode between the 3.3V
line (cathode) and ground (anode). The
easiest place to fit this is between CON3
and CON5 which are located between
the Arduino and the shield on the Mega
Box board (these may be labelled U3
and U5 on the PCB).
This is not necessary if you’re using
the SparkFun MP3 Player shield. The
reason it’s required is that the Geeetech
MP3 Player shield’s lack of level shifting circuitry causes the Arduino output pins to “pump up” the 3.3V supply
when they go high and this can cause
a buzzing in recorded audio.
The zener diode helps to prevent
the loss of regulation on the 3.3V rail
due to this pumping action. Note that
there’s a small risk that the diode could
overheat; we’re counting on the fact
that its voltage “knee” is just above the
normal voltage of the 3.3V rail and so
it will only conduct a small amount of
current (milliamps) at 3.3V.
But it’s possible your diode could
have a low knee voltage or your 3.3V
We’ve used a 3.5mm switched stereo
audio socket (enlarged). You’ll need
to use a DMM on continuity mode to
determine which lead is the tip (white;
left), ring (red; right) and ground.
A close-up of the 3.6V zener diode
inserted with cathode to the 3.3V line
and anode to GND.
Assembly
Table 1: IR codes
Button
Standby (on/off)
Mute
Buttons 0-9
Channel up/down
Volume up/down
Up/down
Right/left
OK
Teletext
Page hold
TV/Video
Pause
Exit
Rewind
Play
Fast forward
Stop
84
Silicon Chip
Hex code (0x)
0C
0D
00-09
20/21
10/11
12/13
14/15
23
3C
29
3F
3D
0B
37
32
34
36
Celebrating 30 Years
siliconchip.com.au
regulator could have a slightly higher
output than typical. So after fitting it,
power up the Arduino and make sure
it isn’t getting too hot.
Wiring it up
Now refer to Table 2 to see which
connections you need to make using
jumper leads. Some of the connections
can only be used with an Arduino
Mega, as indicated in the table, so if
you’re using the Uno you will have to
leave them out and their related functions will not be available.
Since the pushbuttons are wired
with pull-up resistors, the pins connected to the pushbuttons are read as
high by default and low when pressed.
The button’s NO connection should
be wired to +5V by placing jumpers
on JP1.
Note that Arduino pins D2, D6, D7,
D8 & D9 are exclusively being used by
the MP3 Player shield and cannot be
used for anything else, while D11-13
can be used with other SPI devices.
This leaves D0 (receive), D1 (transmit),
D3, D4 and D10 (slave select).
Generally, D0 and D1 should not be
used as this would interfere with the
serial console, nor D10 as that is driven by the Arduino SPI unit.
Once all connections have been
made, the Arduino sketch software can
be loaded. It’s available for download
from the Silicon Chip website (free
for subscribers, and it will be bundled
with the July 2017 software).
You will also need to load your audio files (and two required patch files)
onto the root directory of a properly
formatted microSD card (FAT16 or
FAT32) and insert this into the socket
on the player module.
If you don’t already have the latest
version of the Arduino IDE, download it from www.arduino.cc/en/Main/
Software and install it.
The next step is to install the required libraries, which are supplied
in the download package along with
the sketch. Use the Tools → Libraries
→ Add .ZIP Library menu option to
install each one in turn.
Then open up the sketch file, make
sure the correct COM port is selected
in the Tools menu, and then select
the Upload option (CTRL+U in Windows). Check the bottom of the IDE
window to make sure the upload was
successful.
Next, adjust LCD contrast potentiometer VR1 so that you can comfortably
read the text on the LCD screen. If you
don’t see any text, check that the SD
card is properly connected and try connecting the LCD backlight interface to
the +5V line to make sure the screen
isn’t too dim.
By default, the software uses the line
in connection when recording, which
means you will need an external microphone. You can alter the software to
use the Geeetech on-board electret microphone by removing the line “#define USE_LINEIN 1”, but the resulting
quality is quite poor.
Remote control functions
You should find the infrared remote
control buttons to be fairly straightforward. The arrow keys are used to
navigate the menus with the OK button used to select the current choice.
Shown above are the flying lead connections that need to be made to use the project with an Arduino Uno. Take note of
the jumpers for S1 & S2. If you have a spare PWM pin, the backlight can be controlled using that instead of the yellow
lead going to 5V. The audio sockets don’t need to be placed where we have as it does interfere with the header for the
Arduino Mega. Other good locations include above the four pushbuttons or on the back panel above the five relays.
siliconchip.com.au
Celebrating 30 Years
February 2018 85
Table 2: Lead Connections
Component
16x2 LCD
Infrared Remote
Pushbuttons
Rotary Encoder
To Pin
RS
A0
EN
A1
D4
A2
D5
A3
D6
A4
D7
A5
Backlight
5V
IR interface
D3
S1 COM#
D4
S2 COM#
D5
S3 COM^#
D14
S3 COM^#
D15
Encoder interface A^
D16
Encoder interface B^
D17
Alternatively, you can press a button on the numeric keypad to directly
choose the respective menu option (as
shown on the LCD).
When playing an audio file, the up/
down arrow keys and channel up/
down will go to the previous or next
file respectively. The OK, play and
pause can be used to pause or play
the current file.
Volume up/down will alter the
volume, the mute button will toggle
mute, fast-forward and fast-rewind
will speed up or slow down playback,
rewind will restart the current song
from the beginning and the back/exit/
return button on the remote will end
playback.
When choosing the menu option
“play track number”, you use the numeric buttons on the remote to enter
a specific three-digit track number to
play. The left/right arrows can then
be used to select which file format
to play from (both MP3 and OGG are
supported).
When recording, you will need to
select a file number to record to and
the process is the same. Or you can
simply press OK to record in a sequential order, ergo, record00.ogg, 01, 02…
Using Bluetooth speakers
If you want to use Bluetooth speakers, headphones or some other Bluetooth audio receiving device, all you
86
Silicon Chip
Parts List
Lead
1 Inventa Mega Box kit (Altronics Cat K9670)
1 Arduino Mega (recommended) or Uno (or
compatible)
1 VS1053b based MP3 Player shield (Silicon Chip
Online Shop Cat SC4315 [Geeetech] or SparkFun
version [see text])
1 Altronics A1012 universal remote control
4 jumper shunts (2 if using the Uno)
2 3.5mm stereo chassis-mount sockets
2 3.5mm stereo line plugs (Altronics Cat P0030)
1 1m length stereo shielded audio cable
1 USB Type A to Type B (full size) cable
1 USB charger or other USB power supply
16 150mm long male-male jumper leads (minimum 11)
1 3.6V 1W zener diode
1 Bluetooth audio transmitter (optional)
1 PCB-mount Type-A USB socket (for Bluetooth audio
transmitter)
^ only available when using Arduino Mega board
# place a jumper on JP1
With an Arduino Mega these pins MUST be connected in
parallel: 11 → 51, 12 → 50, 13 → 52 for the SD card to work.
need to do is buy a Bluetooth audio
transmitter.
They’re quite cheap and compact.
Here is one we’ve purchased and used
quite successfully: siliconchip.com.
au/link/aair
It can actually be used as a transmitter or receiver; dedicated transmitters cost around the same price (about
$20). We found the audio quality to be
reasonable.
It comes with a short 3.5mm plugto-plug cable so it can be plugged
straight into the audio output on the
MP3 Player module. It’s also supplied
with a short USB cable to power it,
with a Type-A plug on the end.
You will need to solder a PCB-mount
Type-A socket to the prototyping area
on the Mega Box and wire up its +5V
and GND pins to supply points on the
Mega Box board.
Fig.1 shows the connections required for the USB socket; the Dand D+ connections do not need to
be made. Be careful since reverse
polarity may destroy the Bluetooth
transmitter.
You will then need to attach the
Fig.1: expanded
view of a
USB Type-A
socket showing
the required
connections.
Celebrating 30 Years
transmitter inside the case somehow
(eg, double-sided tape or silicone sealant) and then wire it to the socket with
the supplied USB power cable.
If you’re clever, you could drill a
hole into the case giving you access
to the button on the transmitter unit,
which you need to press before you
can pair it with your receiver.
However, given that pairing is something you only need to do when connecting it to a new receiver, that may
not be necessary.
What can it play?
As mentioned in the previous article
in July 2017, assuming you have the
correct patch file located in the root
directory of the SD card, the player
can play these formats/containers: Ogg
Vorbis, MP1, MP2, MP3, AAC, WMA,
FLAC, WAV and MIDI
This should cover most of the audio
file formats that you will commonly
encounter.
The VS1053b chip is able to record
in the following file formats: Ogg Vorbis, PCM and ADPCM.
However, the software is only programmed to record in the Ogg Vorbis
compressed format.
A list of individual bitrates which
are supported by the IC for each file
format can be found under section 8
in the VS1053 datasheet: www.vlsi.fi/
fileadmin/datasheets/vs1053.pdf SC
siliconchip.com.au
|