Go Down

Topic: Reading Serial Data from USB host (Read 9415 times) previous topic - next topic

lordk

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

federicofissore


lordk

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

Regards,
Seba.

Jantje

I connect my yun to a Arduino mega
You may be interested in this blog article :http://blog.baeyens.it/#post11
Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

lordk

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.

sonnyyu

Code: [Select]
opkg update
opkg list |grep pyserial
opkg install pyserial



federicofissore

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

sonnyyu

#7
Jun 12, 2014, 03:01 pm Last Edit: Jun 12, 2014, 03:29 pm by sonnyyu Reason: 1
Plan B:

Code: [Select]
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)


Code: [Select]
#opkg remove pyserial
pip install pyserial

sonnyyu

Plan C:

Code: [Select]
#pip uninstall pyserial
easy_install pyserial

sonnyyu

Plan D:

Code: [Select]
#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!

sonnyyu

#10
Jun 12, 2014, 03:27 pm Last Edit: Jun 12, 2014, 03:44 pm by sonnyyu Reason: 1
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

federicofissore

#11
Jun 13, 2014, 09:36 am Last Edit: Jun 13, 2014, 09:38 am by Federico Fissore Reason: 1
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?

lordk

Yes, I use "Plan D"., but I change:
Code: [Select]
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:
Code: [Select]
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
http://forum.arduino.cc/index.php?topic=210269.0

Regards.

federicofissore

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

lordk

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)
Code: [Select]

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
Code: [Select]
import serial
ser = serial.Serial ('/dev/ttyATH0',9600 )
while True:
         print ser.readline()



Is this the best way of doing this?
Regards.

Go Up