Page 1 of 2

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 1:06 pm
by Deus
Hello!
I didn't where to post, as this is more of a question...
I have a project (feature detection) where I want RaspPi to just do the calculations and then output data (just numbers) trough an USB port to a PC (windows or linux based). The problem is that, as it turns out, you can't connect two PC's together via USB because they are both Hosts (USB standard defines Host and Device). As RPi is basically a PC (isn't it?) then I guess this is still the case? I just though RPi is more of a device and so I could use the USB interface?
The basic working principal is this:
RPi runs Linux (I want ArchLinux, but any could do I guess) and constantly runs a C++ program. This program outputs numbers via USB. Another PC then gets these numbers via USB and then an application uses these numbers.
To get me started I would like to make/get a simple example where RPI generates numbers randomly and then sends them to a PC which shows these numbers in a console.
So is this even possible?

Thank you in advance.

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 1:32 pm
by andri
1. Use USB to RS232 <—-> RS232 to US

http://img.ectrade.com/v/23/1f.....1abf4a.jpg

2. Use USB to USB cable (basically USB to LAN <-> LAN to USB)

http://www.allaboutadapters.co.....20dal.html

http://www.belkin.com/IWCatPro....._Id=275561

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 1:39 pm
by bobaruni
Use Lan port and crossover cable to PC or straight to Hub/Switch. You could make a mini web server and look at the data in a browser on the PC.

Alternatively, use GPIO pins wired up to printer port on PC, but printer ports are getting scarce these days.

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 3:22 pm
by mole125
The chipset is designed for mobile phones which normally mount as slave devices so I'd be fairly sure that the processor can manage it, I've no idea whether there would be linux drivers to do so or what you would need to do to work. You may also need to construct a dual ended usb cable to actually allow the connection to be made.

It is also possible to bit bang USB via the GPIO pins - though not sure about voltage levels and how much cpu overhead it would take.

Another alternative would be to use the GPIO pins but connected to a dedicated USB chip - or a microcontroller with USB support.

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 5:28 pm
by abishur
The r-pi is a full fledge PC and as such acts as a host device you'll have to use one of the other suggestions but it absolutely will not work as a slave device

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 6:40 pm
by Deus

The r-pi is a full fledge PC and as such acts as a host device


This sucks. I was hoping that mole125 could be right...
Those USB-To-USB connectors are for file sharing and while it could be possible to use them just for communication, I doubt that it will be that easy (or even possible).

RS232 is old and many new computers don't even have the damn thing. My idea was to use a laptop at the receiving end and them don't have RS232.

So why the hell is connecting to PC's together so hard in the 21th century? Because of the RS232 and COM ports this was very easy in the old times. Now we need to use Ethernet (even if the computer usually has one port and that involves using TCP/UDP, assigning IP's and so on) to send information just a few feet? There must be a better way... Making a custom board and then using GPIO is slowly becoming the only way. Does anyone tried something similar or has a place where I could learn how to do that?

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 7:05 pm
by spurious
I may be missing something here, but what is wrong with the ethernet port for talking to another PC?

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 7:11 pm
by merlino3737
I'm no expert but you could use 2 usb dial up modems and a null modem cable if you could get the modem drivers to work.

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 7:23 pm
by andri
Deus said:



The r-pi is a full fledge PC and as such acts as a host device


RS232 is old and many new computers don't even have the damn thing. My idea was to use a laptop at the receiving end and them don't have RS232.

So why the hell is connecting to PC's together so hard in the 21th century? Because of the RS232 and COM ports this was very easy in the old times. Now we need to use Ethernet (even if the computer usually has one port and that involves using TCP/UDP, assigning IP's and so on) to send information just a few feet? There must be a better way… Making a cus tom board and then using GPIO is slowly becoming the only way. Does anyone tried something similar or has a place where I could learn how to do that?


You can use USB to RS232 on both RPi and Laptop. (And null modem cable).

You will be have "virtual RSR232" on both Laptop and RPi.

If you familiar with RS232 programming  i think it's not difficult for you.

(Sorry for my english).

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 7:29 pm
by abishur
+1 to the usb to rs232 adapter.  I've used several and have been generally quite satisfied with them

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 8:07 pm
by drgeoff
merlino3737 said:


I'm no expert but you could use 2 usb dial up modems and a null modem cable if you could get the modem drivers to work.



Dial-up modems expect to connect to phone lines which provide dial tone to the calling end and ringing signal to the called end.  Agreed there are ways around that but it isn't really worth the hassle, the expense of the modems and the relatively slow speed of the end result.  I'd advise exhausting the other suggestions before investing any significant effort into this one.

