Jump to content
  • entries
  • comments
  • views

Type & Talk, just 3 lines of BASIC Code



How many lines of Atari BASIC is required to make the Arduino shield from the last blog post talk? 3 lines - type some text, hit return, send text to the 850 interface and repeat. The Arduino receives the text, does a little reformatting, then sends that string to the XFS5051CE chip for speech synthesis. This isn't just for the Atari8, any computer with an RS232 port can be made to chit-chat.

The Shield is going to use the Serial pins 0 and 1 to talk to the Arduino. A TTL to RS232 converter is needed to make the connection to the computer. A SoftwareSerial port is required. Connect the Ground and 5V power to the converter. The RX pin on the converter should be connected to digital pin 5 and TX to pin 6.


Also, remember that the high side of the busy light was connected to Analog pin5 because I couldn't get the serial output of the chip to work. When the light is on, its busy.

The Arduino is going to have to be programed to accept ASCII code. I try to copy as much code as I can. This time I found a bit of code in "Beginning C for Arduino" by Ph.D. Jack Purdum. The program calls a function to read characters from the software serial port into a string array until and EOL is encountered. I couldn't get it to exit the function until I moved the return command a couple of brackets up. I know if a loop is exited in Atari BASIC, you have to make sure you POP the stack or bad things can happen. The C program seems to work fine so maybe the return belonged where I put it.

The program starts off by setting up the hardware and then speaks a test sample. Sometimes when powering up the arduino you will need to hit reset on the shield(and set RUN switch) and then reset on the Arduino. After you hear the test you know the system is setup and hooked to the amp or headphones. Its ready to start accepting string data.

The ReadLine function gets a character from mySerial port. If it is not a EOL then it adds the character to the string. If it reads an EOL then a null character is added to the string. Now it has the line of text and exits the function.

The SpeechSynthesys library has the functions to add the text to the formatted string for speech. The Arduino then checks the wired-in busy light before sending the string to the chip. Once the text has been send to the shield, it can begin building the next line of text. There hasn't been a problem with the delay settings although some adjustment might be needed in the future.

The way it is setup, there is no easy way to change the voice settings. Again with the future, a way to set these parameters can be incorporated into the code.

Copy the code into the Arduino IDE, make sure you have the SpeechSynthesis Library and upload the program. Hook up the RS232 port to the computer and try sending text through the Serial Monitor. Be sure to set the COM port to the proper number.


/* DFROBOT Text to speech

This program will read ascii text from a RS232 port,
reformat it for the DFROBOT Speech Shield, and then send
the string to the Shield for conversion to speech.

#include <SoftwareSerial.h>
#include <SpeechSynthesis.h>

SoftwareSerial mySerial(5,6); // RX, TX
byte ssr[500];//define a character string
int busyPin = 5;
byte whoToSpeak = 19;//voice number

void setup() {
mySerial.begin(9600);//baud rate computer
Serial.begin(57600); // baud rate shield

// say shield is ready, if you don't hear this something is wrong
SpeechSynthesis.buf_init(ssr);//initialize the buff
SpeechSynthesis.English(ssr,6,"shield test, testing shield, shield tested");
SpeechSynthesis.Espeaking(0,whoToSpeak,4,ssr);//Executive commands above, "0" is synthesis command; "19" select speaker; "4" speech function
SpeechSynthesis.buf_init(ssr);//initialize the buff

int ReadLine(char str[]){
char c;
int index = 0;

while (true) {
if (mySerial.available() >0){
c = mySerial.read();
if (c != '\n'){
str[index++] = c;
} else {
str[index] = '\0';
return index;

void loop() {

char txt[300];
int txtLength;

txtLength = ReadLine(txt);

while(analogRead(busyPin) > 100){}
delay(250);//wait for chip to be ready to receive
delay(250);//wait for chip to show busy

Hook the unit up to the 850 or P:R: Connection. I use a switch box wired to R2:. The cord is wired so that the pin outs at the box are the same as those of the IBM - USB to RS232 unit. The synthesizer is still a work in progress and expect to clean up the hardware before the next blog. Using a different port will require some changes to the program.



The R2: is set up for block mode transmission of data, heavy translation mode and addition of a carriage return at the end of line. Of course the baud rate is 9600 to match the Arduino. Its that simple, once you know how.


100 DIM A$(200):GOSUB 30000
110 INPUT A$:PRINT #1,A$:XIO 32,#1,0,0,"R2:":GOTO 110
30000 CLOSE #1:OPEN #1,8,0,"R2:":XIO 36,#1,14,0,"R2:":XIO 38,#1,64,0,"R2:":RETURN

RUN the program. The "?" is your sign to input some text. Hit Return and the text is sent to the R2: port in 32 byte blocks. The XIO 32 forces the transmission of the last few characters or short block. Then another "?".

Ever wonder what Eliza would sound like with a Chinese accent? Me too.


Recommended Comments

There are no comments to display.

Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...