Arduino and Speakjet Serial Command Mode

Hi Guys.
I’m using the speakjet (voice box shield) to mess around with a project. Making a synthy kind of thing, at this stage its pretty disorganised. However the entire project revolves around using the SCP command “\0” to set the speakjet into Serial Command Mode.

Now the problem I’m having is that I can passthrough serial commands from my computer, and switch it over fine. However I’m having trouble scripting the same.

void setup(){

pinMode(SerOutFrmArdu,OUTPUT);
pinMode(SerInToArdu,INPUT);

mySerialPort.begin(9600);
Serial.begin(9600);
delay(1500);
mySerialPort.print("\0");

};

void loop()
{
  char buffer[64] = {};
  int reader = 0;
  int counter = 0;
  while (Serial.available() > 0 and counter < 64) {
    reader = Serial.read();
    buffer[counter] = reader; 
    counter += 1;
  }
  mySerialPort.print(buffer);
  Serial.write(buffer);
  strcpy(buffer, "");
  mySerialPort.print("8J");
  mySerialPort.print("0N");
  mySerialPort.print("11J");
  mySerialPort.print("24N");
  mySerialPort.print("1J");
  mySerialPort.print(analogRead(sensorPin)*2);
  mySerialPort.print("N");
}

Now, what its doing is reading from USB, and when it has finished, it sends the text to the speakjet and mirrors it back over USB (so I know it’s done).

In my setup section, it sends “\0” to the speakjet, which is the command to tell it to listen to my commands. I had this with the code sending a bunch of information on setting the oscillators etc, but it didn’t help.

Anyway. What happens? It starts up in voice mode, and does nothing. Once I send “\0” over USB, it goes into Serial mode, and starts making the right noises. Now I don’t understand why the “\0” from USB trips it off right, but the “\0” I hardcoded doesn’t. Any idea why?

Once I have this done, I might do a write-up on speakjet and Serial mode, because there really isn’t much on the net!

I wonder if your "0" is being seen by your software as the rogue value ending a string, and thus not going off to the Speakjet.

Sorry... The answer to my question is probably in your code... just an idea to check.

I have an essay online about driving a Speakjet from an Arduino...

http://www.arunet.co.uk/tkboyd/ec/ec1speak.htm

Sounds like you have many of the things covered there already under control, but have a look.... who knows? And may be useful to others inspired by your enquiry.

The Speakjet is a lot of fun for only $25... and can be used in a variety of ways... even a little Arduino-less box with up to 10 buttons, each of which triggers a fixed (by you!) phrase. I dreamed of such a thing in my teaching days....

a) Be less noisy, please b) Hand in your homework c) Start a new page in your workbook d) Why haven't you done your homework e) You can go to the bathroom at the end of the lesson....

You get the idea?

Should it be?

mySerialPort.print("\0");

Should work fine, it should send the text over the soft serial, right? NewSoftSerial doesn't assume a trailing zero is an end of line or anything, does it? In any event, the same command, sent from USB -> string variable -> NewSoftSerial works fine.

Later in the code, it sends "0J" via the same method, and that seems to work fine.

I really don't get it. Anyone else have any ideas?

The SpeakJet is expecting a backslash followed by a zero (ASCII 48). The string you use in setup, "\0" is sending only one character, an ASCII 0 or NUL character (CTRL-@). This is because in C/C++ strings the backslash is an escape character which means that whatever follows it takes on a different meaning. A backslash following by one to three octal digits (0-7) is the way to embedded a special character into a string.

What you really want to do is this: mySerialPort.print("\0");

The double backslash will send a single backslash following by the zero.