Silicon ChipPICAXE Plays Music - July 2007 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Energy saving on a large scale is possible
  4. Feature: How To Cut Your Greenhouse Emissions; Pt.1 by Peter Seligman
  5. Feature: New Superbright LED: Will It Replace 50W Halogens? by Silicon Chip
  6. Review: Watchguard Pro Video Security System by Ross Tester
  7. Project: Build A 6-Digit Nixie Clock, Pt.1 by David Whitby
  8. Project: Tank Water Level Indicator by Allan March
  9. Project: PICAXE Plays Music by Clive Seager
  10. Project: A PID Temperature Controller by Leonid Lerner
  11. Project: 20W Class-A Amplifier Module; Pt.3 by Greg Swain & Peter Smith
  12. Vintage Radio: The Weston Model 660 Radio Set Analyser by Rodney Champness
  13. Book Store
  14. Advertising Index
  15. Outer Back Cover

This is only a preview of the July 2007 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.

Articles in this series:
  • How To Cut Your Greenhouse Emissions; Pt.1 (July 2007)
  • How To Cut Your Greenhouse Emissions; Pt.1 (July 2007)
  • How To Cut Your Greenhouse Emissions; Pt.2 (August 2007)
  • How To Cut Your Greenhouse Emissions; Pt.2 (August 2007)
  • How To Cut Your Greenhouse Emissions; Pt.3 (September 2007)
  • How To Cut Your Greenhouse Emissions; Pt.3 (September 2007)
Articles in this series:
  • Build A 6-Digit Nixie Clock, Pt.1 (July 2007)
  • Build A 6-Digit Nixie Clock, Pt.1 (July 2007)
  • Build A 6-Digit Nixie Clock, Pt.2 (August 2007)
  • Build A 6-Digit Nixie Clock, Pt.2 (August 2007)
Items relevant to "Tank Water Level Indicator":
  • Water Tank Level Indicator PCB [05104022] (AUD $5.00)
  • Water Tank Level Meter PCB pattern (PDF download) [05104022] (Free)
  • Water Tank Level Meter panel artwork and drilling template (PDF download) (Free)
Items relevant to "PICAXE Plays Music":
  • PICAXE-14M/28X1 BASIC source code for "PICAXE Plays Music" (Software, Free)
Items relevant to "A PID Temperature Controller":
  • AT90S2313 firmware and source code for the PID Temperature Controller (Software, Free)
  • PID Temperature Controller PCB pattern (PDF download) [04107071] (Free)
Items relevant to "20W Class-A Amplifier Module; Pt.3":
  • Preamp & Remote Volume Control PCB for the Ultra-LD Mk3 [01111111] (AUD $30.00)
  • Speaker Protection and Muting Module PCB [01207071] (AUD $17.50)
  • 20W Class-A Amplifier Power Supply PCB [01105074] (AUD $20.00)
  • 20W Class-A Amplifier Module PCB, left channel [01105071] (AUD $15.00)
  • 20W Class-A Amplifier Module PCB, right channel [01105072] (AUD $15.00)
  • PIC16F88-I/P programmed for the Low Noise Stereo Preamplifier with Remote Volume Control (Programmed Microcontroller, AUD $15.00)
  • PIC16F88 firmware and source code for the Low Noise Preamplifier with Remote Volume Control (Software, Free)
  • Speaker Protector and Muting Module PCB pattern (PDF download) [01207071] (Free)
  • 20W Class A Low Noise Stereo Preamplifier/Remote Volume Control PCB pattern (PDF download) [01208071] (Free)
  • 20W Class A Amplifier Module PCB patterns (PDF download) [01105071/2] (Free)
  • 20W Class A Amplifier Power Supply PCB pattern (PDF download) [01105073] (Free)
Articles in this series:
  • A 20W Class-A Amplifier Module (May 2007)
  • A 20W Class-A Amplifier Module (May 2007)
  • 20W Class-A Amplifier Module; Pt.2 (June 2007)
  • 20W Class-A Amplifier Module; Pt.2 (June 2007)
  • 20W Class-A Amplifier Module; Pt.3 (July 2007)
  • 20W Class-A Amplifier Module; Pt.3 (July 2007)
  • 20W Class-A Amplifier Module; Pt.4 (August 2007)
  • 20W Class-A Amplifier Module; Pt.4 (August 2007)
  • Building The 20W Stereo Class-A Amplifier; Pt.5 (September 2007)
  • Building The 20W Stereo Class-A Amplifier; Pt.5 (September 2007)

Purchase a printed copy of this issue for $10.00.

