R2 Project Log – External Interrupts

I’ve done some playing, and worked out how to turn on the external interrupts on the atmega128 I am using for R2.

Code:

#define F_CPU 1000000UL
#include < avr/io.h>
#include < util/delay.h>
#include < avr/interrupt.h>

#include "r2.h"

int main(void) {
	// Activate all the LEDs, set their pins to output
	bit_set(LED_WHITE_L_DDR, LED_WHITE_L_BIT);
	bit_set(LED_WHITE_R_DDR, LED_WHITE_R_BIT);
	bit_set(LED_RED_L_DDR, LED_RED_L_BIT);
	bit_set(LED_RED_R_DDR, LED_RED_R_BIT);
	bit_set(LED_YELLOW_FL_DDR, LED_YELLOW_FL_BIT);
	bit_set(LED_YELLOW_FR_DDR, LED_YELLOW_FR_BIT);
	bit_set(LED_YELLOW_RL_DDR, LED_YELLOW_RL_BIT);
	bit_set(LED_YELLOW_RR_DDR, LED_YELLOW_RR_BIT);

	// enable internal pullup on PD0
	bit_set(PORTD, BIT(0));
	// enable external interrupts
	EIMSK = BIT(INT0) | BIT(INT1);
	// enable global interrupts
	sei();

	// turn on the white and red LEDs
	bit_set(LED_WHITE_L_PORT, LED_WHITE_L_BIT);
	bit_set(LED_WHITE_R_PORT, LED_WHITE_R_BIT);
	bit_set(LED_RED_L_PORT, LED_RED_L_BIT);
	bit_set(LED_RED_R_PORT, LED_RED_R_BIT);

	// loop forever
	while (1)
	{
		delayms(500);
	}
	return 0;
}

// delay for up to 65k milliseconds
void delayms(uint16_t millis)
{
	// loop, delaying 1ms each iteration
	while ( millis )
	{
		_delay_ms(1);
		millis--;
	}
}

// this catches the Interrupt sent from pin INT0
ISR(INT0_vect)
{
	//Turn everything off
	bit_clear(LED_WHITE_L_PORT, LED_WHITE_L_BIT);
	bit_clear(LED_WHITE_R_PORT, LED_WHITE_R_BIT);
	bit_clear(LED_RED_L_PORT, LED_RED_L_BIT);
	bit_clear(LED_RED_R_PORT, LED_RED_R_BIT);

	// loop forever, flashing our indicators.
	while(1)
	{
		bit_flip(LED_YELLOW_FL_PORT, LED_YELLOW_FL_BIT);
		bit_flip(LED_YELLOW_FR_PORT, LED_YELLOW_FR_BIT);
		bit_flip(LED_YELLOW_RL_PORT, LED_YELLOW_RL_BIT);
		bit_flip(LED_YELLOW_RR_PORT, LED_YELLOW_RR_BIT);
		delayms(500);
	}
}

Changing Trigger Mode:

By default, the interrupt triggers when the pin is brought low. If we want to change this behavior, we need to poke at the External Interrupt Control Registers, EICRA (for INT0 – INT3) and EICRB (for INT4 – INT7).

Each interrupt pin has 2 bits in the EICR Registers, ISCxO and ISCx1. This Gives 4 possible options for triggering:

  • 0 0: Default, Trigger when INTx is held low
  • 0 1: Not Used
  • 1 0: Trigger when INTx changes from 1 to 0
  • 1 1: Trigger when INTx changes from 0 to 1

So, to turn on INT1, and set it to trigger on a rising edge, we,d use the following code:

// enable external interrupt
EIMSK = BIT(INT0);
//  set the interrupt to trigger on a rising edge
EICRA |= BIT(ISC00) | BIT(ISC01);

Video:

EeeeeeEEEEeeeeeee PeeeeeCeeeee

I’ve been looking for a while now for a small, light, cheap laptop that i could convert into a solid state machine by way of a compactflash – IDE adapter. After wading through countless ebay auctions of 300mhz machines for £200, I had basically given up… Until Sunday.

You see, on Sunday, someone mentioned the Asus eee pc to me in a conversation, saying how it was thin, light, and cheap… And it sounded perfect. So, come Monday i hit Google and found some reviews, saw a takeapart guide, found out it was completely solid state, and ran a customized version of Xandros Linux.

It sounded perfect, if only i could find somewhere that sold it! I quickly hit up RM, the official UK distributor, to find that their price was £240 including vat and delivery. One problem though, they’re not selling them until the 16th! So, i head back to Google, and find that eBuyer have them for £220 including VAT. Out of stock again… but they have a black version in stock! I hit buy quickly, before that little bit of sanity I have left comes back to tell me not to, and tack on next day delivery, because the insane part of my brain is also impatient.

It arrived Tuesday morning, and I immediately set about getting rid of Xandros, and replacing it with the glory that is Ubuntu Gutsy. Easy enough, the basic install worked from a USB DVD drive as it would on any other PC.

