Reading Serial Data from USB host

Hi, I’m new in Arduino Yun.

I’m trying to connect and Arduino YUN and a USB Serial device. It can be, as an example, an Arduino UNO. I connect my UNO to USB host from YUN.

YUN (USB HOST) <—> ARDUINO UNO

How can I read from YUN data sent by UNO? Need a phyton script that “listen” the usb?

Regards,
Seba.-

Yes you can do that with python. See http://playground.arduino.cc/Interfacing/Python

Great! I just need to figure out how to install all that . lol..

Regards, Seba.

I connect my yun to a Arduino mega You may be interested in this blog article :http://blog.baeyens.it/#post11 Best regards Jantje

I still can´t do this.

Steps: 1) I use sd to extend YUN space with: http://arduino.cc/en/Tutorial/ExpandingYunDiskSpace 2) I download pyserial-2.7.tar.gz from https://pypi.python.org/pypi/pyserial 3) Unzip folder with 7zip. 4) I install "Ssfhs Manager" to transfer files but it crashed every time.

How and where I copy that folder?

Regards.

opkg update
opkg list |grep pyserial
opkg install pyserial

As sonnyyu said, pyserial is one of the available packages for the Yun. BTW there are more than 3000 of them, chances are what you need is ready to be installed. And if it's not, request it on github [1]

[1] https://github.com/arduino/openwrt-packages-yun/issues

Plan B:

opkg update
opkg install python-openssl #adds ssl support to python
opkg install distribute #it contains the easy_install command line tool (this can take some time)
easy_install pip #installs pip  (this can take some time)
#opkg remove pyserial
pip install pyserial

Plan C:

#pip uninstall pyserial
easy_install pyserial

Plan D:

#easy_install -m  pyserial #remove it 
cd /mnt/sda1
wget https://pypi.python.org/packages/source/p/pyserial/pyserial-2.7.tar.gz#md5=794506184df83ef2290de0d18803dd11
tar zxf pyserial-2.7.tar.gz
cd pyserial-2.7
python setup.py install

This allow you install latest version of pyserial-2.7 or the version you like!

Backup plan:

There are 2 type python entensions, one is ctypes, one is c-api.

pyserial is ctypes, could be easily installed.

for c-api extension GCC is needed for compile c library.

Native GCC for Yun

http://forum.arduino.cc/index.php?topic=241368.0

lordk I hope you've been successful in running opkg install pyserial as it is the easiest way of the many described so far. Did you?

Yes, I use “Plan D”., but I change:

wget --no-check-certificate https://pypi.python.org/packages/source/p/pyserial/pyserial-2.7.tar.gz#md5=794506184df83ef2290de0d18803dd11

For new linux user like me you need to install “wget” and “tar” with:

opkg update
opkg install wget
opkg install tar

Then I have trouble with /dev/ttyxxx till I realised that I need to install FTDI drivers.

Useful links:
http://smartcity.cs.columbia.edu/openwrt/openwrt_packages.php

Regards.

Did the opkg version fail? By the commands you used it looks like you're using the old image. Please upgrade it ASAP following the link in my signature. A list of improvements in available in the sticky topic "Please upgrade your Yun" http://forum.arduino.cc/index.php?topic=235360.0

Thanks Federico, I have updated my YUN now.

I´m lost in doing the reading. I read these post but cant make it work. http://forum.arduino.cc/index.php?topic=219602.0 -> use picocom http://forum.arduino.cc/index.php?topic=201500.0 -> a post u reply

Only a few times it works. I commented line of ttyATH0::askfirst:/bin/ash --login on /etc/inittab

YUN Code (YUNSerialTerminal mod)

long linuxBaud = 9600;

void setup() {
  Serial.begin(115200);      // open serial connection via USB-Serial
  Serial1.begin(linuxBaud); // open serial connection to Linux

}
void loop() {
 // copy from virtual serial line to uart and vice versa
  if (Serial.available()) {           // got anything from USB-Serial?
     char c = (char)Serial.read();     // read from USB-serial
      Serial.print("Char: ");  
      Serial.println(c);
      Serial1.print(c);             //    otherwise write char to Linux
      }
 }

Python Code

import serial
ser = serial.Serial ('/dev/ttyATH0',9600 )
while True:
         print ser.readline()

Is this the best way of doing this? Regards.

The problem is you are trying to use ttyATH0 which is in use by Yuns bridge implementation. Try using another port or modify inittab.

It depends on the device you're plugging to the you, but you'll need additional kernel modules for talking to another Arduino (say a UNO) plugged to the yun. Try

opkg update
opkg install kmod-usb-acm

Federico,

the linino(UBS host) <-> FDTI is working. I can read in the python console the Strings coming up from the FTDI, what I cant make it work is the Arduino<-> linino communication.-

edit: Commenting the line in inittab seems to work. Can I change the serial1 port as MAMU suggested so I leave inittab as default??

lordk: edit: Commenting the line in inittab seems to work. Can I change the serial1 port as MAMU suggested so I leave inittab as default??

Sadly, no.

It has to be a easy way to send data from linino to ATmega without mixing data.