Emic2 & PICAXE

SolidWorksMagi

Senior Member
Can somebody tell me why this program is not working?

I don't seem to be getting a ":" back from the Emic2 nor does it speak anything.

If I plug it into a BOE the Emic2 works perfectly ... so it must be
Code:
; Emic2&PICAXE

#picaxe 28X2 ; Define the µProcessor IC Type

hsersetup B9600_32, %10	; 9600 baud, inverted polarity

symbol Ready = b0

; BEGIN Main Body * * * * * * * * * * * * * * * * * * * * *
main:
pause 5000

do
gosub speak1
loop
end
; END Main Body * * * * * * * * * * * * * * * * * * * * **

; BEGIN Subroutines * * * * * * * * * * * * * * * * * * **
ReadyChk:
hserin 0,Ready
debug b0
if Ready <> ":" then return ; Waiting for the Emic2 to send its ":" character as being READY
endif
return

speak1:
hserout 0,("S", "Hello")
gosub ReadyChk
hserout 0,("S", "My name is the Emic 2")
gosub ReadyChk
return
end
; END Subroutines * * * * * * * * * * * * * * * * * * * **
 
Last edited by a moderator:

hippy

Technical Support
Staff member
Can somebody tell me why this program is not working?
I can see at least three potential problems -

You are using B9600_32 when the PICAXE is not set to operate at 32MHz. The 28X2 defaults to 8MHz so try B9600_8.

You are inverting the hserial output signal but the module expects a non-inverted signal.

There are no terminating character in the HSEROUT strings to tell the module to speak what has been sent.
 

SolidWorksMagi

Senior Member
I can see at least three potential problems -

You are using B9600_32 when the PICAXE is not set to operate at 32MHz. The 28X2 defaults to 8MHz so try B9600_8 ...

You are inverting the hserial output signal but the module expects a non-inverted signal.

There are no terminating character in the HSEROUT strings to tell the module to speak what has been sent.


Hi,

I tried to setup the hersetup command per the online manual which seems very incomplete and fragmented ... I'll try hsersetup B9600_8, %10 now.

Per what I've read about hserout 0 is non-inverted and 1 is inverted ??? I can try both.

I don't know what the terminating character is ??? I know what they do, just not what the actual character is ??? I tried a quick search online but didn't find an answer other than a carriage return ??? Do I just add CR to the end of the line?


...

hsersetup B9600_8, %00 ; 9600 baud, non-inverted polarity

That seemed to fix the problem ... fixing the baud rate and the invert switch ... now it speaks loud 'n clear ... THANKS!
 
Last edited:

SolidWorksMagi

Senior Member
Hi,

Although I have the Emic2 speaking ... the program check for the ":" character from hserin pin doesn't seem to work???

Using the Simulator when I type the ":" (all three characters) it works ...

How do I set this up so program sees all three characters and the IF statement looks for all three characters? ...

hserin 0,Ready
IF Ready <> ":" then return
ENDIF
 

lbenson

Senior Member
Note that byte registers (as I'm assuming you've defined "Ready") can only contain a single character. Is there a reason you need to look for anything other than the colon? If not, you can do this

hserin 0,Ready,Ready
IF Ready <> ":" then return

Note that the first character, presumably a quote, gets put into "Ready" and then that value gets overwritten when the second character arrives, presumably a colon.

If you actually want to capture the quote characters, you need to read into three separate byte registers, but I don't think you would need to do that.

But does the Emic2 actually send three characters, or only a single colon, indicating that it is listening?
 

hippy

Technical Support
Staff member
The documentation is not clear on exactly what is sent as well as the colon. It appears there are no double-quotes used but there might be preceding CR and/or LF characters.

The easiest solution may be to enable background serial receive and then check for a colon using something like (untested) ...

Code:
CheckForReady:
  Do
    Do : Loop While ptr = hSerPtr
  Loop Until @ptrInc = ":"
  Return
 

Goeytex

Senior Member
If you haven't done so already try removing the debug command from the code as it may interfere with hserin.

The quotes are only to tell the program to look for the ASCII value of the colon symbol. The quote marks are not sent by the
peripheral device so the IF statement only needs to look for a value of 58.

You are using the M2 syntax for hserin instead of the X2 syntax. With an X2 Picaxe, Hserin receives the data byte into the scratchpad instead of user ram.

With an X2 chip the command should be something like:
Code:
Hserin 0,1      'Receive 1 byte into scratchpad location "0"
ptr = 0          'set the Scratchpad pointer to location 0 
if @ptr <> 58 then
   return 
endif
However, if the device does not send anything the program will get stuck at hserin since there is no time out defined.
So a timeout should be used.

