I'm using Voice Recognition Module -- Arduino Compatible. It says there to use AccessPort, but since I'm on Mac OS X it won't work. I don't know of any other solution but to write my own in Python while I'm open to any other language that works.
I found some solutions over here about pySerial but as of now it doesn't seem to work.
import serial import struct def C(val): return struct.pack('H', val) ser = serial.Serial(port='/dev/tty.PL2303-00001004', baudrate=9600, timeout=1) ser.nonblocking() ser.write(C(0xaa11)) print ser.read().__repr__() ser.close()
It opens, write two bytes and doesn't read anything.
0xaa11 is used to start recording. My device seems to be in waiting mode since the red LEDs flash rapidly. Even if I do
0xaa00, it doesn't do much either. I even tried to change the byte order to
0x11aa and so on, but I never receive my
0xe0 error code.
In the documentation it says to send it as hex, so my guess is that accessport converts hex to a
Short which use two bytes.
0xaa00 is a two bytes number. I even tried to change the baud rate to
38400 in case someone before me did set that to this speed.
I'd be happy to read anything from that serial port because as of now I can write, it does nothing and reads nothing...
As of now, I'll try to install AccessPort with crossover. If it still doesn't work, I'll have to find a Windows box. I could even write my own bridge with my Arduino board since the driver I'm using might be buggy.
In case it matters, I'm using a USB to Serial PL2303.
I plugged my output and input pin to test my USB-to-serial. I do read what I write so the driver is working fine.
I'll try to set it up directly with Arduino and test directly from there.
0xaa11 is different than sending
0xaa and then
0x11. The serial seems to reverse the byte order.
On the other hand, the documentation doesn't tell about bit endianess, so it might be the problem too.
I kind of solved my problem while it was pretty dumb after all.
Here is my final script:
import serial import struct from time import sleep def C(val): return struct.pack('!H', val) ser = serial.Serial(port='/dev/tty.PL2303-00002006', baudrate=9600) sleep(2) ser.write(C(0xaa00)) sleep(1) ser.write(C(0xaa36)) sleep(1) ser.write(C(0xaa11)) sleep(1) while True: print ser.readline()
If someone ever want to use that module, it works. It will switch to a mode where it puts to output words instead of bytes so you can read it using readline...
I used in struct.pack "!H" to use network endianess it change 0xaa00 to 0xaa 0x00 like it should be.
But the real problem here wasn't in the script. Since the usb to serial did work I thought that it was strange that the module didn't respond anything... not even a byte for errors. Every command in this module must return something. That's why I looked back at my cable and checked the pins...
gnd, power supply to power supply and then
rxd... While everything seems ok... I should receive something... And then I really thought... what if it's not supposed to use a cross cable and
txd should be plugged to
rxd... Apparently it does.
I switch the cable and now data is sent and received.
So anyone using that module should check that it's correctly plugged in. If it doesn't work, switch the data pins.