Jun 22, 2010
Accessing sensors and actuators in Nokia N900
Nokia N900 has a bunch of interesting sensors and actuators. This post explain how to read the internal sensors (e.g. accelerometer) and write the actuators (e.g. vibration motor) by accessing sysfs in X Terminal application. Details can be found in Maemo wiki pages
Establish the environment (To access data from sensors and actuators, you need to be a root user in X Terminal.)
- Install “rootsh“.
- Open X Terminal application. As it’s a defualt application, you can find it in the application grid.
- Type “sudo grainroot” and press return.
- The screen should show “Root shell enabled”.
Accessing accelerometer
- Type “cat /sys/class/i2c-adapter/i2c-3/3-001d/coord“
- The screen shows “-36 -198 972” for instance. (value is milliG. 1000mG = 1G)
Use Arc tangent to calculate pitch.
angle_in_radians = atan2(x, -y)
angle_in_radians = atan2(y, -z)
Example python code:
def get_rotation():
f = open(“/sys/class/i2c-adapter/i2c-3/3-001d/coord”, ‘r’ )
coords = [int(w) for w in f.readline().split()]
f.close()
return coords
Accessing light meter (ambient light sensor)
- Type “cat /sys/class/i2c-adapter/i2c-2/2-0029/lux“
- The screen shows “20” for instance. (the sensor is located between Nokia Logo and phone speaker on the left hand side.)
Accessing vibration
- Type “sudo gainroot”
- Type “echo <number> > /sys/class/leds/twl4030\:vibrator/brightness”
- Type number between 0 and 255.
- Vibrate for a moment according to the number.
Accessing Bluetooth Serial profile
- Type “sudo gainroot” if you are not the root user.
- Type “rfcomm -r connect 0 <MAC address of the Bluetooth device> 1” (e.g. MAC address -> 03:1A:09:08:32:02). The first 0 is a device number. The digit after the address is channel number.
- Type “cat – >/dev/rfcomm0” (0 is the device number)
- If Bluetooth connectivity is established, you can send data by typing and received data is shown on the screen.
- If the connectivity is failed, type “killall rfcomm 2>/dev/null” and start over again from 1.
Accessing GPS
- Install GPS Track Logger Widget (This widget creates a live log of Geo coordinate if GPS is enabled. The Debian software package has .deb extension.)
- Go to Homescreen. (The widget should already appear there.)
- Press “Rec” button of the widget. See the corresponding screenshot.
- Open X Terminal
- Type “sudo gainroot”
- Type “cd MyDocs” (Default file path should be under MyDocs. This can be changed in the setting view of the widget.)
- Type “cat xxxx.gps” (filename should be latest one if there are multiple).
- The xml file contains log data of Geo coordinates.
See details in Maemo wiki about Location API.
Controlling Full color LEDs
- Type “echo <number> /sys/class/leds/lp5523:r/brightness” (Number between 0 and 255)
- Red: /sys/class/leds/lp5523:r/brightness
- Green: /sys/class/leds/lp5523:g/brightness
- Blue: /sys/class/leds/lp5523:b/brightness
- There are 6 backlight underneath keyboard. Each can be controlled as follow.
- echo <number>/sys/class/leds/lp5523:kb1/brightness
- echo <number> /sys/class/leds/lp5523:kb2/brightnes
- echo <number>/sys/class/leds/lp5523:kb3/brightnes
- echo <number>/sys/class/leds/lp5523:kb4/brightnes
- echo <number>/sys/class/leds/lp5523:kb5/brightnes
- echo <number>/sys/class/leds/lp5523:kb6/brightness
Example python code
oslo:~# cat leds-on.sh
#! /bin/bashRED=/sys/class/leds/lp5523:r/brightness
GREEN=/sys/class/leds/lp5523:g/brightness
BLUE=/sys/class/leds/lp5523:b/brightnesswhile true; do
for led in $RED $GREEN $BLUE; do
echo 255 > $led ; sleep 1 ; echo 0 > $led
done
done
in led paterns give me an error…
it says
exit status 65280
diferent number of lines
can anybody helps me?
my mobile is always withs the lights on and the keypad never is on…