Go Down

Topic: Use Yun bridge without a Yun? (Read 2186 times) previous topic - next topic

gorstj

Is it possible to use an 'standard' Arduino (e.g. Uno) connected to a Linux computer via USB (as two of my projects already are) and make use of a Yun type bridge?

What I am really asking is, has/is anyone porting the Yun Linux side software so it is installable on a standard Linux PC?

sudar

Technically it is possible to do it, but practically you might face some problems.

Also, it would be easier to try with Arduino Leonardo first instead of Uno, since the AVR part in YUN is more similar to Leonardo than Uno.

PeterVH

#2
Oct 16, 2013, 10:31 pm Last Edit: Oct 16, 2013, 10:42 pm by PeterVH Reason: 1
I would not be surprised if the developers used a regular arduino and a pc to develop the bridge.

I gave it a try with a Duemilanove (I have no Uno) and a Leonardo.

When compiled for the Leonardo, the bridge library uses Serial1 (the uart), so you have to hook up a serial to usb converter to the tx (1) and rx (0) pins. Communication with the bridge goes via this extra converter. But the upside is that you have Serial free for println debugging.

When compiled for the Duemilanove, the bridge library automatically uses Serial, so communication goes via the (only) usb cable.

As suggested elsewhere in this forum I added the possibility to start the bridge with a specified baudrate. In Bridge.h I made this change:
Code: [Select]
class SerialBridgeClass : public BridgeClass {
...
 void begin(unsigned long baud = 250000) {
   serial.begin(baud);
   BridgeClass::begin();
 }

I feel more comfortable with 115200 as baudrate, so in the ConsoleRead sketch:
Code: [Select]

Bridge.begin(115200);


Upload e.g. the ConsoleRead sketch to the Duemilanove, Leonardo....

The bridge library does not set the baud rate, so you should do that yourself:
Code: [Select]
stty -F /dev/ttyUSB0 115200

Get the YunBrigde source from Arduino's git hub repository.

The avr on the Yun fires up the bridge on linino by itself, but for experimentation on the pc you can just start it manually. e.g. for the Duemilanove:
Code: [Select]
python bridge.py </dev/ttyUSB0 >/dev/ttyUSB0

The bridge  will try to run the scripst /usr/bin/blink-start and /usr/bin/blink-stop. You might comment this out in packet.py, but I just installed two dummy scripts on my pc and made them executable:
Code: [Select]
#!/bin/sh
echo "$0" 1>&2


In the scripts, make sure not to echo stuff (for debugging) on stdout because it will be sent to the arduino, messing up the bridge communictaion. That is what the 1>&2 is for: it makes sure echo's output ends up on stderr. Likewise if you want to do 'printf debugging' from the python scripts, don't use print, but use:
Code: [Select]

from sys import stderr
...
stderr.write("some string\n").


The arduino may kick out the  python script by sending it the 'XXXXX' command. Just start it again or ignore the command in bridge.py.

Now, in another terminal window, say telnet localhost 6571 and you should see 'Hi, what's your name?'

I did not yet manage to make it run smoothly though. If I type my name, it takes several seconds till I see 'Hi peter! Nice to meet you!'
It looks as if for every send from the arduino to the pc, there is a latency of a second or so. I want to figure out where this comes from...I have no Yun, so I don't know whether it runs smoother on a Yun. I see no reason why it would. On the Yun, there is no usb to serial converter involved but that should not be a bottle neck?. Maybe I did not yet find the magic stty settings?.

federicofissore

On a side note, the Bridge contained in the nightly builds on the IDE (they will become version 1.5.5) is already patched
http://arduino.cc/en/Main/Software#toc4

PeterVH

Ok, I did a git pull and ran from there.

Note that the overloaded function SerialBridgeClass::begin(int baud) in the new code is wrong, the baud rate must be an unsigned long for baudrates like 115200 to work. Adding just an optional baud argument like in my code snippet works also and is backward compatible too.

I observed not behavioural differences. On the Leonardo it works a bit faster than on the Duemilanove. As said, I will  try to figure out where the latencies come from. Does this run smoothly on the Yun?


cow77

#5
Oct 17, 2013, 10:45 pm Last Edit: Oct 17, 2013, 10:48 pm by cow77 Reason: 1
Your right: should be a long.

Syntax
Serial.begin(speed)

Parameters
speed: in bits per second (baud) - long

federicofissore


Go Up