Go Down

Topic: Can a YUN serial to /dev/ttyUSB0? (Read 2519 times) previous topic - next topic

aggrav8d

Feb 03, 2015, 02:28 am Last Edit: Feb 03, 2015, 02:38 am by aggrav8d
I installed drivers on my YUN and now it recognizes a USB device plugged in as /dev/ttyUSB0.

I want to open Serial to the PC and then a second Serial to /dev/ttyUSB0.  My goal is to have the YUN act as a pass through - I send simple commands and get back whatever the USB device reports.

I'm not adept at python, so I'd like to use the sketch system I'm familiar with in Arduino.

Please: how do I talk to /dev/ttyUSB0?  I've done the rest before.

Thank you!
Dance as if no one is watching; post as if it is going to be read aloud as evidence in court.

jessemonroy650

::::SNIP::::

Please: how do I talk to /dev/ttyUSB0?  I've done the rest before.

Thank you!
aggrav8d,
apparently you are on some type of Unix machine. Please elaborate for additional help.

1) You can open the /dev/ttyUSB0 just like any file. You can read and write, what you get back depends on what's plugged in.

2) You want to pass data through. Can you elaborate? There are two USB ports on the Yun. One (mini) is connect to the ATmega32u4. The other (HOST) is connected to the Atheros AR9331 . As the mini talks directly to the ATmega32u4m, to talk to the Atheros AR9331 you have to use the Bridge library. This all sounds silly, as the serial port is bidirectional.

You have two channels. Do you need 4 channels?

Jesse

ShapeShifter

apparently you are on some type of Unix machine. Please elaborate for additional help.
Ummm... Yes... He's on an OpenWRT machine... He has the USB device plugged into the host port of the AR3391 processor, and he wants to talk to it from a sketch on the 32U4 processor.

Aggrav8d: talking between the two USB ports is complicated by them being in two different processors. The connection between them is a serial port that normally runs the Bridge library. With the USB host port being on the OpenWRT processor, I think you're going to need to write some code on the Linux side to handle that part of the communications.

The basic path is: USBd <--> sketch <--> Bridge <--> Linux <--> USBh where:
  • USBd is the device port on the 32U4 processor, connected to your PC
  • sketch is the Arduino sketch you write for the 32U4 processor
  • Bridge is the serial port and library running between the two processors
  • Linux is a program you write on the AR3391 processor
  • USBh is the host port where your device is connected

sonnyyu

#3
Feb 03, 2015, 02:52 pm Last Edit: Feb 03, 2015, 02:54 pm by sonnyyu
USB/IP: A Transparent Device Sharing Technology over IP Network. ( USB over IP)



http://usbip.sourceforge.net/


Yun as Server, connect with USB device and  load usbip stack.
PC as Client and  load usbip driver as well.
Between PC and Yun is IP network ( WIFI or Ethernet )

PC see USB device as local USB device.












aggrav8d

@jessemonroy650 - /dev/ttyUSB0 is connected to the Atheros AR9331.  Bridge can open it like a file?  How would I control the baud rate and parity?  The device in question is 500kbps 8N1.

I only need to pass through for debugging.  Once I'm done it will log data to SD card.

@shapeshifter - I think you have it exactly correct.  Bridge doesn't already provide me this ability?  :(
I was surprised there was no YUN sample for talking to a device from a sketch.  Too bad.  In the future I would love to plug a joystick into a YUN and use it to drive my robot.

@sonnyu - interesting, tho not what I'm going for.
Dance as if no one is watching; post as if it is going to be read aloud as evidence in court.

ShapeShifter

#5
Feb 03, 2015, 07:48 pm Last Edit: Feb 03, 2015, 07:57 pm by ShapeShifter
I don't believe an Arduino sketch running on the 32U4 can use the Bridge library to open the USB device on the AR3391. To be honest, I've not tried it, but it is probably only for accessing the SD card.

I only need to pass through for debugging.  Once I'm done it will log data to SD card.
This is starting to sound more and more like a strictly Linux solution, and not necessarily involving a sketch on the Arduino side.

The USB device will be accessed from some Linux code. The SD card is also on the Linux processor, and while that is accessible from a sketch through the Bridge library, it would be much more efficient to do that on the SD side as well.

This data flow:
  USB --> Linux --> SD
would be much more efficient than:
  USB --> Linux -->  Bridge -->  sketch -->  Bridge -->  SD

You could probably figure out a way to use the latter data flow, doing part of it in a sketch. But I think you're going to have to write at least part of the code on the Linux side, and it will probably be easier to do most, if not all, of it on the Linux side.

Do you have any other I/O requirements that would require a sketch to be involved? Anything connected to the Arduino header pins?


Quote
In the future I would love to plug a joystick into a YUN and use it to drive my robot.
You will almost certainly have to get the Linux side involved. I did something similar with some bar code readers: using a hub, they plug into the USB host port on the Limux side. A Python scrip reads HID events from the bar code reader, and uses the bridge to send them to the sketch. The sketch uses Bridge synchronous Process objects to start two instances of the Python script, one for each reader. The sketch gets the events from the Python script, does some massaging of the data, sends it out the 32U4's USB port and possibly a network socket, and also controls some outputs based on scan activity.

To use a joystick, you will probably have to do something similar: open the USB port on the Linux side, read the data and do some pre-processing, and then forward that information over the bridge to your sketch.

jessemonroy650

@jessemonroy650 - /dev/ttyUSB0 is connected to the Atheros AR9331.  
1) Bridge can open it like a file?
2) How would I control the baud rate and parity?
3) The device in question is 500kbps 8N1.

I only need to pass through for debugging.  Once I'm done it will log data to SD card.
::::SNIP::::
aggrav8d,
You wrote:
I installed drivers on my YUN and now it recognizes a USB device plugged in as /dev/ttyUSB0.
For some reason it stuck in my mind you were talking about your machine (desktop/laptop) being a *nix box. It may be, it does not matter.

1) You can open the port, via the bridge, using a script or similar
2) You can control the port via the command line. Here is a reference document: http://wiki.openwrt.org/doc/recipes/serialbaudratespeed
3) Which device?

Your suggestion sounds seriously awkward. Could you please describe better what you want to do? And perhaps provide a drawing?

Lastly, to accomplish this task you'll need to use the shell (ash, the lesser brother of bash), or a script like, python or lua (both of which are installed), or any other on this list that needs to be installed, _OR_ if you have masochist tendencies you can use vi(1). ;)

I'm still getting the impression you're going about this the long way. But I don't have enough details.

Jesse

TyrrionLannister

Hi aggrav8d, I cant seem to install the drivers to detect the usb, can you please help?

Go Up