Hacking a Better Elvis (Part I of 3)Posted by Evilis on Monday, 11 May 2009
The previous series of articles on this Robocommunity site on establishing a way to drive the Elvis Alive bust from a PC are useful but it becomes a peripheral which can do nothing without being attached to a PC with what amounts to a RS-232 umbilical. This also loads down the PC such that running any other other processes could affect the playback of the animation sequences. What I plan to do in the next three articles are to make the "PC Elvis" more like the Elvis Alive bust, only better! Unfortunately the Elvis Alive personality is removed in the process but then there are so many other personalities waiting to come out!
Improvements To the Original Hack
The goals to be achieved with this upgrade are as follows
- Still maintain the capability for a PC to send the individual animation commands via the RS-232 link. This will still be used as before to create animation sequences.
- Add the new capability to have the microcontroller drive its own movements and play its own audio, triggered by a single command on the RS-232 link. This opens the door to allow the PC to function as a higher level "brain" that monitors the surroundings and then triggers the sequences. No loading of the PC occurs just to drive the audio and the movements which is also better for driving multiple Elvis busts from the same PC.
- Add a wireless link between the PC and the Elvis bust to send the sequence trigger commands. This is also better for driving multiple Elvis busts since there can be multiple receivers for a single transmitter with no other special interface design involved.
- Provide a standalone wireless remote control with some programable customization for triggering sequences on up to 16 Elvis busts.
- Allow a unique optional capability to connect the remote control to the PC to trigger sequences from audio files. This allows the Elvis busts to do things like announce the arrival of email, insult you when you make errors, or event assist you during a Power Point presentation.
The first step to achieve these goals requires a small but not very cheap module (~$40) called a VMUSIC2. Member Retroplayer on this forum recommmended this module to me and has an excellent Instructables article on the module. The link for it is: http://www.instructables.com/member/RetroPlayer/ (Thanks Retroplayer!).
In short, the VMUSIC2 module will do the following.
- Plays back MP3 audio files from a USB flash drive (at least a 4GB size is supported).
- Allows other files to be accessed on the flash drive which can include files where animation events can be stored.
- Supports a directory structure on the flash drive to organize the animation sequences.
- Interfaces to a microcontroller via a RS-232 or an SPI bus interface (I used the SPI bus).
- Operates from a 5V supply but uses 3.3V signals the same as the existing design.
- As an added plus, it allows the playback volume to be adjusted via commands.
The cost of this module is 2/3 what I spent on my Elvis Alive bust but the work it saves it is worth at least 5 times that. So the decision was a no brainer. This module is available at this link http://www.mouser.com/search/ProductDetail.aspx?qs=vnwGVgFuQiYCrKscKT8PIQ%3D%3D for $37.50.
This first article covers the addition of the VMUSIC2 module and a few additional preparations for adding the remote capabilities in the next articles. Once the changes in this first article have been completed, the Elvis bust will run the sequences on its own but will still require a single RS-232 command string to tell it which sequence to play. This will accomplish the first two goals mentioned above.
Required Changes to the PC Elvis Application
To make use of this module, the following changes will be needed to the PC Elvis software application created for the original Elvis Alive hack. This application was previously only used to create and playback the Elvis Alive bust sequences.
- Add a record sequence capability to save the animation movements to a file which can then be copied to the USB flash drive. A corresponding MP3 file must also be created from the .wav file used with the sequence. This can be done with a freeware program such as Audacity available here http://audacity.sourceforge.net/.
- Support at least a two level directory structure for storing the sequence files both on the PC and on the USB flash drive.
- Add a playback sequence capability to send just the sequence name to the bust to trigger that sequence (instead of the tens or hundreds of individual movement commands).
- Support the playback sequence capability through a wireless remote via a RS-232 connection to the remote from the PC.
- Support downloading the list of sequence names to the wireless remote for triggering playbacks via a keypad on the wireless remote (standalone without a RS-232 connection from the remote to the PC).
- Add a capability to create audio files that contain the frequency encoded sequence names. When these files are played back on the PC into the remote via an audio link, the remote will decode the sequence name and send it to the bust through the wireless link to trigger that sequence.
Materials Needed for this Additional Hack
Other than the first item of course in the list below, this is a relatively small hack.
- An Elvis Alive bust that has been modifed to receive animation sequences via an RS-232 cable (My previous 4 articles). IMPORTANT! One change is required to the PC To Elvis Alive Interface Schematic! You must tie Trace Point G-2 on the Elvis Alive CPU board high to 3.3V instead of routing it to pin 29 of the 34 pin connector. You can do this at the same point Trace Point H-2 was tied to 3.3V. Otherwise the second A/D converter on the main CPU board will not be enabled using the new microcontroller circuit in this article.
- 1 VMUSIC2 module
- 1 2 foot long 3.5mm male-male audio cable
- 2 feet of ribbon cable (4 conductors for SPI bus)
- 4 feet of 22 gauge hookup wire (VMUSIC2 power and ground)
- 1 74HCT04 Hex inverter (14 pin DIP)
- 1 14 pin DIP socket
- 1 1N4004 Diode
- 1 or 2 connectors for SPI cable to microcontroller board (if not previously added)
Wiring up the VMUSIC2
If you wired the microcontroller board with the additional expansion connector for the SPI bus that was shown in the original schematic then you are a step ahead. All you need to do to complete this connector is add a 1N4004 diode (D2) to drop the 5.5 volt supply going to it to about 5 volts. If you have not yet added this connector you will need to add it to the microcontroller board or connector combination with at least 6 wires total. The VMUSIC2 comes with a short cable which can be reworked to create the cables needed to complete this connection. The first cable will consist of 6 wires, 2 for power/gnd and 4 more for the SPI bus. To build this cable it is best to cut the short cable supplied with the VMUSIC2 in half. Then splice in the wires from your chosen connector type to the microcontroller board to one half of the VMUSIC2 cable. This will leave you with spare pins to make the second audio cable. The connector drawing is shown below.
The length of the SPI cable should be kept to less than 2 feet. It must be able to reach from the microcontroller circuit board through the base to the VMUSIC2 module siliconed directly to the bottom of the bust. The VMUSIC2 can be mounted underneath the base since the legs that raise the base are taller than this module. The bottom of the VMUSIC2 module is the flat side so it will be attached in an upside down position at any convinient location. With the USB port exposed to the outside of the bust, the flash drive can be easily inserted and removed. A picture of the VMUSIC2 mounded to the rear left side of the Elvis bust is shown below.
An additional cable is needed to connect the audio output of the VMUSIC2 to the audio input of the Elvis bust. The schematic above also shows the audio cable. I had to cut the extra 8 pin VMUSIC2 connector plug into two 3 and 5 pin connector plugs to make this cable. Just cut off one end of the male-male 3.5mm audio cable and solder the wires to the pins of the 3 wire plug created this way.
The audio cable runs from the pins on the back of the VMUSIC2 to the front external audio jack on the bust. This still allows you to unplug this cable and plug in an audio cable from your PC while creating sequences. The audio output from the back of the VMUSIC2 module must be used instead of the front plug output due to the better impedence match between the rear signals and the Elvis bust external audio input. A picture of the cables and the VMUSIC2 module is shown below.
Addtional Changes to the Microcontroller Board
One other addtion to the microcontroller board is to add a 74HCT04 hex inverter. Power and ground go to pins 14 and 7 of this chip respectively and add a .1uf capacitor across them. The signal being inverted is the same signal being used as the chip select to the first A/D converter on the Elvis Alive CPU card. This signal is now also used as the select for the VMUSIC2 module's SPI interface. This can be done since both of these devices do not use the SPI bus. Pins 1,2 on the 74HCT04 are used to invert the signal going to the VMUSIC2 to make this Select signal active at the same polarity as the A/D chip select is active. This is microcontroller pin 7 which after being inverted on the 74HCT04 goes to pin 2 on the external SPI bus connector. This new connection can be seen in the updated microcontroller circuit schematic show below.
The only other wiring change required is to move a signal to make the INT2 input of the microcontroller one of the remaining two unused pins on the microcontroller. These two pins will be used to connect a wireless tranceiver for the remote control. Alternately these unused pins could be used without the remote capability to trigger sequences from external inputs such as motion detectors. The software delivered with this release does not use these pins so it could be easily modified to drive this capability.
To move the signal from the INT2 input you will need to remove the wire going between pin 6 of the ICSP connector and pin 38 of the microcontroller. This wire is not needed for the two wire programming done with the PICKit2 ICSP programmer. After this wire is removed, move the wire going to pin 35 of the microcontroller to pin 38. This now leaves pins 35 and 39 unused. Pin 39 was previously used to select the Elvis Alive mode which is no longer supported in this design.
Now the last change to make is to re-program the PIC18F4620 microcontroller with the latest firmware. The latest microcontroller firmware along with all the schematic updates can be downloaded from here http://www.mediafire.com/file/kznznqwydnq/PCElvis_v1_1.zip.
This completes all the wiring changes!
Loading the VMUSIC2 Firmware
The VMUSIC2 module can now be connected with the 2 cables assembled in the previous steps. However it will probably not do anything when powered on because it is usually sold with no firmware loaded. By default, the LED on its front will be flashed by its firmware when power is applied. If this does not happen you will have to put a copy of the firmware on a USB flash drive and plug it into the module before turning on power, then leave the power on until the LED stops flashing. This file is available on the VMUSIC2 support site here http://www.vinculum.com/downloads.html. In short you will need to download the ftrfb_main_03_65VMSC1F.ftd file, rename it to FTRFB.FTD and copy it to the USB flash drive before you power it on as described above. The version of this file I used to install my firmware is included in the PCElvis_v1_1.zip file.
If you are interested in developing your own application with the VMUSIC2 you may also want to download from this site the firmware manual and the release note that details using the VMUSIC2 with a PIC microcontroller over a SPI interface. The C code supplied in the PCElvis_v1_1.zip will also serve as an example.
New Capabilities Added to the PC Elvis Application
At this point the setup is complete if you have previously installed the PC_Elvis.exe application with the Multitrack Studio demo application. You just need to copy the newest version of PC_Elvis.exe over your old one. Any sequences you have already created are still compatible for full playback over the RS-232 cable. However, since the audio playback can now started locally from the VMUSIC2 by the microcontroller, you will need to change the audio track in Multitrack Studio to always begin at the same time as the first sequence event. This will keep the audio and the animation events in sync when the sequence is recorded to a file and the .wav file is converted to a separate MP3 file. Once the first event is lined up with the start of the audio, to record a sequence requires the following steps.
- Have PC_Elvis running and then Multitrack Studio
- Load or create your Song file that contains the sequence to record and set to start playback at the beginning.
- From the Record menu on the PC_Elvis menu select Start.
- Start the playback and let it complete.
- From the Record menu on the PC_Elvis menu select Stop and only then push the stop button in Multitrack Studio.
- Select Save in the record menu and enter the desired name in the popup window without any file extension.
The directory that sequences are recorded to is selectable in the settings menu of PC_Elvis. However, this is always within the currect directory that the PC_Elvis application is run from and only one subdirectory level is supported. All directory names and sequence names are limited to 8 characters not including the file extension. This is a limitation of the VMUSIC2. The .SEQ extension is automatically added to the sequence name by PC_Elvis.
A corresponding MP3 file must be created and stored with the just recorded .SEQ file. This file can be created from the .WAV file used for the MultitrackStudio track. This can be done with a freeware program such as Audacity available at the site mentioned at the top of this article. The MP3 file should:
- always reside on the USB drive in the same directory as its sequence file
- be the same name as the sequence file
- have a file extension of .MP3
Just remember to do this before the recorded files are copied to the USB Flash drive. You can then just copy all files and subdirectories in the PC_Elvis current directory to the root directory of the USB Flash drive.
One you have moved the USB Flash drive to the VMUSIC2, you can power on the Elvis bust and you are ready to play sequences by selecting them from the Playback/Select menu on the PC_Elvis window. This window allows you to select a Elvis bust number (1-16), a new volume setting to play that sequence, or just leave the volume at 0 to playback at the default volume. The default volume is set using the Playback/Set Default Volume menu selection which will be stored in the microcontroller's flash memory and only needs to be done once.
New Serial Commands for the Elvis Bust
If you are interested in writing your own RS-232 application to trigger the sequences, then you can use the following two command formats.
To trigger a sequence already loaded on the USE flash drive the command structure in hexidecimal is:
0xFn 0xF3 0xyy 0xzz where:
- n is the Elvis bust number 1-16 (0-15 in hex)
- yy is the playback volume of 0x00-0xFE with 0xFF being the default volume
- zz is the length of the sequence name that follows including up to one directory level
- the zz ASCII characters that compose the sequence name follow these four bytes
To set the default volume for playback the command structure in hexidecimal is:
0xFn 0xF7 0xyy where:
- n is the Elvis bust number 1-16 (0-F in hex)
- yy is the default playback volume of 0x00-0xFE with 0 being the maximum.
The next article will add a small tranceiver to the microcontroller board in the Elvis bust to accept commands as well as return text (in the microcontroller's menu mode). Also I will begin to create the custom remote control by creating a new box that contains a microcontoller interfaced to another transceiver but is still driven by the RS-232 interface from the PC. This will establish the wireless link. The third and final article will add the bells an whistles to this box to make it a fully independant remote control.