topamax once a day

Raspberry Pi Physical Gmail Notifier

  

This tutorial will demonstrate how to easily turn your Raspberry Pi into a physical Gmail notifier, in only 10 lines of python! If the configured Gmail account has unread messages, the LED will be illuminated, otherwise dim.  The project was inspired by the Arduino/Mac version by J4mie adapted for use on the Raspberry Pi.

Here is a diagram of the wiring of the LED with a 330 ohm resistor in series (created with Fritzing):

raspi_gmail_led

The python script uses the feedparser module to simplify interaction with Gmail and the RPi.GPIO module to control the GPIO pins. The easiest way to install these is using the python pip package manager. If you don’t have it installed, you can install the pip package manager using apt-get. In a terminal on the Pi:

EDIT: For 2012-07-15-wheezy-raspbian.zip and newer, the Python development headers (python2.7-dev) are also required:

sudo apt-get install python-pip python2.7-dev

Next, for pip to work correctly you will need to update to a newer version of distribute using easy_install:

sudo easy_install -U distribute

Then install the feedparser and GPIO modules with pip:

sudo pip install feedparser RPi.GPIO

Once the pre-requisites have been installed, download , or copy and paste the following Python script to the Raspberry Pi:

The final step is to configure the script to run every minute as a cron job. To do so, open the global crontab for editing:

sudo crontab -e

Then add this line to the end of the file (adjust to the location of the python script):

* * * * * python /home/pi/raspi_gmail.py

That’s it! From now on, cron will execute the script once every minute.  If you have unread messages, the GPIO pin will be pulled high, lighting the LED, otherwise, it will be disabled, dimming the LED.

 

Arduino USB HID Keyboard

  

Turn your Arduino UNO into a USB HID keyboard, and make buttons that do whatever you want. Make it a useful tool, with new buttons for Cut/Copy/Paste or Volume+/Volume-/Mute, or annoy your friends and colleagues by setting the keyboard to perform random keypress after random delays!

The USB HID keyboard conforms to the standard USB specification, so is functional on all modern operating systems.  All this is made possible by the use of the Arduino Device Firmware Update (DFU) function.

Arduino Device Firmware Update (DFU)

The Atmega8U2 chip on the Arduino UNO can be programmed directly using the special USB protocol called Device Firmware Update (DFU). This is completely independant of the ‘normal’ method of flashing sketches to the board using the Arduino IDE.

This process is normally used to update the firmware to a more recent version, as explained in the offical Arduino guide, Updating the Atmega8U2 on an Uno or Mega2560 using DFU. Note: If your board is NOT an Arduino UNO SMD you’ll need to solder a 10k resistor (Brown-black-orange) at the back of your board as shown on the Arduino site.

However, in addition to the ability to flash standard USB Serial firmwares, we can also flash alternative firmwares as well. This allows the device to be recognized as many other device types, including keyboard, mouse, joystick, midi device, etc. This is made possible in part to the wonderful open source LUFA (Lightweight USB Framework for AVRs)  USB stack, and keyboard HID firmware from Darran.

In this demonstration, we will flash generic USB HID keyboard firmware. The USB HID protocol provides manufactures the generic specifications to interact with nearly every operating system in existence. For more info, check out the USB HID Spec sheet.

Before you start, install the required packages. On Ubuntu and Debain systems, in a terminal run:

sudo apt-get install dfu-programmer dfu-util

For Windows and Mac instructions to install the dfu-programmer tool, consult the official Arduino DFU documentation.

Then download these two firmware files:

Arduino-usbserial.hex
Arduino-keyboard-0.3.hex

The first step is to make sure you are able to flash the standard arduino firmware. This will confirm that the programmer and the environment are both functional. NOTE: There is no chance of ‘bricking’ the device using this method. The Arduino bootloader firmware can always be updated using the DFU protocol!

sudo dfu-programmer at90usb82 erase
sudo dfu-programmer at90usb82 flash --debug 1 Arduino-usbserial.hex
sudo dfu-programmer at90usb82 reset

Plug cycle the Arduino, then open the Arduino IDE and ensure that you can still upload a sketch. Assuming everything flashes normally, we can move forward with flashing the HID keyboard firmware.

sudo dfu-programmer at90usb82 erase
sudo dfu-programmer at90usb82 flash --debug 1 Arduino-keyboard-0.3.hex
sudo dfu-programmer at90usb82 reset

NOTE: The Arduino can only be flashed with skectches through the Adruino IDE if the Arduino-usbserial.hex bootloader is active. So, to develop a USB HID device, the process becomes:

Flash Arduino-usbserial.hex bootloader with dfu-programmer (erase/flash/reset)
Plug cycle the Arduino
Flash firmware sketch using Arduino IDE
Plug cycle the Arduino
Flash Arduino-keyboard-0.3.hex bootloader with dfu-programmer (erase/flash/reset)
Test and repeat

Now that you understand how the process works, you can try out some of these keyboard samples. The easiest example is the random keypress with random delays, since it doesn’t require any components connected to the Arduino.

Random Key/Random Delay

The following two examples both use three buttons connected to the Arduino. The code can easily be changed to make the buttons perform other actions, by consulting the mapping tables in the USB HID documentation.  Here is a diagram of the circuit, (created with Fritzing):

 

Volume+/Volume-/Mute

Cut/Copy/Paste

 

Cross-Compiling for TI MSP430 Launchpad

  

TI MSP430

Inspired by this tutorial.

We assumes you are running Ubuntu 12.04 and have a TI msp430g2231 but may work for other msp430 devices (see the Other MSP430 Boards section). This tutorial will cover obtaining the dependencies needed to cross-compile a simple light blinking code for your msp430 device, how to flash the cross-compiled binary to your device, and finish with some advice on how-to compile for other msp430 device variations.

Packages and Dependencies

sudo apt-get install git-core gcc-4.4 texinfo patch libncurses5-dev zlibc zlib1g-dev libx11-dev libusb-dev libreadline6-dev binutils-msp430 gcc-msp430 gdb-msp430 msp430-libc msp430mcu mspdebug srecord libsrecord-dev libgmp-dev

If you have gdb installed you will probably get an error like:

Unpacking gdb-msp430 (from …/gdb-msp430_7.2~mspgcc-7.2-20110612-1ubuntu1_amd64.deb) …
dpkg: error processing /var/cache/apt/archives/gdb-msp430_7.2~mspgcc-7.2-20110612-1ubuntu1_amd64.deb (–unpack):
trying to overwrite ‘/usr/share/gdb/python/gdb/__init__.py’, which is also in package gdb 7.4-2012.04-0ubuntu2

Marek Burza presents a solution that will force overwrite the existing gdb files with the msp430 version. No worries here because the files are identical.

sudo apt-get -o Dpkg::Options::=”–force-overwrite” install gdb-msp430

Michael ran the above command and had the following error.

michael@xt2:~$ sudo apt-get -o Dpkg::Options::=”–force-overwrite” install gdb-msp430
Reading package lists… Done
Building dependency tree
Reading state information… Done
You might want to run ‘apt-get -f install’ to correct these:
The following packages have unmet dependencies:
ia32-libs : Depends: ia32-libs-multiarch but it is not installable
E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).

The solution is to follow through with the recommended command.

sudo apt-get -f install

Code

Save the code below to led.c

/* Blink LED example */

#include <msp430g2553.h>

/** Delay function. **/
delay(unsigned int d) {
  int i;
  for (i = 0; i<d; i++) {
    nop();
  }
}

int main(void) {
  WDTCTL = WDTPW | WDTHOLD;
  P1DIR = 0xFF;
  P1OUT = 0x01;

  for (;;) {
    P1OUT = ~P1OUT;
    delay(0x4fff);
  }
}

Compilation

msp430-gcc -Os -mmcu=msp430g2553 -o led.elf led.c

Installation

sudo mspdebug rf2500
erase
prog led.elf
run

Other MSP430 Boards

To get a list of boards other than the msp430g2231 you can look at the gcc compilation processes in more detail by adding the -v flag.

msp430-gcc -v -Os -mmcu=msp430g2553 -o led.elf led.c

Using built-in specs.
Reading specs from /usr/lib/gcc/msp430/4.5.3/../../../../msp430/lib/msp430mcu.spec
COLLECT_GCC=msp430-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/msp430/4.5.3/lto-wrapper
Target: msp430
Configured with: ‘/build/buildd/gcc-msp430-4.5.3~mspgcc-20110716/./gcc-4.5.3/configure’ -v –enable-languages=c,c++ –prefix=/usr –infodir=’/usr/share/info’ –mandir=’/usr/share/man’ –bindir=’/usr/bin’ –libexecdir=’/usr/lib’ –libdir=’/usr/lib’ –enable-shared –with-system-zlib –enable-long-long –enable-nls –without-included-gettext –disable-checking –disable-libssp –build=x86_64-linux-gnu –host=x86_64-linux-gnu –target=msp430 –with-pkgversion=’GNU GCC patched mspgcc-20110716′
Thread model: single
gcc version 4.5.3 (GNU GCC patched mspgcc-20110716)
COLLECT_GCC_OPTIONS=’-v’ ‘-Os’ ‘-mmcu=msp430g2553′ ‘-o’ ‘led.elf’ ‘-mcpu=430′ ‘-mmpy=none’ ‘-mivcnt=16′
/usr/lib/gcc/msp430/4.5.3/cc1 -quiet -v -D__MSP430G2231__ led.c -mcpu=430 -mmpy=none -mivcnt=16 -quiet -dumpbase led.c -mmcu=msp430g2553 -mcpu=430 -mmpy=none -mivcnt=16 -auxbase led -Os -version -o /tmp/ccxzI5yP.s
GNU C (GNU GCC patched mspgcc-20110716) version 4.5.3 (msp430)
compiled by GNU C version 4.6.2, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: –param ggc-min-expand=100 –param ggc-min-heapsize=131072
ignoring nonexistent directory “/usr/lib/gcc/msp430/4.5.3/../../../../msp430/sys-include”
#include “…” search starts here:
#include search starts here:
/usr/lib/gcc/msp430/4.5.3/include
/usr/lib/gcc/msp430/4.5.3/include-fixed
/usr/lib/gcc/msp430/4.5.3/../../../../msp430/include
End of search list.
GNU C (GNU GCC patched mspgcc-20110716) version 4.5.3 (msp430)
compiled by GNU C version 4.6.2, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: –param ggc-min-expand=100 –param ggc-min-heapsize=131072
Compiler executable checksum: f3faedb94e9b3def3d948861a0f5d178
COLLECT_GCC_OPTIONS=’-v’ ‘-Os’ ‘-mmcu=msp430g2553′ ‘-o’ ‘led.elf’ ‘-mcpu=430′ ‘-mmpy=none’ ‘-mivcnt=16′
/usr/lib/gcc/msp430/4.5.3/../../../../msp430/bin/as -mcpu=430 -mmcu=msp430g2553 -o /tmp/ccISTyMA.o /tmp/ccxzI5yP.s
COMPILER_PATH=/usr/lib/gcc/msp430/4.5.3/:/usr/lib/gcc/msp430/4.5.3/:/usr/lib/gcc/msp430/:/usr/lib/gcc/msp430/4.5.3/:/usr/lib/gcc/msp430/:/usr/lib/gcc/msp430/4.5.3/../../../../msp430/bin/
LIBRARY_PATH=/usr/lib/gcc/msp430/4.5.3/:/usr/lib/gcc/msp430/4.5.3/../../../../msp430/lib/
COLLECT_GCC_OPTIONS=’-v’ ‘-Os’ ‘-mmcu=msp430g2553′ ‘-o’ ‘led.elf’ ‘-mcpu=430′ ‘-mmpy=none’ ‘-mivcnt=16′
/usr/lib/gcc/msp430/4.5.3/collect2 -m msp430 -o led.elf /usr/lib/gcc/msp430/4.5.3/crt0ivtbl16.o -L/usr/lib/gcc/msp430/4.5.3 -L/usr/lib/gcc/msp430/4.5.3/../../../../msp430/lib /tmp/ccISTyMA.o -lgcc -lc -lgcc -lcrt0 -L /usr/lib/gcc/../../msp430/lib/ldscripts/msp430g2231/

From the gcc output we can see can further examine any one of the many linked in libraries. Lets look at /usr/lib/gcc/../../msp430/lib/ldscripts/msp430g2231/ for example.

cd /usr/lib/gcc/../../msp430/lib/ldscripts/msp430g2231/
ls
cd ..
ls -al

drwxr-xr-x 2 root root 4096 Jun 23 08:13 cc430f5133
drwxr-xr-x 2 root root 4096 Jun 23 08:13 cc430f5135
drwxr-xr-x 2 root root 4096 Jun 23 08:13 cc430f5137
drwxr-xr-x 2 root root 4096 Jun 23 08:13 cc430f6125
drwxr-xr-x 2 root root 4096 Jun 23 08:13 cc430f6126
drwxr-xr-x 2 root root 4096 Jun 23 08:13 cc430f6127
drwxr-xr-x 2 root root 4096 Jun 23 08:13 cc430f6135
drwxr-xr-x 2 root root 4096 Jun 23 08:13 cc430f6137
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430afe221
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430afe222
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430afe223
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430afe231
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430afe232
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430afe233
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430afe251
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430afe252
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430afe253
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430bt5190
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c091
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c092
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c111
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c1111
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c112
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c1121
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c1331
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c1351
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c311s
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c312
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c313
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c314
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c315
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c323
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c325
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c336
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c337
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c412
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430c413
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430cg4616
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430cg4617
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430cg4618
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430cg4619
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430e112
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430e313
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430e315
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430e325
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430e337
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f110
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1101
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1101a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1111
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1111a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f112
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1121
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1121a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1122
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1132
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f122
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1222
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f123
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1232
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f133
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f135
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f147
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1471
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f148
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1481
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f149
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1491
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f155
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f156
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f157
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1610
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1611
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f1612
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f167
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f168
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f169
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2001
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2002
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2003
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2011
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2012
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2013
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2101
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2111
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2112
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2121
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2122
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2131
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2132
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2232
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2234
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2252
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2254
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2272
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2274
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f233
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2330
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f235
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2350
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2370
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2410
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2416
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2417
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2418
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2419
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f247
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2471
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f248
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2481
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f249
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2491
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2616
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2617
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2618
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f2619
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f412
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f413
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4132
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f415
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4152
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f417
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f423
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f423a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f425
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4250
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f425a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4260
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f427
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4270
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f427a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f435
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4351
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f436
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4361
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f437
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4371
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f438
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f439
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f447
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f448
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4481
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f449
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4491
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4616
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f46161
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4617
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f46171
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4618
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f46181
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4619
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f46191
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47126
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47127
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47163
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47166
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47167
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47173
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47176
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47177
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47183
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47186
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47187
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47193
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47196
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f47197
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f477
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f478
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4783
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4784
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f479
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4793
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f4794
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5131
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5132
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5151
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5152
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5171
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5172
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5304
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5308
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5309
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5310
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5324
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5325
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5326
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5327
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5328
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5329
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5340
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5341
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5342
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5418
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5418a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5419
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5419a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5435
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5435a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5436
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5436a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5437
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5437a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5438
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5438a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5500
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5501
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5502
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5503
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5504
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5505
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5506
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5507
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5508
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5509
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5510
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5513
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5514
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5515
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5517
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5519
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5521
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5522
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5524
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5525
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5526
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5527
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5528
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5529
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5630
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5631
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5632
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5633
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5634
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5635
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5636
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5637
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f5638
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f6630
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f6631
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f6632
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f6633
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f6634
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f6635
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f6636
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f6637
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430f6638
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fe423
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fe4232
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fe423a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fe4242
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fe425
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fe4252
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fe425a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fe427
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fe4272
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fe427a
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg4250
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg4260
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg4270
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg437
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg438
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg439
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg4616
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg4617
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg4618
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg4619
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg477
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg478
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fg479
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fr5720
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fr5725
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fr5728
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fr5729
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fr5730
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fr5735
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fr5738
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fr5739
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fw423
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fw425
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fw427
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fw428
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430fw429
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2001
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2101
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2102
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2111
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2112
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2113
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2121
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2131
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2132
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2152
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2153
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2201
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2202
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2203
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2211
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2212
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2213
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2221
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2231
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2232
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2233
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2252
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2253
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2302
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2303
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2312
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2313
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2332
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2333
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2352
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2353
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2402
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2403
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2412
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2413
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2432
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2433
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2452
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2453
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2513
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2533
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430g2553
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430l092
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430p112
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430p313
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430p315
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430p315s
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430p325
drwxr-xr-x 2 root root 4096 Jun 23 08:13 msp430p337

It seems that the ubuntu msp430 cross-compiler packages include support for many variation of the msp430. To cross-compile for these variations, adjust the -mmcu=msp430 flag accordingly and, in the led.c file, alter the #include file to reflect the chosen board.

Arduino on Raspberry Pi

  

Connecting an Arduino to a Raspberry Pi is simple. In a terminal, install the Arduino IDE:

sudo apt-get install arduino

This will take a while to download and install all of the dependencies. Once completed, you can start the IDE from the terminal:

arduino

Or, from the LXDE menu, Electronics->Arduino IDE. Note: This is IDE version 0018, and does not seem to recognize boards newer then the Duemilanove. Update: The IDE version in the package manager has been updated to version 1.01 and should work with newer boards like the Uno and Leonardo now as well.

The 1 amp power supply I have connected to my Raspberry Pi was not sufficient to power both the Pi and the Arduino through the USB port, so I connected the Arduino through a powered external USB hub. This may not be necessary with a larger power supply connected to the Pi. Update: A larger power supply will not overcome this limitation; the micro USB port on the Raspberry Pi is fused with 1100mA. –Thanks cavebeat

 

Alternatively, the 5V GPIO R_Pi Pin can be used to power the Arduino. Just connect the 5V GPIO pin on the Raspberry Pi to the VIN pin on the Arduino, and respectively GND from one board to the other.

 

This eliminates the need for the externally powered USB hub, but can make development more of a chore due to the USB port restriction: the keyboard and Arduino will need to be swapped in and out to flash the Arduino.

Raspberry Pi NES Emulator

  

This tutorial will demonstrate how to install Nintendo NES/Famicom emulator on the Raspberry Pi running Debian.  Begin by installing the necessary dependencies. In a terminal, enter:

sudo apt-get install scons libsdl1.2-dev libsdl1.2debian-esd subversion libgtk2.0-dev

Checkout the most recent sources using subversion:

svn checkout https://fceultra.svn.sourceforge.net/svnroot/fceultra/fceu fceultra

The repo has moved here:

svn checkout svn://svn.code.sf.net/p/fceultra/code/fceu fceultra

Change directory into the root of the source tree

cd fceultra/

Compile and install FCEU using the scons build tool:

sudo scons GTK=1 install

That’s it! To run:

fceux

Then select the ROM with from the title bar menu, File->Open ROM, or with Ctrl+O.

You can easily setup a gamepad too, like the USB NES RetroPort. This adapter converts an authentic NES controller to USB.   To configure, run fceux using the inputcfg flag to setup configure.  Press the corresponding buttons in series as they are prompted. Note: There are two dashes ( – - ) together in the command below:

fceux –inputcfg gamepad1

 

Raspberry Pi + OpenCV

  

OpenCV is a suite of powerful computer vision tools. Here is a quick overview of how I installed OpenCV on my Raspberry Pi with debian6-19-04-2012.  The guide is based on the official OpenCV Installation Guide on Debian and Ubuntu. Before you begin, make sure you have expanded your SD card to allow for the install of OpenCV. Its a big package with lots of dependencies. You can follow my instructions here.  Once you have expanded the SD card, open up a terminal and install the following packages:

sudo apt-get -y install build-essential cmake cmake-qt-gui pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev zlib1g-dbg zlib1g zlib1g-dev pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools

 

sudo apt-get -y install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg libavcodec-dev libavcodec53 libavformat53 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils swig libv4l-0 libv4l-dev python-numpy libpython2.6 python-dev python2.6-dev libgtk2.0-dev pkg-config

There are some dependency issues with the order of the install, mostly with regard to libjpeg issues, so be sure to install in this order. You will see some broken package errors if you attempt to install all the dependencies in one step.

Next, pull down the source files for OpenCV using wget:

wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2

Once finished downloading, extract the archive, remove the no longer needed archive (to save space), change directory to the top of the source tree, make a directory for the build, and change into it:

tar -xvjpf OpenCV-2.3.1a.tar.bz2

rm OpenCV-2.3.1a.tar.bz2

cd OpenCV-2.3.1/

mkdir build

cd build

Next, you will need to configure the build using cmake. If you aren’t sure about what options you want/need or are unfamiliar with cmake, this line will create a standard configuration:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..

Alternatively, you can configure the build using a GUI interface. This can be helpful to build with support for additional OpenCV features. To use the cmake GUI, run:

cmake-gui ..

In the cmake GUI, click ‘configure’ to pre-populate the build options. Select or remove any desired features, then click ‘configure’ again, check the output and ensure that there are not any modules that cmake cannot find. If everything looks good, click ‘generate’ to create the makefiles, then close cmake-gui. Now we are ready to start the build! To compile, run make, then install with make install:

make

sudo make install

As you can see from the image, this will take a LONG time… over four and a half hours to compile!

Finally, we need to make a few configurations for OpenCV. First, open the opencv.conf file with the following code:

sudo nano /etc/ld.so.conf.d/opencv.conf

Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:

/usr/local/lib

Then edit the system-wide bashrc file:

sudo nano /etc/bash.bashrc

Add the following new lines to the end of the file:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH

Now that everything is installed and configured, on to the demos!  The C demos are here:

cd ~/opencv/OpenCV-2.3.1/build/bin

C demos in build/bin demos worth checking out (that don’t require a webcam):

convexhull

kmeans

drawing

The python demos are located in samples/python:

cd ~/opencv/OpenCV-2.3.1/build/bin

These demos also don’t require a webcam:

python ./minarea.py

python ./delaunay.py

python ./drawing.py

 

 

Raspberry Pi Root FS on USB Drive

  

This tutorial will demonstrate how to install the Debian root filestem (ie. ‘/’) on a USB drive instead of the SD card. The SD card still retains the /boot partion and swap space. This requires a modified kernel to support the USB storage. You can download the minimal modified kernel and modules here  or follow my guide on how to compile it for yourself.

In either case, begin by installing the Debian image as you normally would to an SD card. Manually format the USB drive you intend to use as the root filesystem as ext4 using a utility like gparted.

Next, copy the root filesytem from the Debian install on the SD card to the USB drive, preserving attributes with the -a flag, substituting “sdcard-rootfs-partition-uuid” and “usbdrive-rootfs-partition-uuid” with the respective identifiers as the filesystem are mounted in Ubuntu.

sudo cp -a /media/sdcard-rootfs-partition-uuid/* /media/usbdrive-rootfs-partition-uuid/

sync

Now, delete the existing kernel.img and replace it with the new one, substituting “sdcard-boot-partition-uuid” with the identifier of the partion as it is mounted in Ubuntu.

sudo rm /media/sdcard-boot-partition-uuid/kernel.img

sudo mv kernel.img /media/sdcard-boot-partition-uuid/

Next, remove the existing /lib/modules and lib/firmware directories,

sudo rm -rf /media/usbdrive-rootfs-partition-uuid/lib/modules/

sudo rm -rf /media/usbdrive-rootfs-partition-uuid/lib/firmware/

and copy the new modules and firmware in their place:

cd ../../kernel/

sudo cp -a lib/modules/ /media/usbdrive-rootfs-partition-uuid/lib/

sudo cp -a lib/firmware/ /media/usbdrive-rootfs-partition-uuid/lib/

sync

Now we need to modify the location of the root partition in the /boot partion. This is contained within the file, cmdline.txt. In this file, change:

root=/dev/mmcblk0p2

to:

root=/dev/sda1

That’s it! Plug in and boot up the root filesystem from the USB stick!