Hardware Access

From WikiPixie
Jump to: navigation, search

Working with PixiePro Hardware

User LED(s)

PixiePro has 3 built-in LEDs (LED1, LED2, and LED3) which can be controlled from userspace, so it is possible to change the output value directly from the command line.

  • The user LED(s) are accessible via the user space in Linux at the following location:
    /sys/class/leds
  • There is one directory per user LED, named as shown below:
    /sys/class/leds/led1
    /sys/class/leds/led2
    /sys/class/leds/led3
  • To control the LED(s). Type in the following commands (For example, LED1):
    # echo 1 > /sys/class/leds/led1/brightness --> Turn LED on
    # echo 0 > /sys/class/leds/led1/brightness --> Turn LED off

Magnetometer and Accelerometer


#!/bin/sh

# set to active mode
i2cset -f -y 1 0x1e 0x2a 1
# enable both accelerometer and magnetometer
i2cset -f -y 1 0x1e 0x5b 3

while [ 1 ]; do
  # accelerometer vector
  a_x=$(( $( i2cget -f -y 1 0x1e 0x01 ) << 8 | $( i2cget -f -y 1 0x1e 0x02 ) ))
  a_y=$(( $( i2cget -f -y 1 0x1e 0x03 ) << 8 | $( i2cget -f -y 1 0x1e 0x04 ) ))
  a_z=$(( $( i2cget -f -y 1 0x1e 0x05 ) << 8 | $( i2cget -f -y 1 0x1e 0x06 ) ))

  # magnetometer vector
  m_x=$(( $( i2cget -f -y 1 0x1e 0x33 ) << 8 | $( i2cget -f -y 1 0x1e 0x34 ) ))
  m_y=$(( $( i2cget -f -y 1 0x1e 0x35 ) << 8 | $( i2cget -f -y 1 0x1e 0x36 ) ))
  m_z=$(( $( i2cget -f -y 1 0x1e 0x37 ) << 8 | $( i2cget -f -y 1 0x1e 0x38 ) ))

  echo "$a_x/$a_y/$a_z $m_x/$m_y/$m_z"
done