Micro-USB port as general purpose USB slave

Hi

Can the micro-USB port on the Yun be used as general purpose slave port? I have a requirement that needs 2x slaves and a single host. I can use the OpenWRT host port or a USB host shield for the host but I'm struggling to get 2xslaves.

Thanks

graham999au:
Hi

Can the micro-USB port on the Yun be used as general purpose slave port? I have a requirement that needs 2x slaves and a single host. I can use the OpenWRT host port or a USB host shield for the host but I'm struggling to get 2xslaves.

Thanks

The micro-USB port on the Yun is on ATmega32u4 side, it is not what you want? detail your application?

I'm building an interface between a PC and ham radio. The PC is running two different applications, each using separate USB ports. The Yun needs to read commands from these apps and pass them to the radio, then read the responses from the radio and send them back to the appropriate app. Some commands do not need to be passed through, hence using the arduino side to control the data flow.

The radio has a silicon labs USB interface. I can use the USB host on the Linux side to talk to that and pass the data over the bridge to the arduino. My issue is trying to get the PC interfaces working. I could use 2 x RS232 shields with corresponding USB-serial cables but was hoping to use the micro-USB instead of one of these.

Load Silicon Labs driver:

kmod-usb-serial-cp210x

10c4 Cygnal Integrated Products, Inc. (Silicon Labs)

http://www.ibuyopenwrt.com/index.php/8-yun-compatible/118-usb-serial-adapters

2xUSB serial adapter+ Dragino Yun shield + arduino mega

USB serial adapter cost few $.

I would still need 2 x RS232 shields as well?

@graham999au,

I'm confused. The Linux side is the Atheros AR9331. The Arduino side is the Atmel ATmega32u4.

What is the ATmega32u4 doing for this radio setup?

Is a USB hub possible?

Jesse

graham999au:
I would still need 2 x RS232 shields as well?

No. 2xUSB serial adapter will be replace them.

jessemonroy650:
@graham999au,

I'm confused. The Linux side is the Atheros AR9331. The Arduino side is the Atmel ATmega32u4.

What is the ATmega32u4 doing for this radio setup?

Is a USB hub possible?

Jesse

The 32u4 would be needed for the 2x rs232 shields which have USB-serial cables going to the PC. A USB hub doesn't help as I need to control the command flow between the 2 apps on the PC and the radio.

sonnyyu:
No. 2xUSB serial adapter will be replace them.

I don't see how the serial adapters replace them? I still need 2 USB serial connections to the PC and assume they would be via rs232-USB cables.

Let me get this straight: it sounds like you need three USB interfaces:

  • a host port for the radio
  • a serial device port to talk to one application
  • a serial device port to talk to another application

You could use a USB host shield for port 1, but it would be easier and cheaper to use the large USB host port that is attached to the Linux side.

The built in micro USB port can be used for a variety of purposes: by default it acts as a serial device, so you've got port 2 right there. (It can also act as other devices, like a keyboard or mouse, but I don't think that helps you.

That leaves port 3. The simplest solution, rather than an RS-232 shield, then an RS-232 USB converter would be a TTL serial to USB converter, something like this: USB to TTL Serial Cable - CAB-12977 - SparkFun Electronics. Ignore the red power pin, don't connect it. Hook up ground, and Tx/Rx to two I/O pins and use SoftwareSerial.

ShapeShifter:
Let me get this straight: it sounds like you need three USB interfaces:

  • a host port for the radio
  • a serial device port to talk to one application
  • a serial device port to talk to another application

You could use a USB host shield for port 1, but it would be easier and cheaper to use the large USB host port that is attached to the Linux side.

The built in micro USB port can be used for a variety of purposes: by default it acts as a serial device, so you've got port 2 right there. (It can also act as other devices, like a keyboard or mouse, but I don't think that helps you.

That leaves port 3. The simplest solution, rather than an RS-232 shield, then an RS-232 USB converter would be a TTL serial to USB converter, something like this: USB to TTL Serial Cable - CAB-12977 - SparkFun Electronics. Ignore the red power pin, don't connect it. Hook up ground, and Tx/Rx to two I/O pins and use SoftwareSerial.

Brilliant this is exactly what I'm doing and what I'm after. I intend to use the USB host port on the Linux side to talk to the radio as you suggested. Can SoftwareSerial handle multiple serial ports? Can you be more specific on how I connect and use the micro USB?

graham999au:
...
Can SoftwareSerial handle multiple serial ports?
...

Here you only need one SoftwareSerial, since an other one is HardwareSerial. But if you search this forum SoftwareSerial with Yun might not be easy.

My solution is two HardwareSerial:

2xUSB serial adapter+ Dragino Yun shield + arduino mega.

USB serial adapter

Male to Female DuPont Wire

graham999au:
Can SoftwareSerial handle multiple serial ports?

Yes, with restrictions: it can only receive from one port at a time. But that's not a limitation here, as you only need to run one instance of SoftwareSerial, connected to the USB to TTL serial adapter.

Study the SoftwareSerial documentation, and take note of the restriction on which pins can be used with a Leonardo: the Yun uses the same processor as the Leonardo, so the same restriction exists.

Can you be more specific on how I connect and use the micro USB?

