Deus
Posts: 3
Joined: Sat Feb 18, 2012 12:26 pm

Re: USB communication with a PC

Sat Feb 18, 2012 1:06 pm

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.

andri
Posts: 51
Joined: Fri Jan 27, 2012 5:05 pm

Re: USB communication with a PC

Sat Feb 18, 2012 1:32 pm

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

bobaruni
Posts: 2
Joined: Sat Feb 18, 2012 1:24 pm

Re: USB communication with a PC

Sat Feb 18, 2012 1:39 pm

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.

mole125
Posts: 228
Joined: Tue Jan 10, 2012 2:01 pm

Re: USB communication with a PC

Sat Feb 18, 2012 3:22 pm

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.

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: USB communication with a PC

Sat Feb 18, 2012 5:28 pm

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
Dear forum: Play nice ;-)

Deus
Posts: 3
Joined: Sat Feb 18, 2012 12:26 pm

Re: USB communication with a PC

Sat Feb 18, 2012 6:40 pm


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?

spurious
Posts: 343
Joined: Mon Nov 21, 2011 9:29 pm

Re: USB communication with a PC

Sat Feb 18, 2012 7:05 pm

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

merlino3737
Posts: 5
Joined: Sat Feb 18, 2012 6:51 pm

Re: USB communication with a PC

Sat Feb 18, 2012 7:11 pm

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.

andri
Posts: 51
Joined: Fri Jan 27, 2012 5:05 pm

Re: USB communication with a PC

Sat Feb 18, 2012 7:23 pm

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).

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: USB communication with a PC

Sat Feb 18, 2012 7:29 pm

+1 to the usb to rs232 adapter.  I've used several and have been generally quite satisfied with them
Dear forum: Play nice ;-)

drgeoff
Posts: 10624
Joined: Wed Jan 25, 2012 6:39 pm

Re: USB communication with a PC

Sat Feb 18, 2012 8:07 pm

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.

mole125
Posts: 228
Joined: Tue Jan 10, 2012 2:01 pm

Re: USB communication with a PC

Sat Feb 18, 2012 9:19 pm

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)

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: USB communication with a PC

Sat Feb 18, 2012 9:54 pm

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.
Dear forum: Play nice ;-)

oninoshiko
Posts: 76
Joined: Sun Jan 29, 2012 9:16 pm

Re: USB communication with a PC

Sun Feb 19, 2012 1:12 am

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.

BjarkeHedegaard
Posts: 12
Joined: Fri Feb 03, 2012 11:06 pm
Contact: Website

Re: USB communication with a PC

Sun Feb 19, 2012 6:29 pm

Cant you use bluetooth for it?

Deus
Posts: 3
Joined: Sat Feb 18, 2012 12:26 pm

Re: USB communication with a PC

Sun Feb 19, 2012 8:16 pm


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.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: USB communication with a PC

Mon Feb 20, 2012 1:16 am

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
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

bredman
Posts: 1415
Joined: Tue Jan 17, 2012 2:38 pm

Re: USB communication with a PC

Mon Feb 20, 2012 1:03 pm

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.

rpt
Posts: 51
Joined: Tue Jan 31, 2012 3:09 pm

Re: USB communication with a PC

Mon Feb 20, 2012 2:22 pm

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

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26388
Joined: Sat Jul 30, 2011 7:41 pm

Re: USB communication with a PC

Mon Feb 20, 2012 2:53 pm

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.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: USB communication with a PC

Mon Feb 20, 2012 3:31 pm

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
Dear forum: Play nice ;-)

rpt
Posts: 51
Joined: Tue Jan 31, 2012 3:09 pm

Re: USB communication with a PC

Mon Feb 20, 2012 3:44 pm

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.

rpt
Posts: 51
Joined: Tue Jan 31, 2012 3:09 pm

Re: USB communication with a PC

Mon Feb 20, 2012 3:45 pm

Asda sell USB A to A leads. Apart from making your computer's PSU smoke, does anybody know what these are for?

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: USB communication with a PC

Mon Feb 20, 2012 4:52 pm

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.

 
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26388
Joined: Sat Jul 30, 2011 7:41 pm

Re: USB communication with a PC

Mon Feb 20, 2012 5:22 pm

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.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

Return to “Other projects”