User Tools

Site Tools


Sidebar

Launch of Linino.org

wiki:luckyshield

LUCKY SHIELD

The Lucky shield provides several sensors directly integrated onto your Linino board. The available sensors embedded on it are the following ones:

  • Pir
  • Humidity
  • Three-axis accelerometer
  • Three-axis magnetometer
  • Pressure
  • Light
  • Buzzer

in addition to this, the shield is also equipped with :

  • display OLED
  • digital joystick
  • two led
  • two relays
  • two push buttons

To enable the Lucky shield you have run this command:

echo lucky > /sys/devices/mcuio/shield_register

You can detect the registered i2c sensors in the following sysfs path:

root@linino:~# ls /sys/bus/i2c/devices/
0-000e  0-0020  0-003c  0-0040  0-0055  0-0060  i2c-0

HUMIDITY

SHELL

To show the fields list of the humidity sensor run the following command:

root@linino:~# ls /sys/bus/i2c/devices/0-0040/
driver                        hwmon            name                 temp1_input
humidity1_input     modalias         subsystem        uevent

To read sensor data:

root@linino:~# cat /sys/bus/i2c/devices/0-0040/humidity1_input
41836

NODEJS

To evaluate the humidity and temperature values from humidity sensor in nodejs, run the following script:

var linino = require('ideino-linino-lib'),
       board = new linino.Board();
       board.addShield('lucky');
 
board.connect( function(){
 
    board.i2cRead('HUM', 'humidity1_input', function(data){
        console.log("Humidity_raw: " + data);
    });
    board.i2cRead('HUM', 'temp1_input', function(data){
        console.log("Temperature_raw: " + data);
    });
});

THREE-AXIS ACCELEROMETER

To show the fields list of the accelerometer sensor run the following command:

root@linino:~# ls /sys/devices/mcuio/0:0.0/0:1.4/i2c-0/0-0055/iio:device2/
buffer                                                   in_accel_z_calibbias
dev                                                       in_accel_z_raw
in_accel_sampling_frequency          name
in_accel_scale                                     scan_elements
in_accel_x_calibbias                          subsystem
in_accel_x_raw                                   trigger
in_accel_y_calibbias                          uevent
in_accel_y_raw

To read sensor data:

root@linino:~# cat /sys/devices/mcuio/0:0.0/0:1.4/i2c-0/0-0055/iio:device2/in_accel_x_raw
14

THREE-AXIS MAGNETOMETER

To show the fields list of the magnetometer sensor run the following command:

root@linino:~# ls /sys/bus/i2c/devices/0-000e/iio\:device3/
buffer                                              in_magn_z_raw
dev                                                   in_temp_raw
in_magn_sampling_frequency    in_temp_scale
in_magn_scale                               name
in_magn_x_calibbias                     sampling_frequency_available
in_magn_x_raw                              scan_elements
in_magn_y_calibbias                     subsystem
in_magn_y_raw                              trigger
in_magn_z_calibbias                     uevent

To read sensor data:

root@linino:~# cat /sys/bus/i2c/devices/0-000e/iio\:device3/in_magn_x_raw
-1477

To set the desired sampling frequency, you first need to read the range of available sampling frequencies and then you can set the one of your choice (deault is 80.000000):

root@linino:~# cat /sys/bus/i2c/devices/0-000e/iio\:device3/sampling_frequency_available
0.625000 1.250000 2.500000 5.000000 10.000000 20.000000 40.000000 80.000000
root@angelino:~# echo 20.000000 > /sys/bus/i2c/devices/0-000e/iio\:device3/in_magn_sampling_frequency

PRESSURE

To show the fields list of the pressure sensor run the following command:

root@linino:~# ls /sys/bus/i2c/devices/0-0060/iio\:device1/
buffer                       in_pressure_scale    name                      trigger
dev                           in_temp_raw             scan_elements      uevent
in_pressure_raw    in_temp_scale           subsystem

To read sensor data:

