User Tools

Site Tools


Sidebar

Launch of Linino.org

wiki:lininoio_sysfs

GPIO on lininoIO

By using MCUIO protocol, linino-IO provides a way to show AVR atmega32u4 GPIOs as they were gpios of the main processor. Such “virtualized” GPIOs start from number 100 and follow the mapping in the attached yun-gpios.cfg file. For Instance, AVR GPIO PC7, which is connected to IO13 on the board, is virtualized as GPIO15, so its id is definitely 100+15=115.

In order to use it as a digital output follow the instructions:

echo 115 > /sys/class/gpio/export
echo out > /sys/class/gpio/D13/direction
echo 1 > /sys/class/gpio/D13/value
echo 0 > /sys/class/gpio/D13/value

You can use these GPIOs in the standard linux way, including the possibility of driving them from your preferred user space library. For more information on GPIOS, look at Linux documentation:

https://github.com/linino/kernel_3.3.8/blob/master/Documentation/gpio.txt

PWM on lininoIO

PWM on lininoIO use the standard linux pwm framework, with some small improvements. This is a quick reference, for more information refer to kernel documentation, e.g. here: https://github.com/linino/kernel_3.3.8/blob/master/Documentation/pwm.txt

1) You need to export the pwm you think you will use. This does not enable pwms, so you can export them all, for convenience.

read number of available pwm here:

cat /sys/class/pwm/pwmchip0/npwm 

Then export all desired pwm's, chosen from 0 to npwm, with this command:

echo 0 > /sys/class/pwm/pwmchip0/export
echo 1  > /sys/class/pwm/pwmchip0/export
...

2) You will find some symbolic link on sysfs, where the name corresponds to the labels on the expansion connector on the board:

/sys/class/pwm/pwmchip0/D3 
/sys/class/pwm/pwmchip0/D9 
/sys/class/pwm/pwmchip0/D10 
/sys/class/pwm/pwmchip0/D11 
...

3) For each of them, you have the following attributes (NOTE: all numeric values are nanoseconds):

  • enable: enable pwm output (can be 0 or 1)
  • resolution (in ns): min step for period and duty_cycle changes
  • max (in ns): max value for period and duty_cycle
  • polarity: can be normal or inversed
  • period (in ns): period of output wave
  • duty_cycle (in ns): time output wave is high (if polarity is “normal”) or low (in case of “inversed”)

Note: D9, D10 and D11 share the same timer so, if you modify the period of one of these digital pins this will affect the remaining two as well. You can not change period on D3, but duty_cycle only

BOARD PWM
PWM n. OUTPUT
0 D3
1 D9
2 D10
3 D11
4 D5
5 D6

Servo

To control a servo motor you need to set the appropriate values of duty_cycle and period of the pwm. To ensure proper operation of the servo motor the minimum value for the period is 20ms. The values ​​to determine the angle of rotation, depend on the model of the servo motor in use. Typically the values ​​of duty_cycle vary from 0.56ms (0°) to 2.4ms (180°). To initialize the usage of pwm with a servo motor, set the minimum values for period and duty_cycle and then enable the pwm

echo 1 > /sys/class/pwm/pwmchip0/export
echo 20000000  > /sys/class/pwm/pwmchip0/D9/period
echo 560000  > /sys/class/pwm/pwmchip0/D9/duty_cycle
echo 1  > /sys/class/pwm/pwmchip0/D9/enable

To rotate of 180°:

echo 2400000 > /sys/class/pwm/pwmchip0/D9/duty_cycle

Buzzer

To play tones with a piezo buzzer you need to set the duty_cycle at 50% of the period of the pwm. The period is the inverse of the frequency of the tone that you want to play. For example if you want reproduce a 40Hz tone the period wiil be 1 / 40Hz = 25ms

echo 25000000  > /sys/class/pwm/pwmchip0/D9/period
echo 12500000  > / sys/class/pwm/pwmchip0/D9/duty_cycle
echo 1  > /sys/class/pwm/pwmchip0/D9/enable

Note: you can not play tones lower to 31Hz

A/D Converter on lininoIO

To read the voltage applied on the pin A0,A1,A2,A3,A4,A5 present on the pinheader of Arduino Yun or Linino ONE from Linino OS follow the next steps.

- Once the device is discovered, you should find the symbolic link:

/sys/bus/iio/devices/iio:device0

- to enable adc usage, echo 1 to 'enable' file:

echo 1 > /sys/bus/iio/devices/iio:device0/enable

- if everything succeeds, you should see those directories in sysfs:

