pmeerw's blog

Aug 2012

Sun, 26 Aug 2012

How to use the Linux Industrial IO (IIO) interface

IIO is a Linux subsystem intended to support reading sensors (or some kind of analog-to-digital convertors) including accelerometers, gyros, temperature/pressure/light sensors. It recently left staging (November 2011).

Reading sensor values via IIO can be done directly or in buffered mode. The later requires setup of a trigger.

Here is the script I use to test an Linux IIO driver I'm developping for the Si1143 ambient light/proximity sensor:

# load necessary modules
modprobe industrialio
modprobe iio-trig-sysfs
modprobe kfifo_buf
modprobe industrialio-triggered-buffer

# reload driver
rmmod si114x_new
insmod si114x-new.ko

# register new i2c device
echo si114x 0x5a > /sys/devices/platform/omap_i2c.2/i2c-2/new_device

# proximity reading (direct)
cat /sys/bus/iio/devices/iio:device0/in_proximity0_raw

# add new IIO sysfs trigger
echo 123 > /sys/bus/iio/devices/iio_sysfs_trigger/add_trigger
echo sysfstrig123 > /sys/bus/iio/devices/iio:device0/trigger/current_trigger

# enable some channels 
echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_proximity0_en
echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_intensity_en
echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_temp_en

# enable scan buffer
echo 100 > /sys/bus/iio/devices/iio:device0/buffer/length
echo 1 > /sys/bus/iio/devices/iio:device0/buffer/enable

# trigger to read data
echo 1 > /sys/bus/iio/devices/trigger0/trigger_now

# read the captured data (buffered)
cat /dev/iio\:device0 > /tmp/data.bin

posted at: 11:56 | path: /projects | permanent link

Fri, 17 Aug 2012

Connecting an OLED display to beaglebaord

Tried to connect the Adafruit Monochrome 1.3" 128x64 OLED graphic display to a beagleboard-xm using the following pins on the main expansion header:
27 - GND
23 - SDA
24 - SCL
4 - GPIO 144 (UART2_CTS)
1 - 1.8 V

First, mount the debug file system
mount -t debugfs none /sys/kernel/debug,
mux the pin to GPIO output
devmem 0x48002174 16 0x0004,
and check the result:

# cat uart2_cts 
name: uart2_cts.gpio_144 (0x48002174/0x144 = 0x0004), b ab26, t NA
mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE4
signals: uart2_cts | mcbsp3_dx | gpt9_pwm_evt | NA | gpio_144 | NA | NA | safe_mode

Next, make GPIO144 accessible
echo 144 > /sys/class/gpio/export,
set the GPIO direction to output
echo out > /sys/class/gpio/gpio144/direction,
and set the output value to high
echo 1 > /sys/class/gpio/gpio144/value.

Finally, we can program the SSD1306 controller (following Adafruit example):

# reset
echo 1 > /sys/class/gpio/gpio144/value
echo 0 > /sys/class/gpio/gpio144/value
echo 1 > /sys/class/gpio/gpio144/value
# initialize
i2cset -y 2 0x3d 0x00 0xae # display off
i2cset -y 2 0x3d 0x00 0xd5 # clockdiv
i2cset -y 2 0x3d 0x00 0x80
i2cset -y 2 0x3d 0x00 0xa8 # multiplex
i2cset -y 2 0x3d 0x00 0x3f
i2cset -y 2 0x3d 0x00 0xd3 # offset
i2cset -y 2 0x3d 0x00 0x00
i2cset -y 2 0x3d 0x00 0x40 # startline
i2cset -y 2 0x3d 0x00 0x8d # charge pump
i2cset -y 2 0x3d 0x00 0x14
i2cset -y 2 0x3d 0x00 0x20 # memory mode
i2cset -y 2 0x3d 0x00 0x00
i2cset -y 2 0x3d 0x00 0xa1 # segregmap
i2cset -y 2 0x3d 0x00 0xc8 # comscandec
i2cset -y 2 0x3d 0x00 0xda # set com pins
i2cset -y 2 0x3d 0x00 0x12
i2cset -y 2 0x3d 0x00 0x81 # contrast
i2cset -y 2 0x3d 0x00 0xcf
i2cset -y 2 0x3d 0x00 0xd9 # precharge
i2cset -y 2 0x3d 0x00 0xf1
i2cset -y 2 0x3d 0x00 0xdb # vcom detect
i2cset -y 2 0x3d 0x00 0x40
i2cset -y 2 0x3d 0x00 0xa4 # resume
i2cset -y 2 0x3d 0x00 0xa6 # normal (not inverted)
i2cset -y 2 0x3d 0x00 0xaf # display on
# transfer frame buffer data
i2cset -y 2 0x3d 0x40 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff i
i2cset -y 2 0x3d 0x40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 i
...

     

posted at: 23:03 | path: /projects | permanent link

Mon, 06 Aug 2012

Playing with Silabs' HID-USB-to-IR reference design with Linux

The Silabs IR Gesture USB HID Reference Design was lacking Linux support... here is some Linux sample code!

I'm using the HID API multi-platform library, available from http://www.signal11.us/oss/hidapi/, to access the cp2112 HID USB bridge and the si1143 sensor connected via SMBus/I2C.

posted at: 22:53 | path: /projects | permanent link

Made with PyBlosxom