A tiny USB device called OpenUI that adds an IR remote receiver, LCD display, RTC, and I2C bus to any headless Linux box — built around an ATtiny2313 acting as a USB HID device.
The problem
For most embedded applications, micro-controllers work well for their low cost and simplicity. But as soon as you need networking on an MMU-less processor, hardware becomes expensive and complex — you need a processor with an MMU and an OS for basic networking and file management.
Technology enthusiasts, hardware hackers, and DIYers find it difficult to use PC-like motherboards that are expensive, bulky, and power-hungry for tiny embedded needs. Over the past few years, we've seen the DIY community shift from micro-controller-based hardware to Linux single-board computers. The mobile market is driving semiconductor companies to build low-cost yet powerful SoCs capable of running Linux at the $5–$10 price range.
For hobbyists this is great news — cheap commercial products running open-source Linux are everywhere. But most of these devices are headless, with no keyboard or display, and lack GPIO, I2C, or UART interfaces needed for sensors, motors, and controls.
To bridge the gap between an off-the-shelf Linux box and the missing I/O interface, I built OpenUI — a USB device using Atmel's ATtiny2313 as a USB HID device. Since most Linux boxes have a USB port, an OpenUI add-on makes sense for anyone planning to use cheap Linux boxes for embedded projects.
Features
- IR remote receiver — acts as a user input device (keyboard)
- 16x2 LCD — acts as a user output device (display)
- I2C bus interface — for connecting peripheral chips
- I2C RTC chip — real-time clock with battery backup
- 5x2 male header — for AVR programming or extending the I2C bus
- 5V power — drawn from the host USB connector
Hardware design is based on Dick Streefland's usbtiny project. The only limitation of usbtiny is a missing I2C bus — OpenUI extends the design with an all-in-one solution for headless Linux boxes.
Building the ATtiny2313 firmware
Step 1 — Install the AVR toolchain:
sudo apt-get install gcc-avr binutils-avr avr-libc avrdude
Step 2 — Prepare a cheap AVR programmer (ponyser) from here.
Step 3 — Download Dick Streefland's usbtiny-1.6 sources and the OpenUI patch.
Step 4 — Build and flash:
mkdir openUI cd openUI cp /path/to/downloaded/usbtiny-1.6.tar.gz . cp /path/to/downloaded/usbtiny-1.6.openui-0.1.diff . tar -xvf usbtiny-1.6.tar.gz cd usbtiny-1.6 patch -p1 < ../usbtiny-1.6.openui-0.1.diff make clean make all cd ir avrdude -p attiny2313 -P /dev/ttyUSB0 -c ponyser -U flash:w:main.hex avrdude -p attiny2313 -P /dev/ttyUSB0 -c ponyser -U hfuse:w:0xdb:m avrdude -p attiny2313 -P /dev/ttyUSB0 -c ponyser -U lfuse:w:0xef:m
Your ATtiny2313 is now ready to run on the OpenUI hardware.
Preparing the headless Linux box
- Build
lircdalong withlirc_dev.koandlirc_igorplugusb.kofor your Linux box. - Load the kernel modules before starting lircd.
- Verify
/dev/lircdevice node exists. - Verify
/var/run/lircfolder exists. - Start lircd:
/usr/sbin/lircd --device=/dev/lirc /etc/lirc/lircd.conf
- Start the OpenUI daemon:
/path/to/openui &
If everything goes well, you'll see a message on the OpenUI's LCD.
Hardware photos
See OpenUI in action in the companion blog post.
6 comments:
Hello. This looks like almost exactly what I need.
But you do not seem to explain much at all about how it actually works (even to a seasoned electronics hobbyist.)
The thing I most don't understand is how you are able to control an HID (usually input only, right?) device connected to an unmodified Linux router (headless linux machine.)
In other words, could you please explain how data gets from the TCP/IP network to the USB port connected HID device, plugged into the back of the router? Right now, that just doesn't make any sense (to me) at all.
Thanks! :-D
Re my previous comment ... you did say in either this or a related article that you did not void the warranty on the TP-Link router. That implied to me that you did not put custom firmware on it. But I'm now guessing that you in fact did have to do that and that this is the major chunk of information that I am missing. So then, do you have an article or link to information about how to perform that part -- the custom linux for the router part -- especially the bit about compiling your own modules etc, as you seem to imply here? Again, many thanks. :-D
Gruvin:
Even if you update tp-link with open source firmware(openwrt), you still can revert back to original OEM firmware. In my case, I downloaded the openwrt distribution, and built if for tp-link MR3220/3240. After building openwrt, all you need is to install lirc daemon with igorplugusb driver(yes.. I missed to give details of including lirc stuff with openwrt - may be later i will publish the details). But at this moment, this gives you an idea of using IR and I2C in linux environment.
Thanks for that. I have since purchased a TP-Link router, installed OpenWRT and successfully compiled custom C test program for it -- as well as installed customer test web pages for GPIO control. There seems much potential here at a very good price for a WiFi connected device. Thank you. :-D
Very well explained with real examples. I had many confusions in mind but now I’m clear about this and will give it a try now.
Post a Comment