ADC overo 2.6.39+

From Gumstix User Wiki
Revision as of 00:48, 19 September 2011 by Alxx (Talk | contribs) (Using the ADC's)

Jump to: navigation, search

Using the ADC's

From posts in the mailing list by Steve Sakoman and others

The madc driver is now upstream and in the process it moved to the hwmon subsystem. It is now even easier to access using the /sys/class interface:

root@omap3-multi:~# ls /sys/class/hwmon/hwmon1/device/

curr10_input in11_input in3_input in7_input power

driver in12_input in4_input in8_input subsystem

hwmon in15_input in5_input in9_input temp1_input

in0_input in2_input in6_input modalias uevent

root@omap3-multi:~# cat /sys/class/hwmon/hwmon1/device/temp1_input

56

root@omap3-multi:~# cat /sys/class/hwmon/hwmon1/device/curr10_input

-750

ADC's via a system call

a quick and very nasty way to access them is by a system call

C

system("cat /sys/class/hwmon/hwmon1/device/in7_input");

Python

os.system("cat /sys/class/hwmon/hwmon1/device/in7_input")

ADC's via sysfs in code

Python

import os

import sys

import subprocess

cmd1 = "cat /sys/class/hwmon/hwmon1/device/in7_input"

process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)

os.waitpid(process.pid, 0)[1]

udata = process.stdout.read().strip()

print udata

In console (in interactive mode)

python

Python 2.6.6 (r266:84292, Sep 1 2011, 13:08:10)

[GCC 4.3.3] on linux2

>>> import os

>>> import sys

>>> import subprocess

>>> cmd1 = "cat /sys/class/hwmon/hwmon1/device/in7_input"

>>> process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)

>>> os.waitpid(process.pid, 0)[1]

0

>>> udata = process.stdout.read().strip()

>>> print udata

1388

>>>

==


Building your own kernel

When building your own kernel Make sure your defconfig has CONFIG_TWL4030_MADC and CONFIG_SENSORS_TWL4030_MADC and make sure your rootfs has the module.

Link to kernel docs for Kernel driver twl4030-madc http://www.sakoman.com/cgi-bin/gitweb.cgi?p=linux-omap-2.6.git;a=blob;f=Documentation/hwmon/twl4030-madc-hwmon;h=ef7984317cecb29eca6ef23a30c21d920e66ef31;hb=refs/heads/omap-2.6.39-pm