Monday, January 09, 2012

OpenUI: IR Remote, LCD & I2C for Headless Linux

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.

OpenUI schematic

OpenUI schematic — ATtiny2313 with USB, IR receiver, LCD, RTC, and I2C expansion.

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

  1. Build lircd along with lirc_dev.ko and lirc_igorplugusb.ko for your Linux box.
  2. Load the kernel modules before starting lircd.
  3. Verify /dev/lirc device node exists.
  4. Verify /var/run/lirc folder exists.
  5. Start lircd:
/usr/sbin/lircd --device=/dev/lirc /etc/lirc/lircd.conf
  1. Start the OpenUI daemon:
/path/to/openui &

If everything goes well, you'll see a message on the OpenUI's LCD.

Hardware photos

OpenUI board top view

OpenUI board — top view showing the ATtiny2313, IR receiver, and I2C header.

OpenUI board with LCD

OpenUI with 16x2 LCD display mounted.

OpenUI board close-up

Close-up of the OpenUI board.

OpenUI connected to router

OpenUI plugged into a router's USB port — the complete setup.

See OpenUI in action in the companion blog post.

Saturday, December 10, 2011

$35 Linux Box for Robotics and Home Automation

A survey of low-cost Linux boards for home automation, robotics, and DIY hardware — and why a ~$35 TP-Link MR3220 Wi-Fi router running OpenWrt turned out to be the sweet spot in 2011.

TP-Link MR3220 router with OpenWrt

TP-Link MR3220 — a cheap Wi-Fi router capable of running OpenWrt Linux.

The hardware landscape

Over the past few years I studied several low-cost open-source hardware platforms for home automation:

Board Price
Beagleboard$150
Beagleboard xM$150
Beaglebone$89
Sheevaplug$85
Seagate Dockstar$50
Buffalo Linkstation Live~$150
Linksys WRT-54GL$50
Asus RT-N16$90
TP-Link MR3220$35
Raspberry Pi$35

Only a few of these are truly open in terms of hardware and software. The rest are commercial products with an option to run open-source Linux.

Requirements

  • Decent processor, RAM, and flash — under $40 (2000 INR)
  • Off-the-shelf product available locally (India)
  • Open-source Linux support (OpenWrt / DD-WRT / Tomato)
  • Lightweight with low power consumption
  • Easy option to extend I/O peripheral access

Why a Wi-Fi router?

With these requirements, I narrowed down to the TP-Link MR3220. While the Raspberry Pi was the ideal solution on paper, it was extremely hard to get in 2011 due to heavy demand.

A Wi-Fi router makes practical sense: everyone already needs one for home connectivity. Adding basic home automation capabilities with little added cost — while saving you from running a 24/7 power-hungry desktop — is a good bargain at ~$35.

For enthusiasts, hobbyists, and students interested in embedded Linux, robotics, home automation, and DIY hardware, a router with USB + OpenWrt lets you skip hardware development and jump straight into firmware and software.

Demo: Android app controlling LEDs over Wi-Fi

No warranty void: You don't need to open your router. The openUI hardware is a USB add-on board that plugs into the router's USB port.

Hardware photos

Collection of Linux hardware boards

My hardware collection — various Linux boards evaluated for home automation.

MR3220 router with openUI USB board

MR3220 router with the openUI USB add-on board connected.

Android app for controlling LEDs

Android app controlling LEDs via Wi-Fi through the MR3220 + openUI setup.

openUI board close-up

Close-up of the openUI USB board.

openUI hardware specs

openUI board with LCD display

openUI board featuring LCD, IR receiver, RTC, and I2C connector.

  • AVR ATtiny2313 — acting as a USB HID device
  • LCD display — for status output
  • RC5 IR receiver — for remote control input
  • PCF8563 RTC — I2C real-time clock with battery backup
  • I2C connector — for extending with additional peripherals
  • ISP header — in-circuit programming for ATtiny2313

Find the schematic, PCB layout, and source code for the openUI hardware and software in this follow-up post.

Friday, October 15, 2010

How to Root the Spice MI-300 with Custom ROM

How to root a Spice MI-300 Android phone by flashing a custom ROM (FiretrapSugar) via the built-in recovery mode. This gives you root access, a custom launcher, and useful pre-installed apps.

Warning: Rooting may brick your device and will void the manufacturer warranty. Proceed at your own risk.

Rooting erases all phone data (SD card data is preserved). Ensure you have backed up everything before starting.

Prerequisites

Rooting procedure

  1. Download the custom ROM from this link
  2. Extract the .rar file (using WinRAR) and rename firetrapSugar.nb0 to firmware.nb0
  3. Copy firmware.nb0 to the root directory of your SD card (not inside any folder)
  4. Switch off the phone
  5. Press and hold Volume Up + Camera, then also press and hold Power (next to the 3.5 mm audio jack) for about 15 seconds
  6. The phone boots into Android system recovery mode
  7. Using the trackball, scroll down to Download nb0 from sdcard and press the trackball to start
  8. Wait 2–3 minutes for the firmware update to complete
  9. The phone reboots with the new "Android" splash screen — you now have FiretrapSugar with root access

Recommended apps

With root access you can install: SetCPU (adjust CPU clock between 122–600 MHz), RootExplorer, QuickSSHd, CacheCleaner, WebSharing, Astro, Skype.

Tips

  • When root apps prompt for superuser access, check Always allow for trusted apps to avoid re-confirmation
  • Use the SwitchPro widget (included in FiretrapSugar) to turn the camera flash into a torch
  • Install QuickSSHd for shell access over Wi-Fi instead of USB adb
  • With QuickSSHd, you can copy files to the phone over Wi-Fi using WinSCP

Backing up NAND flash partitions

After rooting, back up all NAND flash partitions immediately. The boot and recovery partitions are especially important.

  1. Log in to the phone via adb or SSH (QuickSSHd)
  2. If using adb, run su and confirm the superuser prompt on the phone
  3. Run the following commands to dump all partitions to the SD card (view the partition map with cat /proc/mtd):
cat /dev/mtd/mtd0  > /sdcard/bkup.mtd0.boot
cat /dev/mtd/mtd1  > /sdcard/bkup.mtd1.misc
cat /dev/mtd/mtd2  > /sdcard/bkup.mtd2.splash
cat /dev/mtd/mtd3  > /sdcard/bkup.mtd3.recovery
cat /dev/mtd/mtd4  > /sdcard/bkup.mtd4.ftm
cat /dev/mtd/mtd5  > /sdcard/bkup.mtd5.hidden
cat /dev/mtd/mtd6  > /sdcard/bkup.mtd6.dgbmask
cat /dev/mtd/mtd7  > /sdcard/bkup.mtd7.system
cat /dev/mtd/mtd8  > /sdcard/bkup.mtd8.misc2
cat /dev/mtd/mtd9  > /sdcard/bkup.mtd9.cache
cat /dev/mtd/mtd10 > /sdcard/bkup.mtd10.userdata

Copy the backup files from the SD card to a safe location on your PC.

To revert to the official firmware (e.g. for warranty claims), re-flash using the Software Update Tool from Spice and the phone returns to its original state.