Just plug it into your computer, and not the serial port number (it will be the same port that appears in the Arduino IDE. Use that port number for your application. Use the Serial class in the sketch.

It's exactly like using the Serial class with the Arduino IDE's SerialMonitor. The only difference is that your application is connecting to the virtual USB serial port, not the SerialMonitor.

Plan B:

By pass Arduino completed. Replace AR9331 with CPU which has more than one UART port, such like MT7628 which has 2 UART ports.

@graham999au,
I'm still confused. This is likely because I am NOT a hardware person. I am a software person that does embedded systems (and not full time). As such let me take ShapeShifter's evaluation and start there.

ShapeShifter:
Let me get this straight: it sounds like you need three USB interfaces:

  • a host port for the radio
  • a serial device port to talk to one application
  • a serial device port to talk to another application

::::SNIP::::

What do the two applications do? Please add some detail.

For as I see it (as a sofware person), these two applications should be merge, replaced or eliminated.

For instance, many times software applications don't do anything more than run a heuristic logic flows for hardware operations. That is to say, they have a fixed set of routines or logic paths that can be exchanged. But then again, maybe these applications you are using don't do that.

Again, can you describe what these applications do?

TIA
Jesse

jessemonroy650:
For as I see it (as a sofware person), these two applications should be merge, replaced or eliminated.

I would agree. But I'm assuming that they are existing (commercial?) applications, where merging them is not possible and rewriting them (probably from scratch) is not practical?

From the description, I'm picturing two distinct applications that need to share some hardware, and the Yun is acting as the arbitrator and steering the appropriate data to the appropriate application. But that's just a guess.

sonnyyu:
My solution is two HardwareSerial:

2xUSB serial adapter+ Dragino Yun shield + arduino mega.

Your suggestion is very good. Using hardware serial would be my preferred solution.

ShapeShifter:
Yes, with restrictions: it can only receive from one port at a time. But that's not a limitation here, as you only need to run one instance of SoftwareSerial, connected to the USB to TTL serial adapter.

Study the SoftwareSerial documentation, and take note of the restriction on which pins can be used with a Leonardo: the Yun uses the same processor as the Leonardo, so the same restriction exists.

Excellent that all makes sense thank you.

jessemonroy650:
@graham999au,
I'm still confused. This is likely because I am NOT a hardware person. I am a software person that does embedded systems (and not full time). As such let me take ShapeShifter's evaluation and start there.

What do the two applications do? Please add some detail.

For as I see it (as a sofware person), these two applications should be merge, replaced or eliminated.

For instance, many times software applications don't do anything more than run a heuristic logic flows for hardware operations. That is to say, they have a fixed set of routines or logic paths that can be exchanged. But then again, maybe these applications you are using don't do that.

Again, can you describe what these applications do?

TIA
Jesse

I have no control over the apps as they are commercial. I wish I could as I am also a software engineer!

My final question. I assume the Bridge will be too slow to transfer data at 9600 baud between the Linux and arduino so what is my best alternative? I was hoping SPI but not sure this works as I heard there was a bug. I read I could use /dev/ttyATH0 and Serial1 which I think might be fast enough?

graham999au:
My final question. I assume the Bridge will be too slow to transfer data at 9600 baud between the Linux and arduino so what is my best alternative? I was hoping SPI but not sure this works as I heard there was a bug. I read I could use /dev/ttyATH0 and Serial1 which I think might be fast enough?

Plan B:

Bypass Arduino. Run everything at Linux side.

AR9331 (Yun) one UART
AR9341 One low-speed UART (115 Kbps), one highspeed UART (3 Mbps)
AR9344 One low-speed UART (115 Kbps), one highspeed UART (3 Mbps)
QCA9558 One low-speed UART (115 Kbps), one highspeed UART (3 Mbps)
MT7628 two UART
MT7688 three UART

http://forum.arduino.cc/index.php?topic=338827.msg2342748#msg2342748

ShapeShifter:
It's exactly like using the Serial class with the Arduino IDE's SerialMonitor. The only difference is that your application is connecting to the virtual USB serial port, not the SerialMonitor.

I am unable to get the micro USB working, it just hangs on Serial.begin(9600). My Yun is connected to the IDE via WiFi. I have made no changes to any config files on the OpenWrt side.

Here's my code:

#include <Bridge.h>
#include <Console.h>

String readString;

void setup() {
  
  // Bridge startup
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);

  Bridge.begin();
  
  digitalWrite(13, HIGH);

  Console.begin();
  while (!Console);
  Console.println("Started....");

  Serial.begin(9600);
  while (!Serial);
  
  Console.println("Listening...");
}

void loop() {
  String Command;
  
  // check for Serial commands and send to Console
  while (Serial.available()) {
    delay(3);  //delay to allow buffer to fill 
    if (Serial.available() > 0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    } 
  }

  if (readString.length() > 0) {
    Console.print(readString);
    readString = "";
  }
  
  // check for Console commands and send to Serial
  while (Console.available()) {
    delay(3);  //delay to allow buffer to fill 
    if (Console.available() > 0) {
      char c = Console.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    } 
  }

  if (readString.length() > 0) {
    Console.print(readString);
      Serial.print(readString);
    readString = "";
  }
  
  delay(50);
}