amadeus84
Posts: 18
Joined: Sun Jun 22, 2014 5:55 pm

serial usb programming

Mon Jul 21, 2014 5:38 am

Some time ago I wrote a program that opens the serial port (/dev/ttyS0) on a PC and controls a PTZ camera. Now I want to use that with the Pi, but of course, the Pi has no serial port (RS232). Given the right RS232 to usb converter (perhaps this one
http://www.amazon.com/Manhattan-Serial- ... =pd_cp_e_2), what's involved in porting the code from the serial port to the usb port?

An alternative is to use a TTL to RS232 converter and talk to the UART port. But since I already have the usb to RS322
cable, I'd like to try the usb first.

Any examples or tutorials?

Thanks!

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: serial usb programming

Mon Jul 21, 2014 6:28 am

It should be as simple as replacing "/dev/ttyS0" with "/dev/ttyUSB0"

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: serial usb programming

Mon Jul 21, 2014 7:23 am

There is also an on-board serial port at /dev/ttyAMA0

You may need a level-shifter (it operates at 3.3V) and you may need to reconfigure it so that it is not used by the kernel:
http://elinux.org/RPi_Serial_Connection ... erial_port

amadeus84
Posts: 18
Joined: Sun Jun 22, 2014 5:55 pm

Re: serial usb programming

Mon Jul 21, 2014 11:36 am

PeterO wrote:It should be as simple as replacing "/dev/ttyS0" with "/dev/ttyUSB0"

PeterO

That's what I was hoping, but I'm trying this on my pc first, and I don't have /dev/ttyUSB0. I do have /dev/ttyS[0-3].

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: serial usb programming

Wed Jul 23, 2014 10:42 pm

If you plug your USB-serial cable into your (Linux, right?) PC, it should get automatically recognised and create a /dev/ttyUSB0 device for you.

If not you'll have to look at the 'dmesg' output to work out why the driver didn't get automatically loaded...

Return to “Bare metal, Assembly language”