Listing 1.
Part 2: The Software
#include <SoftwareSerial.h> #define Rx 8 // Not used #define Tx 7 #define CTS 3 #define Q 2 #define nRESET 9
/* Soundgin commands */ #define ESC 0x1B // Required before every command #define PRESET 0x4B // Load a Sound into mixer A #define STOP 0x54 // Release mixer A #define VOICE 0x5B // reset to voice parameters #define CLEAR 0x46 // Clear mixer A #define RAMP 0x47 // Ramp to targets A #define CLRALL 0x06 // Clear mixers A and B #define Q_ON 0x0E // Use to note when phrase completed #define Q_OFF 0x0F // as above... #define V_NOTE 0x08 // Set Voice to this note
SoftwareSerial soundgin(Rx,Tx); /** Setup gets everything going. */ void setup() {pinMode(Rx,INPUT); // Set up the soft serial port pinMode(Tx,OUTPUT); pinMode(nRESET, OUTPUT); HardReset(); // Reset the board hardware
soundgin.begin(9600);
pinMode(CTS,INPUT); // Soundgin CTS handshake pinMode(Q,INPUT); // Soundgin phrase done flag }
As I mentioned, I needed to go to Google
to find any documentation on this board;
again, I thank the folks at Babblebot.net for
rescuing the only known documentation for
the Soundgin before it was lost to humanity!
This document gave me lots of details about
the chip and how to connect to it. It left out
many details about the preset sounds, how to
do a software reset, and how to shift between
voice and sound synthesis.
Once again, I resorted to our favorite
search engine and found a couple of posts on
Parallax Propeller and Parallax PBasic forums
whose authors appeared to have "insider"
information. I borrowed freely from these
posts and I hope improved on them a little to
format the Arduino code that I have now.
Kudos go out to skf_wa on the forums.basic
micro.com site and Haunted Programmer on
the www.efx-tek.com forums site.
Figure 2 shows my project using a custom Arduino
board that I have a bunch of in my toolbox. I made one
change since I took the photo in Figure 2; I added a
connection from IO- 9 on the Arduino to the reset pin on
the Soundgin board, so I didn't need to manually reset the
board on power-up.
Careful experimenting with these folk's
examples showed that the Soundgin has some
quirks, but you can get around them. The first
revelation is that there appears to be a
software reset that can be done by sending
eight ESC (0x1B) characters to the chip. Not
seven, not 10 — only eight will do the job. The
second big revelation is that this reset
sequence is the only certain way to stop a
preset once it has been started that allows the
voice settings to work immediately afterward.
Rather than bore on about how to control the
Soundgin chip in text, I'll show the setup that I used and
explain it. Listing 1 shows my definitions and setup
function. I have a bunch of commands defined in my
code that I am not using, but I did use all of them while
/* My phrases. */ unsigned char domo[] = {252, 203, 228, 223, 228, 252, 228, 232, 207, 210, 231, 239, 228, 252, 223, 214, 236, 239, 208, 252, 235, 228, 198, 230, 239, 228, 252, 0}; unsigned char baddog[]= {252, 197, 192, 205, 252, 203, 228, 211, 252, 0};
[…]
/** Speak the allophone string sent. Deal with handshaking as well */ void Speak(unsigned char *phrase)
{int n;
n=0; SendGin(Q_ON); while(phrase[n] != 0) { while(digitalRead(CTS) == 1); // wait for buffer to empty. soundgin.write(phrase[n]); n++; } // Clear Q and wait for the bit, meaning // phrase is done. SendGin(Q_OFF); while(digitalRead(Q) == 1); }
Listing 2.
16 SERVO 03.2014