Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install Arduino Yun (Linino) software on OpenWrt on 3rd-party devices. TODO: Fully automate install and/or use Linino rootfs image and/or build own firmware using OpenWrt Image Generator. CAVEATS: I have not yet found out how to make the Bridge use Serial (USB) instead of Serial1 (HardwareSerial) for the Leonardo. I have asked a question about t…
opkg install luci-lib-json luci rng-tools usbutils avrdude avahi-daemon
# If rng-tools is not installable, then install it by hand from e.g.,
# Edit your /etc/opkg.conf, add
src/gz barrier_breaker
# Comment out your earlier src/gz
opkg update
opkg list|grep bridge
opkg list|grep yun
opkg install -force-overwrite cpu-mcu-bridge yun-conf yun-scripts luci-app-arduino-webpanel gnupg temboo spacebrew uSDaemon
# When no yun shows up in the Arduino IDE, might need to restart avahi-daemon
/etc/init.d/avahi-daemon start
# Need to edit in order to change to correct LED
rm /tmp/luci-indexcache
# In /etc/avahi/avahi-daemon.conf edit
# Important; otherwise Arduino IDE will not find the device
chmod a+r /etc/avahi/services/arduino.service
/etc/init.d/avahi-daemon enable
/etc/init.d/avahi-daemon start
/etc/init.d/generate_new_gpg_key start
# Works only if rngd is there, generates
# Apparently Yun uses avrdude linuxgpio, this is suggested by /etc/linino/
# run-avrdude wants to edit sys/class/gpio/gpio21/value which does not exist here
# Also see
# It has modified files for the Arduino IDE and it has the GPG key and gpg binary
# They have also a modified /usr/bin/run-avrdude script which is pure genius, it changes linuxgpio to serial programming and if that is all that is required to change makes it trivial to hook up different boards via USB as well. I have modified it to launch login on ttyACM0 so that Bridge can be launched by the sketch connected to ttyACM0.
# Now launch login on ttyACM0 so that Bridge can be launched by the sketch connected to ttyACM0
/sbin/askfirst ttyACM0 /bin/ash --login
Here is how the Bridge gets launched:
Arduino sends enter, then "run-bridge" on the serial port that it is connected to; expecting a login shell there. It appears to me that this is dangerous, since the Arduino has a root shell at its serial port (that we open with "/sbin/askfirst ttyACM0 /bin/ash --login"). Wouldn't it be more sensible to just launch the bridge on the serial port rather than a login shell?
Here is how the Serial Monitor (probably) gets launched:
Arduino IDE connects to root@arduino.local. and runs "ash -c telnet localhost 6571"
In the sketch, just change from "Serial" and use "Console" instead if you want to write to the Serial Monitor. See the ConsoleRead example in the Bridge examples. "Serial" is the serial port on the Arduino while Console is the USB connection going to the Arudino.
# Need at least(possibly more) selected parts from full python
# for /usr/bin/run-bridge
root@Yun:~# cp /tmp/usr/lib/python2.7/ /usr/lib/python2.7/
root@Yun:~# cp /tmp/usr/lib/python2.7/ /usr/lib/python2.7/
root@Yun:~# cp /tmp/usr/lib/python2.7/ //usr/lib/python2.7/
# kmod-fs-hfsplus and kmod-nls-utf8 sufficient to mount Mac devices?
For my own reference, these are the packages that come with the YUN according to
luci-lib-sys kmod-usb-storage terminfo libuci-lua libc opkg triggerhappy kmod-usb-core libpthread ubus iw kmod-crypto-manager luci-mod-admin-core busybox libubus-lua python-json kmod-crypto-hash libiwinfo-lua swconfig kmod-fs-reiserfs libiwinfo libdbus libcurl libdw kmod-lib-crc-ccitt libgpgme luci-theme-openwrt luci-theme-bootstrap kmod-pppoe kmod-video-core libavahi-client kmod-pppox kmod-ipt-conntrack kmod-lib-crc16 base-files kmod-fs-hfsplus netifd uboot-envtools kmod-usb-ohci dnsmasq usbutils luci-sgi-cgi libblkid ubusd libelf1 kmod-spi-gpio python kmod-i2c-core libgpg-error block-mount kmod-fs-vfat kmod-usb2 firewall luci-app-firewall kmod-fs-hfs temboo luci-lib-ipkg libuci liblua libip4tc avahi-dnsconfd libcyassl libdaemon kmod-ath9k libavahi uci lua kmod-fs-ext4 wpad-mini dbus dropbear kmod-ledtrig-timer curl kmod-nls-utf8 kmod-crypto-aes mtd libstdcpp kmod-crypto-core luci-theme-base libjson-c libgcc libreadline libip6tc luci-proto-ppp libffi libuuid luci-mod-admin-full ppp libubox kmod-leds-gpio libusb-1.0 kmod-gpio-button-hotplug gnupg libjson cpu-mcu-bridge luci-lib-web spacebrew librt libassuan kmod-mac80211 libjson-script swap-utils libblobmsg-json iptables hotplug2 kmod-ipt-nathelper kmod-fs-ntfs kmod-fuse jshn libncurses kmod-ipt-core luci-webpanel-linino kmod-ledtrig-default-on rng-tools libpolarssl kmod-ppp kmod-spi-bitbang avahi-daemon uhttpd-mod-lua python-mini kmod-wdt-ath79 avahi-utils libubus uhttpd libxtables avrdude zlib luci-lib-nixio luci-lib-json luci kmod-spi-tty-ds kmod-ath libexpat kernel libnl-tiny libbz2 blkid libusb luci-proto-core px5g kmod-nls-base luci-i18n-english libgdbm yun-scripts libusb-compat uhttpd-mod-ubus uSDaemon wireless-tools kmod-ath9k-common kmod-crypto-arc4 libopenssl kmod-scsi-core kmod-cfg80211 libavahi-dbus-support luci-lib-core ppp-mod-pppoe kmod-spi-dev kmod-ipt-nat kmod-ledtrig-netdev
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<name replace-wildcards="yes">%h</name>
</service-group> Leonardo
diff -Naur /Users/newuser/Downloads/Arduino Yun /Users/newuser/Downloads/Arduino Yun
--- /Users/newuser/Downloads/Arduino Yun 2014-02-21 18:07:50.000000000 +0100
+++ /Users/newuser/Downloads/Arduino Yun 2014-01-15 02:58:55.000000000 +0100
@@ -243,6 +243,17 @@
#ifdef __AVR_ATmega32U4__
// Leonardo variants (where HardwareSerial is Serial1)
SerialBridgeClass Bridge(Serial1);
+#elif defined(__AVR_ATmega2560__)
+//Arduino mega,use Serial1,not default Serial0
+SerialBridgeClass Bridge(Serial1);
+#if defined(USART1_RX_vect)
+//has Serial1
+SerialBridgeClass Bridge(Serial1);
+#ifndef skiponeserial
+#error Your Arduino just have one serial(like UNO),if you want to use the default serial as a bridge,define skiponeserial in the first line.
SerialBridgeClass Bridge(Serial);
diff -Naur /Users/newuser/Downloads/Arduino Yun /Users/newuser/Downloads/Arduino Yun
--- /Users/newuser/Downloads/Arduino Yun 2014-02-21 18:07:50.000000000 +0100
+++ /Users/newuser/Downloads/Arduino Yun 2014-01-14 16:28:51.000000000 +0100
@@ -96,7 +96,7 @@
// Empty
- void begin(unsigned long baudrate = 250000) {
+ void begin(unsigned long baudrate = 115200) {
import sys
import serial
ser = serial.Serial(sys.argv[1], 1200)
#echo 1 > /sys/class/gpio/gpio21/value
#avrdude -c linuxgpio -C /etc/avrdude.conf -p m32u4 -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xFB:m -Uflash:w:$1:i $2
#echo 0 > /sys/class/gpio/gpio21/value
#echo "$2" > /s2
echo "" > /dev/ttyACM0
lsusb|grep 0036
if [ "$?"x == "0"x ];then
reset-arduino /dev/ttyACM0
avrdude -V -p atmega32u4 -c avr109 -b 57600 -P /dev/ttyACM0 -C /etc/avrdude.conf -U flash:w:$1 $2
lsusb|grep 0043
if [ "$?"x == "0"x ];then
echo UNO
avrdude -V -p m328p -c arduino -b 115200 -P /dev/ttyACM0 -C /etc/avrdude.conf -U flash:w:$1 $2
lsusb|grep 0042
if [ "$?"x == "0"x ];then
echo MEGA
avrdude -V -C/etc/avrdude.conf -patmega2560 -cstk500v2 -P/dev/ttyACM0 -b115200 -D -Uflash:w:$1 $2
echo "" > /dev/ttyACM0
# Enable every sketch to communicate with IDE (without the Bridge)
# ser2net -C 6571:raw:0:/dev/ttyACM0:9600
# Enable Bridge
/sbin/askfirst ttyACM0 /bin/ash --login &
Copy link

ffissore commented Mar 30, 2014

GPG is used by the webpanel to encrypt sensitive information (your password and your wifi credential). This is necessary since a typical user will connect using plain http (not being aware of the fact that the yun webserver support https) thus creating a potential security breach.

Copy link

probonopd commented Mar 30, 2014

Sounds like the web service should ONLY be provided over https, and http requests should be forwarded to https?

Copy link

sangood commented Jun 7, 2014

run-avrdude line 25 maybe:
avrdude -V -C /etc/avrdude.conf -p atmega2560 -c stk500v2 -P /dev/ttyACM0 -b 115200 -D -U flash:w:$1 $2

Copy link

sangood commented Jun 9, 2014

hello,can you tell me why my 703n openwrt can't find /sbin/askfirst ?

Copy link

fredericplante commented Sep 28, 2014

Nice script and all, but I got a Easylink M-mini AR9331 module, basicaly the same chip set as Yun, and I would like to know where to begin? Do I have to download some thing first? Where is that file, if so? Thank you for your help.

By the way, i'm totaly new at this. ;)

Copy link

hagope commented Oct 29, 2014

Any idea on how to use SPI for a 3rd party OpenWRT device without the MCU/Bridge? For example, driving a graphics LCD use u8glib.

Copy link

probonopd commented Dec 23, 2014

See probonopd/poor-mans-yun#2 (Dragino patches to support different Arduino models)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment