So I kinda thought this part of my project would be the easy part, but it’s beginning to look like I was wrong. I’m trying to talk to my ssc32 from a raspberry pi (in python) over a usb->serial cable and it’s giving me a ton of trouble. I’ve already gone through a ton of debugging just getting the pyserial module to work; things like removing the ttyAMA0 references from /etc/inittab and whatnot, and I’m reasonably confident that I’ve set it up properly. I’ve heard the usb->serial cables can be notoriously unreliable but I’ve used this specific one for a whole semester in a previous microP class so I’m feeling confident in that as well. I’m using the code posted by linuxguy here.
Specifically:
[code]
#!/usr/bin/python
Import the Serial module
import serial;
Reads single characters until a CR is read
def Response(port):
ich = “”;
resp = “”;
while (ich <> ‘\r’):
ich = port.read(1);
if (ich <> ‘\r’):
resp = resp + ich;
return resp;
Open the port at 115200 Bps - defaults to 8N1
ssc32 = serial.Serial(’/dev/ttyS0’, 115200); #mine being /dev/ttyAMA0
Send the version command
ssc32.write(“ver\r”);
Read the response
inp = Response(ssc32);
Show what we got back
print inp;
Close the port
ssc32.close();[/code]
Running this now throws no errors, exceptions or hangs, but my response is always empty. I’ve tinkered with the read() a bit (and checked the blinking lights!) and my current thinking is that the ssc32 is not actually receiving my commands, causing my script to hang on reading more than a byte without a timeout value. At this this point I’m at a loss, I’ve worked with this controller before and getting the version back is about as basic as it gets. My project is on the ‘critical path’ as it were, so any pointers or direction on what I could be doing wrong would be amazing.
I have the Pi talking right now to an SSC-32 (actually the one on my T-Hex is a beta SSC-32u), but have 2nd Pi talking to SSC-32 using a USB to TTL converter.
Also I have code up on github.com\kurte\Raspberry_Pi for this project.
Note: I am using C++ not python. I am not a python expert so…
Things to check include: Is your SSC-32 powered up? ie is there power going to VL or alternatively I have mine hacked to take +5v from USB to ttl converter and plugged it into one of the + pins on the SSC-32.
When your program runs, does the LED on the SSC-32 blink? If so it is getting some data, but maybe not necessarily valid data or baud.
Is your SSC-32 configured for 115200 baud rate (both baud jumpers installed)?
Are you sure it is /dev/ttyS0 ? My USB adapters often give addresses like /dev/ttyUSB0. Also I have set up on alias on my machine so I can use:
/dev/ttySSC-32 regardless of which hardware I am using… How I ddi that is in in the posting I mentioned.
Yes, I have it powered separately from a 9v battery.
I don’t see it blink at any point during the run, noticeably at least. This is what leads me to believe I’m having a writing or connection problem.
Yes. I re-checked all the hardware jumpers while I was in the relevant portion of the ssc32 manual.
The ttyS0 was left in there when I quoted linuxguy’s code snippet. I left a comment on that line saying that mine was /dev/ttyAMA0.
This is a topic of some confusion for me… when I plug in my cable, dmesg tells me that my device was connected on /dev/ttyUSB0 which is how most all other platforms I’ve used work, but when I tried using that as the port the script would hang on the constructor and never return. After some google-fu it seems that usb->serial adapters are attached as /dev/ttyAMA0 as referenced from here. I’ve tried several others just out of frustration and this is the only one that’s made it past the constructor or open() call. I’m open to suggestions on this though.
Thanks again, I’m scrolling through your git source now.
Again this assumes that you setup an alias to create the device: char szSSC32Device] = “/dev/ttySSC-32”;
But as you can see it would not be hard change the program to use whichever hardware device you wish to use.
If you are using /dev/ttyAMA0, did you update the hardware configuration files to not have this device used as a console? I have seen several different places that talk about this including: hobbytronics.co.uk/raspberry-pi-serial-port
Edit: Unless I am logged in as user Pi, when I run commands that use devices like my program: testSSC32
The program will fail to open the device, unless I sudo it, i.e. : sudo ./testSSC32
Just wanted to update the issue here: I fixed the problem. The correct device was /dev/ttyUSB, the crash was cause by a firmware problem in the PI. I’m not sure if apt-get dist-upgrade will work or not because I didn’t recompile the kernel, but the script provided HERE solved my problem in case anyone else wanders through with the same problem I had.
I see that you are using the onboard UART on the Raspberry Pi. I also had some issues with the serial port that might overlap with yours.
Apparently when you open the UART for the first time, a short pulse is sent that will obviously interfere with the receiving end and you will get a protocol error for the first packet sent.
This does not happen with a USB based UART. Anyway, it is something to keep in mind when using the onboard port.