One of the most popular uses of PICAXE chips is in sound orientated projects. Both the new PICAXE-14M and PICAXE-28X1 support the 08M ‘play’ and ‘tune’ commands, which allow the PICAXE chips to play mobile phone ring-tones directly via a piezo sounder. by CLIVE SEAGER (www.rev-ed.co.uk) B ut what if you want to play real songs or sounds? The most obvious answer is to record your sound as an MP3 file and play it from the PICAXE chip. Unfortunately, though, MP3 files are very large and no microcontroller, PICAXE included, has sufficient memory to store many files. Fortunately a company called FDTI (www.ftdichip.com), based in Glasgow, Scotland has produced a very neat ‘VMUSIC2’ module ideal for this type of application. The VMUSIC2 module The FTDI VMUSIC2 module is shown below. It is supplied in a neat plastic enclosure but this is very easy to pop open if you want to look inside! The enclosure has a bi-colour LED, a headphone socket and USB thumb drive socket on the front, while on the rear there’s an 8 wire connector to connect power and control signals. Pop open the enclosure and you will find two main components on the PC board - a Vinculum VCN1L USB VMUSIC2 GND RTS V+ RXD TXD CTS n/c RI 40  Silicon Chip 1 2 3 4 5 6 7 8 Black Brown Red Orange Yellow Green n/c Blue USB DRIVE HEADPHONES host controller IC and a VS1003 MP3 playback IC. In simple terms, MP3 files are read from a USB thumb drive by the VCN1L USB controller and then decoded and played back via the VS1003 chip. The VS1003 sound output line will drive headphones directly; we also used the external speakers from our computer for testing purposes. It can also drive most amplifiers if you want some real sound! So to use the system, all we need to do is download a few MP3 (or WAV) Here’s the VMUSIC2 module, shown at left with the earphone and USB sockets and below opened out to show the workings. Don’t worry about the unused pins. Between the two pics are the connections to the VMUSIC2. siliconchip.com.au files from a computer onto a USB ‘thumb drive’, move the thumb drive to the VMUSIC2 module and then use the PICAXE chip to send play/stop etc commands to the VMUSIC2 module. PROGRAM EDITOR (TO PC SERIAL PORT) 2 3 VMUSIC2 Connections Connecting to a PICAXE-14M chip The VMUSIC2 module supports serial connections at a 9600 baud rate. If you’ve been playing with PICAXEs, you’ll know that the maximum baud rate of a PICAXE-14M is 4800 when running at the (default) 4MHz. However if we double the internal clock speed of the 14M to 8MHz (via a ‘setfreq m8’ command) everything now runs twice as fast and so we get the desired 9600 baud rate! Table 1 – Connections VMUSIC2 PICAXE 1 Black GND – 0V 2 Brown RTS – not connected 3 Red V+ – V+ 4 Orange RXD – output pin 5 Yellow TXD – input pin 6 Green CTS – 0V 7 (not used) 8 Blue RI – not connected siliconchip.com.au 5 10k “STOP” CON2 DB9 “PLAY” IN4 14 4 PICAXE 11 IN3 14M IN1 SC 2007 7 1 10k 13 12 3 IN2 PICAXE 14M 1 2 RXD 22k 5 10 6 9 7 IN0 OUT0 OUT1 OUT2 CONNECTIONS ON VMUSIC2 OUT3 OUT4 14 RED 8 ORANGE OUT5 GREEN 10k BLACK Picaxe 14m – vMUSIC DRIVER Fig.1: the simplest possible connection to the VMUSIC2: just one signal wire plus power (green in this case must be tied to 0V). Below is the protoboard layout of this circuit. “PLAY” SWITCH “STOP” SWITCH V+ V+ BLUE, YELLOW & BROWN WIRES NOT CONNECTED Vmusic The VMUSIC2 is supplied with a colour-coded 8-wire connector. Unfortunately this is on a 2mm (not 2.54mm) pitch and so will not easily connect to stripboard or breadboard layouts. So in the end we simply cut one end of the connector off and soldered the wires to our project board directly. Table 1 shows the function of the different wires. Connection to the PICAXE chip is made via a serial (RS232) link, so the wires can connect directly to the PICAXE input/outputs pins. Although the VMUSIC2 supports CTS/RTS serial handshaking, we have not used that feature here, so it is essential to tie the green wire (CTS) to 0V. Note also that the VMUSIC2 ‘transmit’ (output) pin connects to a PICAXE ‘receive’ (input) pin and vice versa. The VMUSIC2 requires a nominal 5V supply on the red and black wires (we ran it quite happily at 4.5V from 3xAA cells; you could also use 4xAA NiCad or NiMH rechargeables to provide 4.8V). +5V PROGRAMMING RESISTORS PICAXE-14M # 22kΩ 4.5V (3x “AA” ALKALINE) * 5 3 2 PROGRAMMING 10kΩ 10kΩ 10kΩ 0V # CUT OFF CONNECTOR, BARE ENDS ~5mm AND TIN WITH SOLDER. * OR 4.8V (4x NiCd OR NiMH) Table 2 - VMUSIC2 commands Play track “filename.mp3” serout 5,t9600_8, (“vpf filename.mp3”,CR) Play all tracks serout 5,t9600_8, (“w3a”,CR) Stop track serout 5,t9600_8, (“vst”,CR) Skip to Next Track serout 5,t9600_8, (“vsf”,CR) Skip to Start of current Track serout 5,t9600_8, (“vsb”,CR) Skip to Previous Track serout 5,t9600_8, (“vsb”,CR,”vsb”,CR) Pause serout 5,t9600_8, (“e”) Resume (after pause) serout 5,t9600_8, (CR) Set Volume serout 5,t9600_8, (“vwr”,$0B,vol_right,vol_left,CR) ;where $00 = maximum volume, $FE is the minimum Suspend disk Wakeup disk Get firmware version serout 5,t9600_8, (“sud”,CR) serout 5,t9600_8,(“wkd”,CR) serout 5,t9600_8,(“fwv”,CR) July 2007  41 Program 1 – VMUSIC2 to PICAXE 14M (1) #picaxe 14m Program 2 – VMUSIC2 to PICAXE 14M (2) ; set picaxe type #picaxe 14m ; set picaxe type init: init: setfreq m8 pause 1000 setfreq m8 pause 1000 ; double speed ; allow 500ms to wake-up main: serout 5,t9600_8,(“vpf 1.mp3”,CR) pause 20000 serout 5,t9600_8,(“vst”,CR) pause 20000 serout 5,t9600_8,(“vpf 2.mp3”,CR) pause 20000 serout 5,t9600_8,(“vst”,CR) pause 20000 goto main ; send play 1.mp3 ; wait 10 seconds ; send stop ; wait 10 seconds ; send play 2.mp3 ; wait 10 seconds ; send stop ; wait 10 seconds The four PICAXE program listings above and right are all that you need to get the PICAXE to talk to the VMUSIC2 – or is it sing to it? Don’t forget the 08M is being run at double speed so all your normal time-dependent variables must be doubled! Fig.1 shows the simplest connection method possible, just one wire (and power) to a PICAXE-14M chip. In this mode the PICAXE-14M issues commands directly to the VDRIVE2 main: if pin0 = 1 then do_play if pin1 = 1 then do_stop goto main ; play switch pushed ; stop switch pushed do_play: pause 10 if pin0 = 1 then do_play serout 5,t9600_8,(“vpf 1.mp3”,CR) goto main ; short debounce time ; wait until switch released ; send play 1.mp3 do_stop: pause 10 if pin1 = 1 then do_stop serout 5,t9600_8,(“vst”,CR) goto main ; short debounce time ; wait until switch released ; send stop command module without feedback. Program 1 shows a program to play ten seconds of each of the two music files ‘1.mp3’ and ‘2.mp3’. Remember that the chip is running twice as +5V 4.7k PROGRAM EDITOR (TO PC SERIAL PORT) ADC1 ADC2 ADC3 2 3 5 10k 22k SERIAL IN SERIAL OUT CON2 DB9 1 28 2 27 3 26 4 25 5 24 6 7 8 PROGRAMMING RESISTORS IN0 RESET IN1 IN2 IN3 SC 2007 PICAXE--28X1 ADC0 23 22 21 9 20 10 19 11 18 12 17 13 16 14 15 OUT6 OUT6 OUT5 OUT4 OUT3 OUT2 OUT1 OUT0 +V HRXD RED YELLOW TO ORANGE VMUSIC2 HTXD IN5 GREEN IN4 BLACK Picaxe 28X1 – vMUSIC DRIVER Fig.2: here the VMUSIC2 drives the new PICAXE-28XI chip. You not only get more control and functions but sixteen times the memory! 42  Silicon Chip ; double speed ; allow 500ms to wake-up fast as normal, so to get a 10 second delay you actually have to enter 20000 (milliseconds) for the pause command! You could use the Revolution Education PICAXE-14 project board (AXE117) for testing but it would be quite simple to make up your own pc board/stripboard layout or, as we have shown here, use the breadboard approach taken with many of the PICAXE projects in SILICON CHIP. ‘vpf filename’ and ‘vst’ are the commands required by the VMUSIC2 to play and stop mp3 files. Table 2 shows all the most common VMUSIC2 commands. Note that as each letter in the MP3 filename uses up memory in the PICAXE, it is far better to rename your files “1.mp3”, “2.mp3” etc. rather than “Meatloaf - Bat out of hell.mp3”! Of course you could now add switches to the PICAXE circuit, so that when a switch is pressed the song is played. Program 2 shows this type of idea, with two switches connected to PICAXE inputs 0 and 1. Connecting to a PICAXE-28X1 chip Although the VMUSIC2 will work fine with a PICAXE-14M chip, you will probably soon run out of memory on more complex programs. In this case it would be advisable to switch to the new PICAXE-28X1 chip, as it has 16x more memory! The PICAXE-28 siliconchip.com.au Program 3 – VMUSIC2 to PICAXE 28X1 #picaxe 28x1 ; set picaxe type symbol first_byte = b0 symbol point = b1 symbol temp = b2 symbol loopcounter = b3 init: ; Send Es until the unit responds correctly hserout 0,(“E”,CR) gosub get_response if first_byte <> “E” then init main: ; check to see if a drive is actually inserted ; response will start D for yes and N for no hserout 0,(CR) gosub get_response if first_byte <> “D” then main ; play track 1.mp3 ; response will start D if ok, C if not hserout 0,(“vpf 1.mp3”,CR) gosub get_response if first_byte <> “D” then main ‘ play ten seconds pause 10000 ; note no CR here ‘ play another ten seconds hserout 0,(CR) gosub get_response pause 10000 ‘stop hserout 0,(“vst”,CR) gosub get_response pause 5000 ; readadc value into variable b20 bintoascii b20,b5,b6,b7 ; convert loopcounter byte to 3 ascii digits ; and write 8 bytes loop_xyz hserout 0,(“wrf “,$00,$00,$00,$09,CR,”value “,b5,b6,b7) gosub get_response hserout 0,(“clf log”,CR) gosub get_response pause 1000 goto logging protoboard (AXE022P) is ideal for testing but again it would be quite simple to make up your own PC board/ stripboard layout. One of the new features of the 28X1 is its ‘internal’ enhanced hardware serial module. This module is far more efficient than the serial connection via the standard input/ output pins, and also supports much higher baud rates (the 9600 required here is no problem at all!). It also allows serial receives in the background (while the PICAXE processes other tasks). Fig.2 shows a slightly more complex connection, where the VMUSIC2 is connected to both the hardware serial in and hardware serial out pins. This now allows the VMUSIC2 to send replies and information back to the 28X1 chip – ie, we now know if a command has been received and understood. Program 3 shows how to get replies from the VMUSIC2 module. This is achieved via the ‘get response’ sub procedure, which receives the serial replies from the PICAXE serial port hardware. Each reply can be of different length, so the sub-procedure only returns when the terminating carriage return (CR) byte is received. Data Logging goto main ; Sub procedure to receive background bytes get_response: pause 1000 ; wait a while point = 0 ; reset local pointer get point,first_byte do get point,temp sertxd (temp) inc point loop while temp <> CR ; Save the first reply byte hserptr = 0 return ; reset the background receive pointer siliconchip.com.au logging: readadc 1, b20 ; create a log file called ‘log.txt’ hserout 0,(“opw log.txt”,CR) gosub get_response setup: ; setup serial hardware ; at 9600 with background receive hsersetup b9600_4,%01 ‘ pause for 5 seconds hserout 0,(“e”) pause 5000 Program 4 – logging ; get returned byte ; transmit it ; increment pointer ; if not CR loop A secondary feature of the VMUSIC2 (and the primary feature of its cheaper, non-MP3, little brother, the VDRIVE2) is to read and write to files onto the USB thumb drive. This makes it ideal for data logging experiments. Program 4 shows part of a program to use the fileopen (opw), file write (wrf) and file close (clf) commands. Further details for these commands can be found in the VMUSIC2/ VDRIVE2 datasheets. Summary The VMUSIC2 is a neat, economical, solution to playing MP3 and WAV songs and sounds. It is easily interfaced to a PICAXE chip making it ideal for linking into many musical projects. The file reading / writing functions will also appeal to many data-logging type experiments. For further details, schematics and technical datasheets for the VMUSIC2/VDRIVE2 module please visit www. vinculum.com SC July 2007  43