root@linino:~# cat /sys/bus/i2c/devices/0-0060/iio\:device1/in_pressure_raw
408081

LIGHT

Light sensor is connected to A0 analog pin. To use it, you have to enable the analog input:

root@linino:~# echo 1 > /sys/bus/iio/devices/iio\:device0/enable

Then, you can read sensor data:

root@linino:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage_A0_raw
609

BUZZER

Buzzer is connected to D5 pin and work in pwm mode. To use it, you have to export pwm pin D5:

root@linino:~# echo 4 > /sys/class/pwm/pwmchip0/export

Then, you can play a tone by running this commands:

root@linino:~# echo 500000 > /sys/class/pwm/pwmchip0/D5/period
root@linino:~# echo 250000 > /sys/class/pwm/pwmchip0/D5/duty_cycle
root@linino:~# echo 1 > /sys/class/pwm/pwmchip0/D5/enable

DISPLAY OLED

To display an image on the oled screen, send a data stream of monochrome image to the framebuffer as follows:

root@linino:~# cat linino_log.1bpp > /dev/fb0

You can download demo monochrome images here

If you want to display your custom png image on the oled screen use our png2mono tool. To install png2mono follows this steps:

root@linino:~# opkg update
root@linino:~# opkg install png2mono_1.0.0-5_ar71xx.ipk

Then, to generate a monochrome image from your custom image run this command :

root@linino:~# png2mono custom_image.png monochrome_image.1bpp

Now you should be able to display your custom image with a simple 'cat' of the image itself :

root@linino:~# cat monochrome_image.1bpp > /dev/fb0

DIGITAL JOYSTICK

Joystick are connected in a gpio expander as follows:

  • gpio 208 –> joystick-up
  • gpio 209 –> joystick-down
  • gpio 210 –> joystick-left
  • gpio 211 –> joystick-right
  • gpio 212 –> joystick-center

to enable the use of a joystick's direction you have first to export the corresponding gpio (i.e. “joystick-up”) :

root@linino:~# echo 208 > /sys/class/gpio/export

set the gpio direction in input mode:

root@linino:~# echo in > /sys/class/gpio/gpio208/direction

and then you can read the input value:

root@linino:~# cat /sys/class/gpio/gpio208/value
0

note: joystick's direction is active-low

LED

Leds are connected in a gpio expander as follows:

  • gpio 204 –> red-Led
  • gpio 205 –> green-Led

to enable the use of one of them you have first to export the corresponding gpio:

root@linino:~# echo 204 > /sys/class/gpio/export

set the gpio direction in output mode:

root@linino:~# echo out > /sys/class/gpio/gpio204/direction

and then turn the led on by running this command:

root@linino:~# echo 0 > /sys/class/gpio/gpio204/value

note: Led is active-low

RELAYS

Relays are connected in a gpio expander as follows:

  • gpio 206 –> relay 1
  • gpio 207 –> relay 2

to enable the use of one of them you have first to export the corresponding gpio:

root@linino:~# echo 206 > /sys/class/gpio/export

set the gpio direction in output mode:

root@linino:~# echo out > /sys/class/gpio/gpio206/direction

then, you can change relay's state by writing “1” or “0” in the “value” field:

root@linino:~# echo 0 > /sys/class/gpio/gpio206/value

PUSH BUTTONS

Buttons are connected in a gpio expander as follows:

  • gpio 213 –> push-button 1
  • gpio 214 –> push-button 2

to enable the use of one of them you have first to export the corresponding gpio:

root@linino:~# echo 213 > /sys/class/gpio/export

set the gpio direction in input mode:

root@linino:~# echo in > /sys/class/gpio/gpio213/direction

and then you can read the input value:

root@linino:~# cat /sys/class/gpio/gpio213/value
0

note: push-button is active-low

/var/www/wiki.linino.org/data/pages/wiki/luckyshield.txt · Last modified: 2014/11/07 12:57 by andrea

2014 © dog hunter llc and the Linino Community. Linino.org is a dog hunter sponsored community project. Credits