sensor8 and sensor20 are utilities for
communicating with the DLP-IO8
and DLP-IO20
data acquisition modules. They are inexpensive, well-documented,
Linux-compatible USB devices for digital and analog I/O. Individually
controlled pins can function as any of the above, as well as being able
to read 18b20 1-wire temperature sensors. The sensor20 adds two
relays, two counters, some function-specific pins, and a more complex
and efficient protocol to these options.
These utilities allow you to use them directly from a Linux
commandline, shell script, cron job, etc. It was developed to
monitor the thermal systems of a solar house, and now is used for
greenhouses as well.
UPDATE: 0.0.2 has improved temperature handling, and by
default will wait 600 milliseconds for a valid
temperature if a DS18B20 sensor is detected.
If no sensor is detected it won't wait at all.
UPDATE: 0.0.3 has an important bugfix preventing the program
from quitting prematurely when it can't read from a
temperature sensor.
UPDATE: 0.0.4 has much better error detection for invalid
temperatures, and can take multiple readings from one
temperature sensor in a row then choose the median,
to better deal with single-bit errors and the like.
UPDATE: Added a similar sensor20 program for the related
DLP-IO20 product. It's not as polished as sensor8 yet,
but already has function for digital I/O, analog input,
temperature sensors, and the built-in relays. It ought
to support both big and little-endian systems but this
hasn't actually been tested. The interface for the
RB6/RB7 counters isn't yet finished.
UPDATE: sensor20-0.0.2 released. It's much more complete,
with functioning analog-block commands and counters.
--raw, --verbose don't work yet, those should be next.
UPDATE: sensor20-0.0.3 released. i2c support has been
added, allowing you to chain sensors and devices and
external IC's onto an IO20 module. It should be
possible to add this feature to sensor8, as well.
HUGE UPDATE:
sensor8 1.0.0 has been released. Its interface is
quite different, more similar to sensor20's. It
numbers I/O pins from 1-8 to match the device
labels, instead of 0-7. It includes I2C
support like sensor20's. It also has the --bug
switch, to workaround buggy FTDI kernel drivers.
The old-style interface is still available in
sensor8 0.0.6. It does not have I2C support.
sensor20 0.0.4 is now available, also supporting the
--bug flag, and with many improvements to the
documentation.
UPDATE: sensor20-0.0.6 has been released. It features:
More robust I2C implementation with timeouts and arbitration recovery
More I2C options(7-bit registerless communication)
Oversampling for analog values
I2C communication examples(ADXL345 accelerometer,
BMP085 barometer, HIH6130 temperature/humidity
sensor, HMC5883L magnetometer, K30 CO2
sensor)
Fixes for commandline option bugs
$ ./sensor8 --help --verbose
sensor8 v1.0.0, utility to talk to a DLP-I08 module
Written 2012 Tyler Montbriand. Freeware.
Usage: ./sensor8 ...
--device(-d) -d /dev/ttyUSB0
--mode(-m) -m 115200N81 (- means leave alone)
--verbose(-v) Enables debug output
--bug Works around kernel bug
--help(-h) Shows this listing
--raw(-r) Outputs raw bytes
--tempms(-m) Milliseconds between temp read retries
--retries(-n) Max # of tries to read a temp from a pin
--count(-c) Min # of valid temperature reads per sensor, 1-7
--lock(-l) Enables cooperative locking
--SCL What pin to use for i2c clock
--SDA What pin to use for i2c data
Valid commands:
[1-8]:I ex. 7:I, reads logic value on input 7
[1-8]:V ex. 7:V, reads analog voltage on input 7
[1-8]:T ex. 7:T, reads temperature from DS18B20 on pin 7
[1-8]:[01] ex. 1:0, sets logic 0 on pin 1
[1-8]:Z ex. 2:Z tristates pin 2
PING Pings device, waits for reply
You can string these commands together, like
3:10101010Z
...to pulse pin 3 four times, then tristate it.
D[0-9]+ ex. D100, delays 100 milliseconds
U[0-9]+ ex. U1000, delays 1000 microseconds
PING Contact the device, or quit if it can't.
$ ./sensor20 --verbose --help
SENSOR20 v0.0.6, utility to talk to a DLP-IO20 module
Written 2013 Tyler Montbriand. Freeware.
Usage: ./sensor20 ...
--help(-h) Shows this listing
--verbose(-v) Debug output and better help
--bug Workaround FTDI kernel bug
--device(-d) VAL -d /dev/ttyUSB0
--rate(-r) VAL Sample rate 1K ... 20K
Valid values 1K 2K 4K 8K 20K
--avg(-a) VAL Multi-sample analog average
Valid values 128 256 512 1024 2048 4096 8192
--lock(-l) Enables cooperative locking
--vref VAL Voltage reference for the ADC
--SDA VAL I2C data pin
Valid values AN0 AN1 AN2 AN3 AN4 AN5 AN6 AN7 AN8 AN9
AN10 AN11 AN12 AN13 RA4 P5 P6 P7 RB7 RB6
--SCL VAL I2C clock pin
Valid values AN0 AN1 AN2 AN3 AN4 AN5 AN6 AN7 AN8 AN9
AN10 AN11 AN12 AN13 RA4 P5 P6 P7 RB7 RB6
Use these commands like 'sensor20 AN7:I AN6:0 AN5:V'. Any commands
which output values will print their results to standard output, one
result to a line. If the command fails, it will print ERR instead.
PIN can be AN0-AN13, RA4, P5-P7, RB6-RB7.
SIMPLE PIN I/O:
PIN:I Read logic value from given pin, i.e. AN7:I
PIN:T Read temperature from DS1820B, i.e. AN7:T
PIN:F Like :T, but in Fahrenheit, i.e. AN7:F
PIN:'?' Detect serial number of DS18b20, i.e. AN7:'?'
PIN:[0-1] Set logic high or low on any pin, i.e. AN7:1
PIN:Z Set tri-state on any pin i.e. AN7:Z
AN[0-13]:V ex AN7, reads ADC voltage from AN7, i.e. AN7:V
Any of the above can be strung together, like AN13:010101010Z
..which will pulse AN13 four times then tristate it. The maximum
speed the IO20 can pulse a pin is on the order of 20Khz.
If you give sensor20 a --vref value, it will tell the IO20 to
use an external voltage reference attached to AN3. Otherwise,
it will assume the 5.0v internal reference. Give the INTREF
command to make sure the IO20 really is using the internal
reference if you used the external one last time.
ANALOG STREAM COMMANDS:
AN[0-13]:M(1|2|4|8|20)K:(128|256|512|1024|2048|4096|8192)
Capture many ADC samples at a given rate, i.e AN7:M4K:128
RELAY COMMANDS:
R:[1-2]:[0-1] Set or reset contacts of relay 1 or 2, i.e. R:2:0
COUNTER COMMANDS:
RB[6-7]:R Enable and reset pulse counts on RB6/RB7, i.e. RB6:R
RB[6-7]:r Same, but trigger on falling edge RB6:r
RB[6-7]:C Print pulse counts from RB6/RB7, i.e. RB7:C
LED COMMANDS:
FLASH Flash the built-in LED briefly, then keep on
LED:[0-1] Turns the built-in LED on/off, i.e. LED:0
UTILITY:
PING Checks if the IO20 is there, quits with error if not.
D:[0-9]* delay some milliseconds, i.e. D:100
U:[0-9]* Delay some microseconds, i.e. U:10000
You can't depend on greater than 10 milliseconds accuracy on
most systems.
I2C COMMANDS:
The following commands use bit-banging to communicate with 7-bit I2C
devices attached to the DLP-IO20. They expect the SCL and SDA
environment variables to specify what pins to use.
devid[reg] Read I2C register, i.e. 1d[00]
devid[reg]:n Like above but n bytes, i.e. 1d[00]:4
devid[reg]=xx Write one or more i2c registers, i.e. 1d[1e]=010203
devid[] Registerless I2C read 7f[]
devid[]:4 Like above, but n bytes, i.e. 7f[]:2
devid[]=xx Registerless i2c write of n bytes, i.e. 7f[]=2000
RAWI2C:datapin:clockpin:command,command2,command3,...
Raw I2C sequence. You can put start/stop/nack wherever
you feel appropriate. Wordy but should be capable of anything.
R Read command
W Write command
A 7-bit address
S Send start bit
P Send stop bit
N Send NACK
xx Send two hexadecimal digits
Example: Read device ID(register 00) from OSEPP
accelerometer(addr 1D)
RAWI2C:AN5:AN6:SAW1D,00,SAR1D,NRP
ENVIRONMENT VARIABLES
Many commandline values can also be exported as environment
variables instead. useful if you're using sensor20 repeatedly.
SENSOR20 Serial device to open. Defaults to /dev/ttyUSB0
SDA Which pin to use for I2C data.
SCL Which pin to use for I2C clock.
VREF What the AN3 external vref is assumed to be.
causes EXTREF command.
teal-deer:
sensor20 FLASH LED:0 # Flash built-in LED then turn it off
sensor20 R:1:0 D:100 R:1:1 # Click relay 1
sensor20 AN7:V AN6:I AN5:'?' # Read AN7 V, AN6 bit, AN5 DS18B20 serial
sensor20 AN7:01010101Z # Pulse 0 1 0 1 0 1 0 1 on AN7 then tristate it
sensor20 AN5:S D:1000 AN5:T # Start DS18B20, wait 1 second, read temp in C
sensor20 AN3:M1K:128 # Dump 128 analog samples from AN3 at 1Khz
sensor20 RB6:R D:1000 RB6:C # Enable RB6 counter, wait a sec, print count
# Read reg 00 of I2C devid 1d from pins AN5/AN6
sensor20 --SCL AN5 --SDA AN6 1d[00]
# Write 0b to reg 31 of I2C devid 1d via AN5/AN6
sensor20 --SCL AN5 --SDA AN6 1d[31]=0b
Broke your buffer? Try ./sensor20 -v -h 2>&1 | less
$