Once i had the OS installed, it was time for customization and optimization. Step 1 was to get the wireless working. Easy as hell with ndiswrapper from the Gutsy install DVD, and the windows driver from the eee driver disk.  Once that was set up, i could connect easily to WPA networks through nm-applet, and run an update. After that i set /tmp and /var/log to run from tmpfs RAM drives, and

My eee has been running along nicely now for 3 days, Unknowing of the horror i am soon going to unleash on it with a soldering iron, and some USB devices…

sp_a0021.jpg

Tune in soon to see what happens…

Wiimote connected to linux

So, I’ve been playing around recently with trying to set up bluetooth on wrecs so i can connect a wiimote to it.

I finally got it working using libwiimote

parag0n@wrecs:$ ./test1 00:19:1D:83:A5:89
test1 - libwiimote test application

A    - Enable accelerometer
B    - Enable ir-sensor
1    - Enable rumble
+    - Increment leds
-    - Decrement leds
Home - Exit

Press buttons 1 and 2 on the wiimote now to connect.
MODE 34
BAT 70
KEYS 0000 one=0 two=0 a=0 b=0 <=0 >=0 ^=0 v=0 h=0 +=0 -=0
JOY1 joyx=128 joyy=127 x=125 y=107 z=173 keys.z=0 keys.c=0
JOY2 joyx=128 joyy=127
JOY3 joyx=125 joyy=107
AXIS x=000 y=000 z=000
TILT x=0.000 y=0.000 z=0.000
FORCE x=0.000 y=0.000 z=0.000 (sum=0.000)
IR1 x=0000 y=0000 ss=0
IR2 x=0000 y=0000 ss=0
IR3 x=0000 y=0000 ss=0
IR4 x=0000 y=0000 ss=0

Now i have this working, it’ll be a simple matter to create a remote control application for when i get the motor drivers working, and get full remote control!

wiimote.jpg

Wrecs Update

It just occurred to me that i have no pictures of wrecs on here since… well… forever… anyway, here are some recent pictures (about a month old). The only differences between then and now is that he now has a 10.4″ LCD screen on top, which will be activated when there is a person within a couple of meters of him.

wrecs-front.jpg
wrecs-inside.jpg

The next step in hardware is to design and build the power distribution board, which will supply 12v and 5v to the rest of the electronics.

In software the next step is to get a bluetooth adaptor working, and link in a wiimote :).

Logitech mx1000 under Ubuntu 6.06LTS (Dapper Drake)

Most stuff on my mx1000 worked fine from install in ubuntu, all except the forward, back & task buttons, heres how i got them working:

step 1: install dependencies

sudo apt-get install xorg-dev xserver-xorg-dev xbindkeys xvkbd build-essential

step 2: edit /etc/udev/rules.d/01_mx1000.rules

sudo gedit /etc/udev/rules.d/01_mx1000.rules

Paste in the following, then save:

ACTION==”add”,
KERNEL==”event*”,
SUBSYSTEM==”input”,
SYSFS{manufacturer}==”Logitech”,
SYSFS{product}==”Logitech USB Receiver”,
NAME=”input/mx1000″

Then restart udev:

sudo /etc/init.d/udev restart

Re-plug your mouse, and check if its device node is there

parag0n@Aura:~$ ls /dev/input/
event0  event2  event3  event4  mice  mouse0  mx1000  ts0

It is, so we can carry on…

step 3: edit xorg

sudo gedit /etc/X11/xorg.conf

Change the “Configured Mouse” Device section to read:

Section "InputDevice"
Identifier "MX1000"
Driver     "evdev"
Option     "CorePointer"
Option "Name" "Logitech USB Receiver"
EndSection

and change DefaultMouse in the server section to “MX1000″

Save and exit.

step 4: edit ~/.xbindkeysrc

sudo gedit ~/.xbindkeysrc

Paste in the following:

# Activate Backward and Forward buttons
"xvkbd -text "[Alt_L][Left]""
m:0x10 + b:8
"xvkbd -text "[Alt_L][Right]""
m:0x10 + b:9

# This enables the click up / down buttons to move you further:
"/usr/bin/click 4"
m:0x10 + b:11
"/usr/bin/click 5"
m:0x10 + b:12

#I take lots of screenshots, so i mapped the middle button of forward / back to printscreen
"gnome-screenshot"
m:0x10 + b:10

step 5: make gnome run xbindkeys at startup

edit ~/.gnomerc

gedit ~/.gnomerc

And add:

xbindkeys

step 6: compile click

now we are going to make ‘click’, the program that makes the scroll wheel work properly:

wget http://www.ussg.iu.edu/hypermail/linux/kernel/0504.0/1371/click.tgz
tar xzf click.tgz
cd click
make
sudo cp click /usr/bin/click

reboot, and enjoy!

Thanks to Jürgen Kreileder, for his blog entry that this is based upon, and various other places i found while trying to fix the problems i had with his config.