SEROUT Hex Numbers?

erco

Senior Member
I need an M2 chip to serial output hex format numbers to control a speech recognition module. Possible?

SEROUT command says "Optional #'s are for outputting ASCII decimal numbers, rather than raw characters" but it doesn't say what format "raw characters" is.
 

inglewoodpete

Senior Member
I presume it needs ASCII characters 0-9, A-F to be sent in pairs.

Edit: While the code I posted here will send ASCII-HEX data as text, post #9 by @Aries indicates that simple byte values (Decimal 0-255 / $00-FF) are required by the module.

You may be able to adapt the following code for your purpose:
Rich (BB code):
'
' ----- ShowHex: Send Hexadecimal value to PE Terminal -----------------------------------------
'
'        Send a  byte  as hex to terminal on the programming lead
'        Send a nibble as hex to terminal on the programming lead
'        Alternate "D" entries cause a leading $ sign to be sent
'
'        Entry:   bByteToShow (byte) data to be transmitted
'        Exit:    bByteToShow (byte) unchanged
'        Used:    bTemp       (byte)
'
ShowHexD:SerTxd("$")                      'Alternate entry
ShowHex: bTemp = bByteToShow >> 4         'Get high nibble
         GoSub SHexNib2                   'Show it
         Goto SHexNibl
ShowNibD:SerTxd("$")                      'Alternate entry
SHexNibl:bTemp = bByteToShow And mskLoNibble
SHexNib2:bTemp = bTemp + "0"              'Convert to ASCII
         If bTemp > "9" Then              'Separate out and
            bTemp = bTemp + 7             ' correct over-decimal part.
         EndIf
         SerTxd(bTemp)                    'Display it
         Return
 
Last edited:

westaust55

Moderator
More information or data sheet on your module could be helpful.

it may want the hex values in a format such as
0X41 0XAF 0X0D
 

westaust55

Moderator
Raw values (not ascii encoded)
Can be sent as binary %10101010
Or as hexadecimal $AA or 0xAA
Or by decimal value 170

binary is the native form for most/all microcontrollers and computers
Hex and decimal are just ways to express the same value which can be easier for us humans to understand/interpret.
 

steliosm

Senior Member
It's pretty weird that you need to send a hex representation of the command value instead of the actual value. Any change the datasheet has been translated from Chinese and this part may contain errors?
 

erco

Senior Member
Thanks all. Here is the module. I bought it probably 8 years ago, but it's still available on ebay.

https://www.geeetech.com/wiki/images/6/69/Voice_Recognize_manual.pdf manual

https://www.banggood.com/Voice-Recognition-Module-With-Microphone-Control-Voice-Board-p-10 56127.html

The module works quite well with a PC using Hterm serial terminal, just as this video shows:


It's a bit convoluted because he is using an Arduino as his USB/serial adapter, and he is sending hex characters but receiving ASCII. I will be playing with this today with a 14M2, will advise. Thanks again.
 

Aries

New Member
Just looking at the manual (the "introduction" on banggood), you have commands like:
serial.write(0x37)
That isn't sending hex characters - it is sending the value (in Picaxe terms) $37 (or 55 decimal)
 

erco

Senior Member
Success! Jeez, that took a lot of brute force experimenting. The Geeetech module is finnicky since it has its own micro & ecosystem, and the documentation is scarce, so it took a while to configure and get the comms right sending numbers in hex. I wasted half a day trying to get 4800 baud working but no go, so I had to stick with 9600 baud, running my 08M2 at 8 Mhz. Recognition is surprisingly good, but the limiter is the number of phrases. User trains up to 15 phrases of 1.3 sec max, but the phrases are in 3 groups of 5. That is, only 5 phrases are active at a time. So to make full use, you would have to break up your phrases in the right groups, then based on the phrase, the Picaxe can select (import) a different group of 5 phrases. The attached code looks ridiculously simple and obvious, but when you start from nothing, there's nothing simple and obvious about it!


Code:
'voice recognition chip 9600 baud
'c.1 output
'c.2 input

#picaxe 08m2
#no_data

pause 500
setfreq m8 ' 8mHz sets 9600 baud
pause 500


serout 1,T9600_8,($00,$AA,$00) ' wait mode
pause 400

sertxd ("Voice Recognition Module",13,10)

serout 1,T9600_8,($00,$AA,$22) ' import word group 2 
pause 400

serout 1,T9600_8,($00,$AA,$37) ' compact mode
pause 400

sertxd ("READY",13,10)


do
serin 2,T9600_8,b0:sertxd (#b0,13,10)
loop
 

Attachments

Last edited:
Top