/** Run the giving preset for the duration sent. */ void SendPre(unsigned char pre, int duration) {SendGin(PRESET); soundgin.write(pre); delay(duration); ResetSG(); }
/** Send a SoundGin command with ESC. */ void SendGin(unsigned char data) {soundgin.write(ESC); soundgin.write(data); }
/** Send the magic number of ESC to get a reset on the SoundGin. */
void ResetSG(void) {int n;
for (n=0;n<8;n++) { while(digitalRead(CTS) == 1); soundgin.write(ESC); }
delay(100); }
/** Yank Soundgin chip reset line to reset the chip. */ void HardReset(void) {digitalWrite(nRESET, 0); delay(1); digitalWrite(nRESET,1);
delay(100); }
Listing 3.
I was carefully experimenting (ahem).
I wanted to leave the Arduino hardware serial port
available for debugging and programming, so I created a
SoftwareSerial object to talk to the Soundgin. This requires
you to define a transmit and receive pin
pair. At this time, I'm not getting data back
from the Soundgin, so the Rx signal is not
being used.
I found that if I cleared this pin before I started a
phrase and then set it after I sent the last allophone, that
the pin did not set until the phrase was complete. This
means that by checking this pin, we know exactly when
Listing 4.
Way back at the beginning of this
project, I mentioned the CTS and Q signals
as being essential. I have them defined in
the Setup() function. Listing 2 shows how
they are used when we are sending strings
of allophones to the Soundgin to create
speech.
The Soundgin documentation says that
it sets the CTS pin high when its receive
buffer reaches half full. If we watch that
pin and stop sending commands when it
goes high, then we are assured that the
Soundgin will get all of our commands. If
you don't check this pin, then you will find
that long phrases won't complete.
Other programs that I found online
relied on their communications to be slow
enough to avoid this problem. Another
programming ploy I saw continually used
was a delay after sending the phrase that
allows the phrase to be completely played
before sending other commands. I thought
this was too imprecise. Fortunately, the
documentation details commands that set
and clear the Soundgin Q signal that is on
one of the Soundgin board's header pins.
/* Soundgin preset sounds. */ #define preSPACEWARP 0 // 0 Space Warp #define preWABA 1 // 1 Waba #define preRNDTHOUGHTS 2 // 2 Random Thoughts #define preGONG 3 // 3 Gong #define prePWANG 4 // 4 Pwang #define preWOW 5 // 5 Wow #define preRANANANA 6 // 6 Rananana #define preTWARTY 7 // 7 Twarty #define preTELLY 8 // 8 Telly #define prePULSATOR 9 // 9 Pulsator #define preBOUNCE 10 //10 Bounce #define preTIPTOE 11 //11 Tip Toe #define preSPOKES 12 //12 Spokes #define preCHOPPER 13 //13 Chopper #define prePHAZER 14 //14 Phazer #define prePOWERLINES 15 //15 Power Lines #define preHEAVYMETAL1 16 //16 Heavy Metal 1 #define preHEAVYMETAL2 17 //17 Heavy Metal 2 #define preACMOTOR 18 //18 AC Motor #define preYAYA 19 //19 Ya-Ya #define preMARCH 20 //20 March #define preNOISE 21 //21 Noise Chatter #define preBLIP 22 //22 Blip Chatter #define preCARNEY 23 //23 Carney #define preEARTHQUAKE 24 //24 Earth Quake #define preMINDPROBE 25 //25 Mind Probe #define preSIREN 26 //26 Siren #define preSQUABA 27 //27 Squaba #define preSTEAMLOC 28 //28 Steam Locomotive #define preSIMPLEFM 29 //29 Simple Frequency Modulation #define preSIMPLEAM 30 //30 Simple Amplitude Modulation
SERVO 03.2014 17