And you don't connect modems together with a null modem cable.  A null modem cable is what you use instead of a pair of modems.

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 9:19 pm
by mole125
Abishur said:


The r-pi is a full fledge PC and as such acts as a host device you'll have to use one of the other suggestions but it absolutely will not work as a slave device


Are you certain about this? I may be misunderstanding page 200 of the datasheet (http://dmkenr5gtnd8f.cloudfron.....herals.pdf) and the linked to page the USB core is On-The-Go compatible (http://en.wikipedia.org/wiki/U....._On-The-Go) which means it can switch between acting as a host or a device.

Along with this the Configuration listing includes the following:Mode of Operation: 0 HNP- and SRP-Capable OTG (Device and Host) Number of Device Mode Endpoints in Addition to Control Endpoint 0: 7Number of Host Mode Channels: 8
This implies to me that it is technically possible for it to operate as a slave. (though I could be wrong) Whether there is currently any driver support to do this on linux, and if not whether sufficient information is available to ever actually write it is of course a different question. Certainly the other approaches mentioned may be easier to get working quicker (but cost more)

Re: USB communication with a PC

Posted: Sat Feb 18, 2012 9:54 pm
by abishur
mole125 said:


Abishur said:


The r-pi is a full fledge PC and as such acts as a host device you"ll have to use one of the other suggestions but it absolutely will not work as a slave device


Are you certain about this? I may be misunderstanding page 200 of the datasheet (http://dmkenr5gtnd8f.cloudfron.....herals.pdf) and the linked to page the USB core is On-The-Go compatible (http://en.wikipedia.org/wiki/U....._On-The-Go) which means it can switch between acting as a host or a device.

Along with this the Configuration listing includes the following:Mode of Operation: 0 HNP- and SRP-Capable OTG (Device and Host) Number of Device Mode Endpoints in Addition to Control Endpoint 0: 7Number of Host Mode Channels: 8
This implies to me that it is technically possible for it to operate as a slave. (though I could be wrong) Whether there is currently any driver support to do this on linux, and if not whether sufficient information is available to ever actually write it is of course a different question. Certainly the other approaches mentioned may be easier to get working quicker (but cost more)



My understanding is that those features are not being implemented.  I also know that if they were implemented, it wouldn't work on the model B as the LAN9512 chip is in the way.

Re: USB communication with a PC

Posted: Sun Feb 19, 2012 1:12 am
by oninoshiko
Deus said:



So why the hell is connecting to PC's together so hard in the 21th century? Because of the RS232 and COM ports this was very easy in the old times. Now we need to use Ethernet (even if the computer usually has one port and that involves using TCP/UDP, assigning IP's and so on) to send information just a few feet? There must be a better way… Making a custom board and then using GPIO is slowly becoming the only way. Does anyone tried something similar or has a place where I could learn how to do that?



I think you may be misremembering how "easy" RS232 is. I still have to use it from time to time in my day job, and after setting bps, flow control, stop bits, Bits per frame, plus knowing if each device is DCE or DTE, and if its using 9-pin, 25-pin, or modular connectors… just setting an IP is trivial.

Of course if you dont want to deal with IPs, noone says you even have to. Ethernet does not REQUIRE TCP/IP. If you are talking to your own devices, you could always write a new protocol, use IPX, or even Lanman/netbios.

Re: USB communication with a PC

Posted: Sun Feb 19, 2012 6:29 pm
by BjarkeHedegaard
Cant you use bluetooth for it?

Re: USB communication with a PC

Posted: Sun Feb 19, 2012 8:16 pm
by Deus

I may be missing something here, but what is wrong with the ethernet port for talking to another PC?


Why is it right? As I already said, I want to use RPi as a peripheral in a way, so why I would need to connect it to a router? I can't connect it to a PC because I have only one Ethernet port, and even then, I would require assigning IP's and ports and whatnot. This seems like unbelievable overkill. What I want in the end is to have a driver for PC, then plug in RPi and it works. Nothing more.


+1 to the usb to rs232 adapter.  I've used several and have been generally quite satisfied with them


Many PC's don't have rs232 ports (including mine). I want to be able to give this to someone else without a hassle.


My understanding is that those features are not being implemented.  I also know that if they were implemented, it wouldn't work on the model B as the LAN9512 chip is in the way.


Maybe someone who made the documentation could come and clear this up? As far as I know some people from Broadcom and of course the RPi itself comes around here.

So basically, if I was the only one who used this and if I did this for myself then I might use these ideas, but if I want to give this to others then I really need a very hassle free solution. I am looking into GPIO and a custom USB controller now. Maybe someone has some useful links about that?

edit:


Cant you use bluetooth for it?


I didn't know RPi had bluetooth... and I still think it doesn't. If you think of using a bluetooth dongle then maybe that can work, but then again I can use some Usb adapter dongle.

Re: USB communication with a PC

Posted: Mon Feb 20, 2012 1:16 am
by panik
Deus said:

 I am looking into GPIO and a custom USB controller now. Maybe someone has some useful links about that?
ATmega32U4 breakout board: http://www.adafruit.com/products/296

Dean Camera's excellent LUFA: http://www.fourwalledcubicle.c.....m/LUFA.php

Re: USB communication with a PC

Posted: Mon Feb 20, 2012 1:03 pm
by bredman
A USB solution is way overkill. Much easier to use Ethernet.

You do not need a router because the RPi can support a direct Ethernet connection to a PC.

If you run dhcpd on the RPi, you do not need to configure an IP address on the PC.

By using Ethernet instead of USB, you do not need to design drivers on both ends. Just use standard net streams or a simple protocol like http.

Using USB is just inventing problems for no reason.

Re: USB communication with a PC

Posted: Mon Feb 20, 2012 2:22 pm
by rpt
Easiest solution is two USB-RS232 adapters and a null modem cable. I use that all the time at work.

Re: USB communication with a PC

Posted: Mon Feb 20, 2012 2:53 pm
by jamesh
I disagree. The easiest solution is to use ethernet. Anything else adds excessive hardware and/or software.

Connecting PC's together isn't difficult nowadays. You just use ethernet. Back in the day, connecting PC together was a right PITA. Ethernet was flakey, RS232 was horribly slow (and flakey), parallel ports could be used - they works occasionally, but were mostly flakey.

Now we plug the cable into the device, then the other device (or hub) and it just works.

Mostly.

Re: USB communication with a PC

Posted: Mon Feb 20, 2012 3:31 pm
by abishur
rpt said:


Easiest solution is two USB-RS232 adapters and a null modem cable. I use that all the time at work.



This is what I was suggesting with my +1 to usb to rs232 adapter

Re: USB communication with a PC

Posted: Mon Feb 20, 2012 3:44 pm
by rpt
JamesH said:


I disagree. The easiest solution is to use ethernet. Anything else adds excessive hardware and/or software.


You need less software to use RS232. The OP wants to just send numbers - this is done just by opening the port and writing to the file descriptor. Ethernet involves allocating IP addresses, opening streams etc.


Connecting PC's together isn't difficult nowadays. You just use ethernet. Back in the day, connecting PC together was a right PITA. Ethernet was flakey, RS232 was horribly slow (and flakey), parallel ports could be used - they works occasionally, but were mostly flakey.

Now we plug the cable into the device, then the other device (or hub) and it just works.

Mostly.


What just works? It depends what application you are running.

Re: USB communication with a PC

Posted: Mon Feb 20, 2012 3:45 pm
by rpt
Asda sell USB A to A leads. Apart from making your computer's PSU smoke, does anybody know what these are for?

Re: USB communication with a PC

Posted: Mon Feb 20, 2012 4:52 pm
by Joe Schmoe
JamesH said:  

I disagree. The easiest solution is to use ethernet. Anything else adds excessive hardware and/or software.

Connecting PC's together isn't difficult nowadays. You just use ethernet. Back in the day, connecting PC together was a right PITA. Ethernet was flakey, RS232 was horribly slow (and flakey), parallel ports could be used – they works occasionally, but were mostly flakey.

Now we plug the cable into the device, then the other device (or hub) and it just works.

This thread is a classic instance of "The XY problem" (Google it - especially looking for the seminal piece by JdPollard).

The answer to the question "How do I connect two PCs together via USB?" is "Get two USB <> Serial" adapters.

The solution to the problem "How do I connect two PCs together and exchange data between them - what is the best and easiest way to do this?" is "Use Ethernet and TCP/IP".

Note the difference.   As a responder, you are, of course, free to answer either (or both) question, but don't make the mistake of assuming that they are the same question - or that they have the same audience.

 

Re: USB communication with a PC

Posted: Mon Feb 20, 2012 5:22 pm
by jamesh
Are they different questions?

You could certainly argue  a good solution  for connection two PC's together with USB would be two USB bluetooth adapters. Then you don't even need the cable. Cheaper as well. And note than that answers the question of using USB.

Or how about two USB to ethernet adapters connected with an ethernet cable. Once again, answers the question.

Or how about just using ethernet. That technically certainly uses USB on the Raspi end (since the SoC talks to the ethernet adapter using USB).

Yay, I can be picky too!

And please don't shout, although that's probably a side effect of the dodgy forum software.