Read data from another Arduino via USB Host

I have seen similar posts but none of the answers seem to address my particular question.

I have a Moteino board acting as a gateway to collect sensor data. I can receive the data packet and print it on the serial monitor of the IDE in the format of "aaaaaaa,###".

    uint8_t buf[50];
    uint8_t len = sizeof(buf);
    memset(buf, '\0', sizeof(buf));

I want to pass the data packet to the Yun and log in a sqlite data base. If I were using the Atmega chip on the Yun to collect the data I would pass the data to python script.

If you 'other' arduino is so close that you can connect that one to the yun, why not replace the 'other' with the yun and connect the sensors to it straight away. One less step for the data to take, one less step prone to error...

The sensors are over 300' away and operate on 900Mhz. There is no power source at the sensor to operate the Yun, sensors operate on battery.

So the setup is
Sensor(s) -> rf link -> moteino board? Or are you planning on a 300' usb-cable?

In case of first, is the moteino able to connect to a lan? I'm not familiair with the board, but trying to get your setup clear...

Moteino is a transceiver board by low power labs based on Arduino.

Setup is:

Sensor->rf node->rf gateway->usb or serial to Yun.

Rf gateway has Tx and Rx pins open or can connect to Yun Usb host via micro USB.

or can connect to Yun Usb host via micro USB.

Is that micro USB port on the Yun or the Motenino board?

The micro-USB port on the Yun is strictly a USB device port (Serial, Keyboard, or Mouse emulation) and does not act as a host port. If you are connecting the Montenino board to the Yun's micro USB port, it will only work if the Motenino board acts as a USB host (which is very unlikely.)

The only USB host port on the Yun is the full size A connector, which is under the control of Linux. You will need to load the appropriate Linux serial port USB driver according to the type of USB interface that is on the Motenino board. To see which drivers are available to be loaded, run the Linux commands:

opkg update
opkg list | grep kmod-usb-serial

Is that micro USB port on the Yun or the Motenino board?

Moteino has USB micro. Yun acts as USB Host via the Linux side.

I'll give the drivers a look through, but not sure what I'm looking for.

Do you know any good examples (Python based) I could look at to learn how to pull data from the USB port once I get the drivers figured out?

I don't have any specific experience with that. But there are others here who have done it. A little time searching the forums should turn up some information. (Hint: the two main contexts I've seen are to talk to a Arduino Mega and to bypass the bridge and talk to the Yun's '32Yu4 over USB - that may give some hints on search terms.)

That should give some hints, but the driver you will need will likely be different. It appears your board might use an FTDI USB chip, so I would start with the driver that mentions FTDI.

Besides this forum, you can also do general searches about using USB serial with OpenWRT. (The OpenWRT site has lots of good information on a variety of topics, most of which are directly applicable yo the Yun.)

This guy has written a shell script (although he uses it for the RPI to get info from his solarpanels) but it reads from the USB host there. All comments are in English so maybe it can help you.

This page has a zip file containing a python script which does the same thing as the url above. Code comments are in Dutch though so maybe not so useful.

I think if you understand the basics it should be a relative simple job changing the code(s).
I would also recommend ShapeShifters comment and search the forum. There are a few examples on StackOverflow as well.

Good luck!

The list maker of USB serial adapter IC:

  • Cygnal Integrated Products, Inc. (Silicon Labs), CP21XX
  • QinHeng Electronics, CH34X
  • Arduino SA (Atmel/Microchip), Atmega16u2
  • Future Technology Devices International, Ltd, FT2XX
  • Prolific Technology, Inc, PL230X

The openwrt USB serial adapter driver list:

Find out USB serial adapter's Vendor ID/ Product ID:

root@Arduino:~# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 058f:6254 Alcor Micro Corp. USB Hub
Bus 001 Device 007: ID 2341:0042 Arduino SA Mega 2560 R3 (CDC ACM)
Bus 001 Device 005: ID 058f:6366 Alcor Micro Corp. Multi Flash Reader

Install driver:

opkg update 
opkg install kmod-usb-acm

Comfirm driver installed:

ls -al /dev/ttyACM0
crw-rw-rw-    1 root     root      166,   0 May  6 01:20 /dev/ttyACM0


Why Arduino and clone use wide range USB serial adapter IC?

The reason is price.

16U2: $1.23

16U2 costs 400% of CH340. PL230X is cheaper than CH340

Thanks to all for the help and suggestions.

The following solution worked for me incase anyone else has a similar project:

Python code on the Yun:

#--This code simply records the values from the sensor.

#--Serial FTDI driver for Yun
#--opkg update
#--opkg install kmod-usb-serial-ftdi
#--opkg install pyserial

import serial
import sqlite3 as sqlite
#import sys

#serial = serial.Serial("/dev/ttyUSB0", baudrate=115200, )
serial = serial.Serial('/dev/ttyUSB0', 115200, timeout=3) # Open the serial port at 115200

code = ''

while True:
	data =
	if data == '\r':
		(strdevice,strcount) = code.split(',',1)
		device = strdevice
		count = int(strcount)
		con = sqlite.connect('/mnt/sda1/sensor_flow_moteino.db')
		cur = con.cursor()
		cur.execute('''INSERT INTO data_log (device,count) VALUES(?,?)''',(device,count))
		code = ''
		code = code + data

Arduino based Gateway with FTDI to USB board:

#include <SPI.h>
#include <RH_RF95.h>
#include <LowPower.h>

#define FREQUENCY  	  915
#define LED           9 		// Moteinos have LEDs on D9
#define FLASH_SS      8 		// and FLASH SS on D8
#define BAUD_RATE     115200

// Singleton instance of the radio driver
RH_RF95 rf95;

//#define SERIAL_EN             // Uncomment when debugging
#ifdef  SERIAL_EN
#define DEBUG(input)   {Serial.print(input); delay(5);}
#define DEBUGln(input) {Serial.println(input); delay(5);}
#define DEBUG(input);
#define DEBUGln(input);

#define DEVICE    "Gateway"

void setup() 
  pinMode(LED, OUTPUT);
  if (!rf95.init())
    DEBUGln("init failed");  
    DEBUG(DEVICE); DEBUG("_initialized- "); DEBUG(FREQUENCY); DEBUGln("mhz"); 

void loop()
  if (rf95.available())
    // Should be a message for us now   
    uint8_t buf[50];
    uint8_t len = sizeof(buf);
    memset(buf, '\0', sizeof(buf));

    if (rf95.recv(buf, &len))
      digitalWrite(LED, HIGH);
      //RH_RF95::printBuffer("request: ", buf, len);
      DEBUG("got request: ");
      DEBUG("RSSI: ");
      DEBUGln((rf95.lastRssi(), DEC));
      digitalWrite(LED, LOW);

Python code on the Yun:


#--This code simply records the values from the sensor.

#--Serial FTDI driver for Yun
#--opkg update
#--opkg install kmod-usb-serial-ftdi
#--opkg install pyserial

A very nice touch including comments describing the installation of the prerequisite software! 8)

I try to do that, but I wish I could remember to do it ALL the time. It sure would make it easier to get stuff working again on a new board, after I forgot all of the steps that it took to get there...