Here is some code to test. Modify as needed
Code:
CheckForReady:
Hserin [1000,timeout] ,0,1      'Receive 1 byte into scratchpad location "0"  - Time out after 1000 ms 
ptr = 0                                'Set the Scratchpad pointer to location 0 
if @ptr  = 58 then
       sertxd ( "Received a colon character",cr,lf)
else 
      sertxd ( "Received a character, but not a colon",cr,lf)       
endif
goto exit_sub
  
   TIMEOUT: 
        sertxd ( "Hserin timed out",cr,lf)

   Exit_sub:
       return
 

jims

Senior Member
I'm curious... have any of you used this Emic 2 text to speech board on a Picaxe chip? If YES; what chip? and does it work as advertised ? Thank you, Jims
 

SolidWorksMagi

Senior Member
Hi,

That's something that is confusing with the "Simulator" ...

The Emic2 manual says it only sends a ":" when it is ready to receive a command and/or text.

The PICAXE Programming Editor "Simulator" required me to type in all three characters! ":"

So I'm confused as to why the 28X2 doesn't seem to see the : from the Emic2 via hserin 0, Ready

The IF statment seems to require the "" around the character to be tested ... I tried () but that just got a syntax error message.
 

SolidWorksMagi

Senior Member
The documentation is not clear on exactly what is sent as well as the colon. It appears there are no double-quotes used but there might be preceding CR and/or LF characters.

The easiest solution may be to enable background serial receive and then check for a colon using something like (untested) ...

Code:
CheckForReady:
  Do
    Do : Loop While ptr = hSerPtr
  Loop Until @ptrInc = ":"
  Return


Hi,

I tried that do/loop for the : but the 28X2 keeps the debug screen open (waiting...)

Here's the paragraph from the Emic2 manual;

The serial interface is configured for 9600 bps, 8 data bits, no parity, 1 stop bit (8N1). When Emic 2 is ready to receive commands, it will send a &#8220;:&#8221; to the host. It will then wait in an idle state until it receives a valid command, at which time it performs the command and returns any command-specific response.
 

Goeytex

Senior Member
The IF statment seems to require the "" around the character to be tested ... I tried () but that just got a syntax error message.
A colon is a "character". This colon character represents the ASCII number 58. Quotes are placed around a character to tell the program to send or receive the ASCII number represented by that character. Therefore the two conditional statements below are equivalent.

IF value = ":" then
IF value = 58 then

We use the quotes so we don't have to look up the ASCII table. The software sees the quotes and then knows to send the ASCII value (number) represented by the character within the quotes.
 

SolidWorksMagi

Senior Member
Code:
Hserin [1000,timeout] ,0,1      'Receive 1 byte into scratchpad location "0"  - Time out after 1000 ms 
ptr = 0                                'Set the Scratchpad pointer to location 0 
if @ptr  = 26 then
       sertxd ( "Received a colon character",cr,lf)
else 
      sertxd ( "Received a character, but not a colon",cr,lf)
endif
goto exit_sub
  
   TIMEOUT: 
        sertxd ( "Hserin timed out",cr,lf)

   Exit_sub:
return

That routine seems to almost work. I keep getting a "Received a character, but not a colon" every few "Hserin timed out" lines in the Serial Terminal ...

I made a slight change to see that a "13" is coming back from the Emic2 ??? the ASCII table says 13=cr ???