root@linino:~# ls /sys/bus/iio/devices/iio:device0
dev                  in_voltage_A2_raw    in_voltage_A5_raw
enable               in_voltage_A2_scale  in_voltage_A5_scale
in_voltage_A0_raw    in_voltage_A3_raw    name
in_voltage_A0_scale  in_voltage_A3_scale  subsystem
in_voltage_A1_raw    in_voltage_A4_raw    uevent
in_voltage_A1_scale  in_voltage_A4_scale

- to read the voltage value of the input A0, you can execute the follwoing comamnd:

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

- to get resolution (in microVolts):

root@linino:~# cat /sys/bus/iio/devices/iio:device0/in_voltage_A0_scale
4882

you will get 4882uV, that is 5V / 1024

- all analog input values are referenced to AVcc=5V.

I2C on lininoIO

With lininoIO you can also read sensors data from i2c devices, through sysfs. Before starting it would be appropriate to install i2c-tools, which helps to identify the device address:

opkg update
opkg install i2c-tools

Below a list of devices ready to use with lininoIO:

SHT20 Humidity - Temperature

get the address of the i2c device through i2cdetect

i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

Next register the sht21 driver

echo sht21 0x40 > /sys/bus/i2c/devices/i2c-0/new_device

Then list all the fields of the device

ls /sys/bus/i2c/devices/0-0040/
driver           humidity1_input  hwmon            modalias         name             subsystem        temp1_input      uevent

Finally you can read the sensor data:

cat /sys/bus/i2c/devices/0-0040/humidity1_input

MAG3110 Magnetometer

get the address of the i2c device through i2cdetect

i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- 0e -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

Next register the mag3110 driver

echo mag3110 0x0e > /sys/bus/i2c/devices/i2c-0/new_device

Then list all the fields of the device (the number of devices depends on the number of devices already registered)

ls /sys/bus/iio/devices/iio\:device0/
buffer                        in_magn_x_calibbias           in_magn_z_calibbias           name                          trigger
dev                           in_magn_x_raw                 in_magn_z_raw                 sampling_frequency_available  uevent
in_magn_sampling_frequency    in_magn_y_calibbias           in_temp_raw                   scan_elements
in_magn_scale                 in_magn_y_raw                 in_temp_scale                 subsystem

Finally you can read the sensor data:

cat /sys/bus/iio/devices/iio\:device0/in_magn_x_raw

MPL3115A2 Precision Altimeter

get the address of the i2c device through i2cdetect

i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:            -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

Next register the mpl3115 driver

echo mpl3115 0x60 > /sys/bus/i2c/devices/i2c-0/new_device

Then list all the fields of the device (the number of devices depends on the number of devices already registered)

ls /sys/bus/iio/devices/iio\:device0/
buffer             in_pressure_raw    in_temp_raw        name               subsystem          uevent
dev                in_pressure_scale  in_temp_scale      scan_elements      trigger

Finally you can read the sensor data:

cat /sys/bus/iio/devices/iio\:device0/in_pressure_raw

MMA8491 Accelerometer

get the address of the i2c device through i2cdetect

i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:            -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- 55 -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

Next register the mma8491 driver

echo mma8491 0x55 > /sys/bus/i2c/devices/i2c-0/new_device

Then list all the fields of the device (the number of devices depends on the number of devices already registered)

ls /sys/bus/iio/devices/iio\:device0/

TODO list of fields

Finally you can read the sensor data:

cat /sys/bus/iio/devices/iio\:device0/in_accel_x_calibbias

GPIO mapping on lininoIO

BOARD GPIO
GPIO n. OUTPUT
104 D8
105 D9
106 D10
107 D11
114 D5
115 D13
116 D3
117 D2
120 D4
122 D12
123 D6
LUCKY SHIELD
GPIO OUTPUT shield
204 gpio204 LED 1
205 gpio205 LED 2
206 gpio206 RELE 1
207 gpio207 RELE 2
208 gpio208 JOY_U
209 gpio209 JOY_D
210 gpio210 JOY_L
211 gpio211 JOY_R
212 gpio212 JOY_C
213 gpio213 BTN 1
214 gpio214 BTN 2
DIGITAL-IO SHIELD
GPIO OUTPUT shield
216 gpio216 IN 1
217 gpio217 IN 2
218 gpio218 IN 3
219 gpio219 IN 4
220 gpio220
221 gpio221
222 gpio222
223 gpio223
224 gpio224 OUT1 (RELAYS)
225 gpio225 OUT2 (RELAYS)
226 gpio226 OUT3 (RELAYS)
227 gpio227 OUT4 (RELAYS)
228 gpio228 OUT5
229 gpio229 OUT6
230 gpio230 OUT7
231 gpio231 OUT8
/var/www/wiki.linino.org/data/pages/wiki/lininoio_sysfs.txt · Last modified: 2014/10/23 08:58 by administrator

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