sertxd ( "Received a character, but not a colon", #@ptr,cr,lf)

But this doesn't seem to be complete full control over the Emic2 ... the do/loop in main sticks at playing the song1 routine after doing all the subroutines that come before the song1 and not the last subroutine that comes after the song1
 
Last edited by a moderator:

SolidWorksMagi

Senior Member
Emic2 w/PICAXE 28X2 ... Latest Listing ... almost working but not full control

Emic2 & PICAXE 28X2 ... current listing ... still doesn't work
Code:
; Emic2.bas

#picaxe 28X2   ; Define the µProcessor IC Type

hsersetup B9600_8, %00    ; 9600 baud, non-inverted polarity

; BEGIN Main Body * * * * * * * * * * * * * * * * * * * * *
main:
pause 3000 ; time to reprogram the chip

do
  gosub speak0
    pause 500

gosub Wait4Emic2
  gosub speak1
    pause 500

gosub Wait4Emic2
  gosub speech1
    pause 500

gosub Wait4Emic2
  gosub song1
    pause 500

gosub Wait4Emic2
  gosub speech3
    pause 500
loop
end
; END  Main Body * * * * * * * * * * * * * * * * * * * * **

; BEGIN Subroutines * * * * * * * * * * * * * * * * * * * *
Wait4Emic2:
Hserin [1000,timeout] ,0,1  'Receive 1 byte into scratchpad location "0"  - Time out after 1000 ms
ptr = 0                     'Set the Scratchpad pointer to location 0
if @ptr  = 13 then ; 26=substitute?  58=:  13=cr
       sertxd ( "Received a 13 character",cr,lf)
else
      sertxd ( "Received a character, but not a cr but a ",#@ptr, cr,lf) ; #@ptr,
endif
goto exit_sub
  
   TIMEOUT:
        sertxd ( "Hserin timed out",cr,lf)
   Exit_sub:
return

speak0:
hserout 0,("S", "Hello", cr)
return

speak1:
hserout 0,("S", "My name is. Billy Bot", cr)
return

speech1:
pause 100
hserout 0,("D0", cr)
return

speech2:
hserout 0,("D2", cr)
return

speech3:
;hserout 0,("R", cr)     ; R Revert to default text-to-speech settings
hserout 0,("S", "Is this working correctly yet", cr)
return

song1:
hserout 0,("D1", cr)
return
end
; END Subroutines * * * * * * * * * * * * * * * * * * * **
 
Last edited by a moderator:

SolidWorksMagi

Senior Member
Hi,

This is close but not working exactly correctly ... What I see in the Serial Terminal is:
"hersin timed out"
"hersin timed out"
"hersin received a 13 instead"

... and those three lines repeat over and over ... as the program is trying to play three messages with only a pause 500 between them ... and so the messages are all screwed-up. If I increase the pause to 5000 then I can hear the full little messages, but that's just the pause waiting past the ready signal from the Emic2.

Somehow this routine doesn't seem to fully function ... but it does seem a closer solution;



Wait4Emic2:
hserin [1000,timeout] ,0,1 ;Receive 1 byte into scratchpad location "0" - Time out after 1second
ptr = 0 ;Set the Scratchpad pointer to location 0
if @ptr = 58 then ; 26=substitute? 58=: 13=cr
sertxd ( "Received a : character",cr,lf)
else
sertxd ( "hersin received character ",#@ptr, " instead",cr,lf)
endif
goto exit_sub
TIMEOUT:
sertxd ( "hserin timed out",cr,lf)
Exit_sub:
return
 

Goeytex

Senior Member
It seems to me that there may be more than one byte being sent by the device. Also if the message takes more than 1 second to play hserin will timeout.
Try increasing the time out to 15000 and see what happens.

Since the message lengths can vary, having a timeout may not be such a good idea. If it were me, I would probably use hserin background receive. With hserin background receive you can catch all the bytes sent and then display them with sertxd to see what they really are. We already know that one of them is a 13.
 

SolidWorksMagi

Senior Member
It seems to me that there may be more than one byte being sent by the device. Also if the message takes more than 1 second to play hserin will timeout.
Try increasing the time out to 15000 and see what happens.

Since the message lengths can vary, having a timeout may not be such a good idea. If it were me, I would probably use hserin background receive. With hserin background receive you can catch all the bytes sent and then display them with sertxd to see what they really are. We already know that one of them is a 13.

Hi,

How do I setup hersin in background receive? What's that look like?

I set the timeout to 15000 ... I think the timeout just waits longer allowing for the 30 second speech and song to complete rather than working with the Emic2 control character : because the program is still screwing up with saying the messages in the order of the do/loop and some turn into Martian language as the Emic2 is confused from the broken message info.

You can see in the image below during the longer speech and song I get the hersin timed out message which is normal ... I'm just not getting any other characters back from the Emic2 other than the 13 ...

Emic2-hersin15000timeout3.jpg

I tried setting the timeout to 100ms and the thing seems to be screwed up too ... and I didn't see any returned characters ... not even the 13.
 

hippy

Technical Support
Staff member
Untested, but I would try ...

Code:
#Picaxe 28X2

HSerSetup B9600_8, %001

Pause 3000

Do
  Gosub Speak
  Gosub WaitForReady
Loop

Speak:
  HSerOut 0, ( "S", "Hello", CR )
  Return

WaitForReady:
  Do
    Do : Loop While ptr = hSerPtr
  Loop Until @ptrInc = ":"
  Return
 

Goeytex

Senior Member
That should work.

Example code provided by Parallax for Basic Stamp simply uses SERIN with a colon as a qualifier. The manual is vague about what is actually returned by the EMIC2.

The serial interface is configured for 9600 bps, 8 data bits, no parity, 1 stop bit (8N1). When Emic 2 is
ready to receive commands, it will send a &#8220;:&#8221; to the host. It will then wait in an idle state until it receives
a valid command, at which time it performs the command and returns any command-specific response.
Emic 2 will return a &#8220;?&#8221; upon receiving an invalid command.
This suggests that along with ":" and "?" there are also command specific responses that do not seem to be documented.
So it seems to me that the ":" or the "?" must be filtered out from among other possible responses.
 
Last edited:

SolidWorksMagi

Senior Member
Emic2 w/PICAXE 28X2 ... Latest Listing ... works very well ...

Untested, but I would try ...

Code:
#Picaxe 28X2

HSerSetup B9600_8, %001

Pause 3000

Do
  Gosub Speak
  Gosub WaitForReady
Loop

Speak:
  HSerOut 0, ( "S", "Hello", CR )
  Return

WaitForReady:
  Do
    Do : Loop While ptr = hSerPtr
  Loop Until @ptrInc = 13             ; Emic2 Manual say's ":", but the 13 seems to be working perfectly as I never saw a : back from the Emic2.
  Return
Hi,

I like the nice clean looking code, but the WaitForReady subroutine doesn't seem to be getting the ":" character so I changed to a 13 and it seems to be working. Thanks a lot folks for staying on message and helping me find a solution!

I'm not sure why the Emic2 manual say's it puts out a ":" when the Emic2 is ready ... unless it's an older or newer Emic2 board than the manual.

I'll have to try this code with the PICAXE 18M2 µPU too.
 
Last edited:

jims

Senior Member
SolidWorksMagi...I've been following this thread closely, and I plan to order an Emic 2 card to speak various status info from my controllers (temperatures, Relays and lights ON/OFF, TOD, etc). Have you definitely settled on some variation of the simplified code that Hippy has suggested? Thank you, Jims
 

SolidWorksMagi

Senior Member
Hi,

This works very well ... but READ the Emic2 documentation to get all its secrets ... so far I'm changing voices and speed and pitch in separate subroutines so the system doesn't get confused.

#Picaxe 28X2

HSerSetup B9600_8, %001

Pause 3000

Do
Gosub Speak
Gosub WaitForReady
Loop

Speak:
HSerOut 0, ( "S", "Hello", CR )
Return

WaitForReady:
Do
Do : Loop While ptr = hSerPtr
Loop Until @ptrInc = 13 ; Emic2 Manual say's ":", but the 13 seems to be working perfectly as I never saw a : back from the Emic2.
Return


My program is much larger now and working good. Now I'm trying to change it to work on the 18M2 chip that doesn't do background hserin ...
 

jims

Senior Member
Thank you, SolidWorksMagi.......Jims
Hi,

This works very well ... but READ the Emic2 documentation to get all its secrets ... so far I'm changing voices and speed and pitch in separate subroutines so the system doesn't get confused.

#Picaxe 28X2

HSerSetup B9600_8, %001

Pause 3000

Do
Gosub Speak
Gosub WaitForReady
Loop

Speak:
HSerOut 0, ( "S", "Hello", CR )
Return

WaitForReady:
Do
Do : Loop While ptr = hSerPtr
Loop Until @ptrInc = 13 ; Emic2 Manual say's ":", but the 13 seems to be working perfectly as I never saw a : back from the Emic2.
Return


My program is much larger now and working good. Now I'm trying to change it to work on the 18M2 chip that doesn't do background hserin ...
 

SolidWorksMagi

Senior Member
Emic2 w/PICAXE 18M2 ... Looping Test Help Please?

Hi,

Now I'm working to get the same program ... slightly modified for the PICAXE 18M2 chip ... but the Wait4Emic2 subroutine seems to be returning garbage in my "Serial Terminal" screen instead of the text ???

I want to see the messages to see the returning character from the Emic2 ... although as you can see in the program listing below waiting for a 58 ":" seems to be partially working ... but not really in control.

Wait4Emic2-FeedBack2SerialTerminal.jpg


#picaxe 18M2 ; Define the µProcessor IC Type

hsersetup B9600_4, %00

symbol Emic2Ready = b0

; BEGIN Main Body * * * * * * * * * * * * * * * * * * * * *
pause 3000

do
gosub Speak1

gosub Speech0

gosub Song1

gosub Speech2
loop
end
; END Main Body * * * * * * * * * * * * * * * * * * * * **

; BEGIN Subroutines * * * * * * * * * * * * * * * * * * * *


; BEGIN Wait4Emic2 Subroutine * * * * *
Wait4Emic2:
hserin Emic2Ready ;Receive 1 byte into scratchpad location 0
if Emic2Ready <> 58 then gosub timeout ; Emic2 manual says 58 character, but 13 works
sertxd ( "Received 58 character",cr,lf)
return

timeout:
pause 5
sertxd ( "Received a ",Emic2Ready," character",cr,lf)
return
; END Wait4Emic2 Subroutine * * * * * *




; Demo Speeches & Songs
Speak1:
hserout 0, ("S", "This is Message 1 speaking slower",cr)
gosub Wait4Emic2
return

Speech0:
hserout 0, ("D0",cr)
gosub Wait4Emic2
return

Song1:
hserout 0, ("D1",cr)
gosub Wait4Emic2
return
end
; END Subroutines * * * * * * * * * * * * * * * * * * * * * * * * *
 

hippy

Technical Support
Staff member
I'm not sure why the Emic2 manual say's it puts out a ":" when the Emic2 is ready ... unless it's an older or newer Emic2 board than the manual.
Post your BOE code which worked. Then we can look at what that was doing.

the Wait4Emic2 subroutine seems to be returning garbage in my "Serial Terminal" screen instead of the text ???
That's probably because you have 9600 baud selected while the 18M2 will output via SERTXD at 4800 baud at its default speed.
 

SolidWorksMagi

Senior Member
Post your BOE code which worked. Then we can look at what that was doing.



That's probably because you have 9600 baud selected while the 18M2 will output via SERTXD at 4800 baud at its default speed.

Hi,

The SERTXD sends data back to the PC ... I just tried setting the "Serial Terminal" to 4800 baud and now I see what's coming back from the 18M2. Thanks.

Now I need to understand why the program is still not working correctly. If the Wait4Emc2 routine is getting the 58 code then why doesn't it hold back the next speak routine until it sees that code ... but as I turn ON the speaker the program is not in control ... and alternating between 58 code and ? ... the ? from the Emic2 is an error ... so somehow the PICAXE 18M2 isn't waiting for the 58 to send the next speak string but just blasting everything at the Emic2. I'm wondering why the 28X2 chip only received a 13 from the Emic2 and the 18M2 sees the appropriate 58 and ? characters?

The Emic2 communicates at 9600 baud 8N1 standardized format ...

Here's the subroutine where my problem is;
hsersetup B9600_4, %00

symbol Emic2Ready = b0

Wait4Emic2:
hserin Emic2Ready ;Receive 1 byte into scratchpad location 0
if Emic2Ready <> 58 then gosub timeout ; Emic2 manual says 58 character
sertxd ( "Received 58 character",cr,lf)
return

timeout:
pause 500
sertxd ( "Received a ",Emic2Ready," character",cr,lf)
return

Seems straight forward enough to do nothing but look for a 58 then return to the main body to send out the next speak message.

This is what I get in the Serial Terminal screen ... looks like cr that's invisible? But if I add Emic2Ready <> 13 to the IF statement I still get garbage control of the Emic2/18M2 program.

Received a aracter
Received a ? character
Received a
character
Received a
character
Received a
character
Received a
character
Received a
character


ALSO: I tried that very nice DO WHILE LOOP too, but nothing happens when I use that;

Wait4Emic2:
do
do : loop while Emic2Ready <> 13
loop until Emic2Ready = 13 ; Emic2 Manual it should be 58
return

and

Wait4Emic2:
do
do : loop while Emic2Ready <> 58
loop until Emic2Ready = 58 ; Emic2 Manual it should be 58
return

and

Wait4Emic2:
do
do : loop while Emic2Ready <> 58 or Emic2Ready <> 13
loop until Emic2Ready = 58 or Emic2Ready = 13 ; Emic2 Manual it should be 58
return
 
Last edited:

SolidWorksMagi

Senior Member
Hi,

FYI ... this is the original demo code from Parallax.com where I bought the Emic2 board;

' =========================================================================
'
' File....... Emic2_Demo.bs2
' Purpose.... Demonstration of the Emic 2 Text-to-Speech Module
' Author..... Joe Grand, Grand Idea Studio, Inc. [www.grandideastudio.com]
' E-mail..... support@parallax.com
' Updated.... 14 FEB 2012
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================

' -----[ Program Description ]---------------------------------------------
'
' This program provides a simple demonstration of the Emic 2 Text-to-Speech
' Module. Please refer to the product manual for full details of system
' functionality and capabilities.
'

' -----[ Revision History ]------------------------------------------------
'
' 1.0: Initial release
'

' -----[ I/O Definitions ]-------------------------------------------------

EMIC_TX PIN 0 ' Serial output (connects to Emic 2 SIN)
EMIC_RX PIN 1 ' Serial input (connects to Emic 2 SOUT)


' -----[ Constants ]-------------------------------------------------------

#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
T9600 CON 84
#CASE BS2SX, BS2P
T9600 CON 240
#ENDSELECT

EmicBaud CON T9600


' -----[ Initialization ]--------------------------------------------------

Init:
DEBUG CLS, "Emic 2 Text-to-Speech Module Demonstration", CR, CR

' when the Emic 2 powers on, it takes about 3 seconds for it to successfully
' intialize. it then sends a ":" character to indicate it's ready to accept
' commands. if the Emic 2 is already initialized, a CR will also cause it
' to send a ":"
DEBUG "Waiting for Emic 2..."
SEROUT EMIC_TX, EmicBaud, [CR]
SERIN EMIC_RX, EmicBaud, 5000, No_Response, [WAIT(":")]
DEBUG "Ready!", CR


' -----[ Program Code ]----------------------------------------------------

Main:
DEBUG "Speaking some text..."
SEROUT EMIC_TX, EmicBaud, ["S", "Hello. My name is the E mik, 2, Text-to-Speech module. I would like to sing you a song.", CR] ' Send the desired string to convert to speech
SERIN EMIC_RX, EmicBaud, [WAIT(":")] ' Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
DEBUG "Done!", CR

PAUSE 500 ' Short delay

DEBUG "Singing a song..."
SEROUT EMIC_TX, EmicBaud, ["D1", CR] ' Play the built-in demonstration song. See the product manual for exact settings used to create this song.
SERIN EMIC_RX, EmicBaud, [WAIT(":")] ' Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
DEBUG "Done!", CR

DEBUG CR, "Demonstration complete!"
END


' -----[ Subroutines ]-----------------------------------------------------

No_Response:
' if we get here, it means we did not receive a ":" from the Emic 2
DEBUG "No response!", CR, CR, "Ending demonstration!"
END


' -----[ End of File ]--------------------
 

hippy

Technical Support
Staff member
this is the original demo code from Parallax.com where I bought the Emic2 board
Thanks.

Code:
SEROUT EMIC_TX, EmicBaud, ["S", "Hello....", CR]
SERIN EMIC_RX, EmicBaud, [WAIT(":")]  ' Wait here until the Emic 2 responds with a ":"
That would indicate to me that the module sends back a colon, this code would not complete if it did not.

I would guess that it also sends CR ( and possibly LF ) before the colon. The BS2 probably doesn't care about that and ignores everything until the colon.

The question then is why the code in Post #19 detects a CR but not the colon.

I would suggest going back to the 28X2 used earlier as switching to an 18M2 may make things more difficult to analyse.
 

jims

Senior Member
Does this statement from page 92 of Manual 2 help to explain what's happening when use the M2 chip? Jims
"Example - M2 parts:
On M2 parts the hserin command is used to transfer background received bytes
into a variable. Up to two bytes can be &#8216;background received&#8217; at any time during
the PICAXE program (not just when the hserin command is processing) and are
temporarily stored in a 2 deep FIFO buffer. Any more than two bytes are lost.
Therefore on M2 parts the hserin command is non-blocking, it always processes
immediately. If there is received data in the internal buffer the first byte is copied
into the variable, if not the variable is left unaltered and the program continues
on the next line. If two bytes are expected in the buffer it is necessary to use two
separate hserin commands to retrieve both bytes."
 

Goeytex

Senior Member
The following test program will show exactly what the EMIC device sends.

For Picaxe 28X2
Code:
[color=Navy]#no_table[/color]

[color=Blue]Hsersetup B9600_8[/color][color=Black],[/color][color=Navy]%001[/color]
[color=Blue]setintflags [/color][color=Navy]%00100000[/color][color=Black],[/color][color=Navy]%00100000[/color]

[color=Blue]symbol [/color][color=Purple]numbytes [/color][color=DarkCyan]= [/color][color=Purple]b0[/color]
[color=Blue]symbol [/color][color=Purple]ack [/color][color=DarkCyan]= [/color][color=Purple]b1[/color]
[color=Blue]symbol [/color][color=Purple]cntr [/color][color=DarkCyan]= [/color][color=Purple]w1[/color]

[color=Black]MAIN:[/color]

[color=Purple]ack [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Purple]cntr [/color][color=DarkCyan]= [/color][color=Navy]0[/color]

[color=Blue]Do

   hserout [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]([/color][color=Red]"S"[/color][color=Black],[/color][color=Red]"Hello"[/color][color=Black], [/color][color=Blue]cr)
  
 [/color][color=Green]'wait up to 10 sec for serial interrupt 
    [/color][color=Purple]cntr [/color][color=DarkCyan]= [/color][color=Navy]1
    [/color][color=Blue]do while [/color][color=Purple]cntr [/color][color=DarkCyan]< [/color][color=Navy]1000
       [/color][color=Blue]pause [/color][color=Navy]10  [/color][color=Green]'// 10 ms
       [/color][color=Blue]inc [/color][color=Purple]cntr
       [/color][color=Blue]if [/color][color=Purple]ack [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then [/color][color=Black]main
    [/color][color=Blue]loop 
   
   sertxd ([/color][color=Red]"Timeout"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf) 
   goto [/color][color=Black]main 
 
 [/color][color=Blue]Loop
 
    
Interrupt:
  pause [/color][color=Navy]100 [/color][color=Green]'allow 100 ms for all bytes to arrive
  [/color][color=Purple]numbytes [/color][color=DarkCyan]= [/color][color=Purple]hserptr [/color][color=DarkCyan]-[/color][color=Navy]1     
  [/color][color=Blue]sertxd ([/color][color=Red]"Received: "[/color][color=Blue])
  
    for [/color][color=Purple]ptr [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Purple]numbytes   
       [/color][color=Blue]sertxd ([/color][color=Black]#[/color][color=Purple]@ptr[/color][color=Black],[/color][color=Red]"  "[/color][color=Blue])[/color][color=Navy]}
    [/color][color=Blue]next
    sertxd (cr[/color][color=Black],[/color][color=Blue]lf)    
  [/color][color=Purple]flags [/color][color=DarkCyan]= [/color][color=Navy]0
  [/color][color=Blue]setintflags [/color][color=Navy]%00100000[/color][color=Black],[/color][color=Navy]%00100000
  [/color][color=Purple]hserptr [/color][color=DarkCyan]= [/color][color=Navy]0
  [/color][color=Purple]cntr [/color][color=DarkCyan]= [/color][color=Navy]0
  [/color][color=Purple]ack [/color][color=DarkCyan]= [/color][color=Navy]1 
  [/color][color=Blue]return
  
 [/color]
 

jims

Senior Member
Goeytex...glad that you're "on-the-mend". When using Picaxe M2 chips; is there anyplace in "code explorer" (or wherever) to observe the contents of the 2 deep FIFO buffer for background received data? Jims
 

hippy

Technical Support
Staff member
Why HSEROUT / HSERIN ?

There is no way to see what is held in the internal buffer using Programming Editor.

I suspect the module sends back CR-LF-colon so it could be possible to just look for CR although that did not seem to have worked if I read previous posts correctly.

Not sure why the code is using HSEROUT and HSERIN but an alternative could be to use SEROUT and SERIN, because a SERIN can simply wait for a colon and should ignore everything before the colon ...

SerOut TX, BAUD, ( "S", "Hello", CR )
SerIn RX, BAUD, ( ":" )
SerTxd( "Got the colon!", CR, LF )

There may however be turn-round time issues with that, how soon things are sent as a reply after the SEROUT completes and how soon SERIN begins executing. It would probably be worth trying.

Could even be worth trying a HSEROUT with SERIN ...

HSerOut 0, ( "S", "Hello", CR )
SerIn RX, BAUD, ( ":" )
SerTxd( "Got the colon!", CR, LF )
 

SolidWorksMagi

Senior Member
There is no way to see what is held in the internal buffer using Programming Editor.

I suspect the module sends back CR-LF-colon so it could be possible to just look for CR although that did not seem to have worked if I read previous posts correctly.

Not sure why the code is using HSEROUT and HSERIN but an alternative could be to use SEROUT and SERIN, because a SERIN can simply wait for a colon and should ignore everything before the colon ...

SerOut TX, BAUD, ( "S", "Hello", CR )
SerIn RX, BAUD, ( ":" )
SerTxd( "Got the colon!", CR, LF )

There may however be turn-round time issues with that, how soon things are sent as a reply after the SEROUT completes and how soon SERIN begins executing. It would probably be worth trying.

Could even be worth trying a HSEROUT with SERIN ...

HSerOut 0, ( "S", "Hello", CR )
SerIn RX, BAUD, ( ":" )
SerTxd( "Got the colon!", CR, LF )



I"m trying to keep the serin/serout connected to the PC for other tasks ... although other uses might not care for that setup.
 

Goeytex

Senior Member
Using Serin/Serout will not affect the serial connection to the PC. Serin / serout can use the same pins you are now using for hserin/hserout.
 

SolidWorksMagi

Senior Member
Emic2 &amp; PICAXE 28X2 ...

SolidWorksMagi...I've been following this thread closely, and I plan to order an Emic 2 card to speak various status info from my controllers (temperatures, Relays and lights ON/OFF, TOD, etc). Have you definitely settled on some variation of the simplified code that Hippy has suggested? Thank you, Jims

Here is my full program listing ... it's working very nearly perfect catching the 13 character for control ... the Emic Speaks English, Spanish and Sings "DAISY".

Code:
; Emic2.bas

#picaxe 28X2   ; Define the µProcessor IC Type

hsersetup B9600_8, %001

; BEGIN Main Body * * * * * * * * * * * * * * * * * * * * *
pause 3000

do
  gosub Paul
  gosub Slowest
  gosub Speak1

  gosub Speech0

  gosub Song1

  gosub Speech2
loop
end
; END  Main Body * * * * * * * * * * * * * * * * * * * * **

; BEGIN Subroutines * * * * * * * * * * * * * * * * * * * *
Wait4Emic2:
do
  do : loop while ptr = hserptr
  loop until @ptrinc = 13  ; Emic2 Manual it should be 58
  return

; Demo Speaks & Songs
Speak1:
  hserout 0, ("S", "This is Message 1 speaking slower",cr)
  gosub Wait4Emic2
  return

Speech0:
  hserout 0, ("D0",cr)
  gosub Wait4Emic2
  return

Song1:
  hserout 0, ("D1",cr)
  gosub Wait4Emic2
  return

Speech2:
  hserout 0, ("D2",cr)
  gosub Wait4Emic2
  return


; Voices
Paul:
  hserout 0,("N0",cr)  ; Uppity Ursula Voice
  gosub Wait4Emic2
  return

Harry:
  hserout 0,("N1",cr)  ; Uppity Ursula Voice
  gosub Wait4Emic2
  return

Betty:
  hserout 0,("N2",cr)  ; Uppity Ursula Voice
  gosub Wait4Emic2
  return

Ursula:
  hserout 0,("N3",cr)  ; Uppity Ursula Voice
  gosub Wait4Emic2
  return

Dennis:
  hserout 0,("N4",cr)  ; Uppity Ursula Voice
  gosub Wait4Emic2
  return

Kit:
  hserout 0,("N5",cr)  ; Uppity Ursula Voice
  gosub Wait4Emic2
  return

Frank:
  hserout 0,("N6",cr)  ; Uppity Ursula Voice
  gosub Wait4Emic2
  return

Rita:
  hserout 0,("N7",cr)  ; Uppity Ursula Voice
  gosub Wait4Emic2
  return

Wendy:
  hserout 0,("N8",cr)  ; Uppity Ursula Voice
  gosub Wait4Emic2
  return


; Voice Speeds
Slowest:
  hserout 0,("W75",cr)   ; Slowest Speech
  gosub Wait4Emic2
  return

Slow:
  hserout 0,("W100",cr)  ; Slow Speech
  gosub Wait4Emic2
  return

Normal:
  hserout 0,("R",cr)     ; Default Speech Settings
  gosub Wait4Emic2
  return

Fast:
  hserout 0,("W250",cr)  ; Fast Speech
  gosub Wait4Emic2
  return

Faster:
  hserout 0,("W300",cr)  ; Faster Speech
  gosub Wait4Emic2
  return

Fastest:
  hserout 0,("W400",cr)  ; Fastest Speech
  gosub Wait4Emic2
  return

; VOICES:
;0: Perfect Paul (Paulo)
;1: Huge Harry (Francisco)
;2: Beautiful Betty
;3: Uppity Ursula
;4: Doctor Dennis (Enrique)
;5: Kit the Kid
;6: Frail Frank
;7: Rough Rita
;8: Whispering Wendy (Beatriz) 


;  COMMAND SET: 
;Sx Convert text-to-speech:
;x = message (1023 characters maximum)
;Dx Play demonstration message: x = 0 (Speaking), 1 (Singing), 2 (Spanish)
;X Stop playback (while message is playing)
;Z Pause/un-pause playback (while message is playing)
;Nx Select voice: x = 0 to 8
;Vx Set audio volume (dB): x = -48 to 18
;Wx Set speaking rate (words/minute): x = 75 to 600
;Lx Select language: x = 0 (US English), 1 (Castilian Spanish), 2 (Latin Spanish)
;Px Select parser: x = 0 (DECtalk), 1 (Epson)
;R Revert to default text-to-speech settings
;C Print current text-to-speech settings
;I Print version information
;H Print list of available commands


; Emic2 LED:
;1. Green: Idle state. Waiting for a valid command to be sent by the host.

;2. Red: Active state. For example, during a text-to-speech conversion.

;3. Orange (Solid): Initialization state. Occurs on power-up only. 
;      Emic 2 takes approximately three seconds to properly initialize on power-up 
;      before it is ready to receive commands.   

;4. Orange (Blinking): Error state. Emic 2 has malfunctioned 
;      due to an on-board communication error. 
;      If a power cycle of Emic 2 does not remedy the situation, 
;      please contact Parallax technical support for further assistance.
 
Last edited:
Top