Bus 1-wire
De MicElectroLinGenMet.
Sommaire |
Description
1-Wire (aussi connu sous le nom de bus Dallas ou OneWire) est un bus conçu par Dallas Semiconductor qui permet de connecter (en série, parallèle ou en étoile) des composants avec seulement deux fils (un fil de données et un fil de terre). De nature similaire à I²C, il présente cependant des vitesses de transmission et un coût inférieurs. Il est généralement utilisé pour des thermomètres ou autres instruments de mesure météorologiques. (Source: Wikipedia)
Voir autre article Bus 1-wire sur Linksys Wrt54gl.
Composants
DS2480B Driver de ligne série DS18B20 Température avec précision DS2405 Adressable switch DS2406 Adressable switch + 1kbit memory DS2438 Temperature, A/D Battery Monitor DS2450 1-Wire Quad A/D Converter DS2408 8-channel, programmable I/O DS2406P Double PIO DS2409P Architecture 1-wire en étoile DS2423P 4 RAM du kbit 1-Wire avec compteur DS2401 Numéro de série unique 1-wire
Interfaces
DS9490R 1-Wire Bus Master USB Adapter DS9097U-009 UNIVERSAL 1-W COM PORT ADAPTER W/ID DS9097 Adaptateur de type passif (http://rosset.org/linux/temperature/howto2.html) CD4007 Interface simple sur port COM.
Interface passive équivalente DS9097
Interface à base de composants discrets.
Interface active DS9097U
Cette interface utilise un circuit Max232 et le DS2480B qui est un convertisseur série vers 1-wire dédié.
- Brochage du DS2480B
Ce CI est sous la forme de boitier SO8. Il est possible de le soudé sur un adaptateur DIL8/SO8 pour faciliter son utilisation.
- Shéma de câblage
Cette interface est aussi vendue montée.
Interface 1-wire/USB DS9490R
- Sous Linux blacklister le module kernel ds2490
Créer un fichier /etc/modprobe.d/ds2490.conf contenant:
blacklist ds2490
- Test avec owfs version 2.7p27
# /usr/local/bin/owserver --error_print 1 --error_level 1 -p 4304 -u
Voir messages dans syslog:
Nov 15 14:50:31 vesta OWFS[3472]: CONNECT: ow_ds9490.c:USB_next(623) Adapter found: 003/006 Nov 15 14:50:31 vesta OWFS[3472]: DEFAULT: ow_ds9490.c:DS9490_sub_open(555) Opened USB DS9490 adapter at 003/006. Nov 15 14:50:31 vesta OWFS[3472]: DEFAULT: ow_ds9490.c:DS9490_detect_found(415) Set DS9490 003/006 unique id to 81 E1 BC 2C 00 00 00 B8 Nov 15 14:50:31 vesta OWFS[3472]: CONNECT: ow_ds9490.c:DS9490_detect_low(336) USB DS9490 1/1 successful bound
Filesytem owfs:
# /usr/local/bin/owfs --allow_other -s localhost:4304 /mnt/owfs
# l /mnt/owfs total 0 drwxrwxrwx 1 root root 8 nov. 14 23:42 81.E1BC2C000000/ drwxr-xr-x 1 root root 8 nov. 14 23:42 bus.0/ drwxr-xr-x 1 root root 8 nov. 14 23:42 settings/ drwxr-xr-x 1 root root 8 nov. 14 23:42 statistics/ drwxr-xr-x 1 root root 30 nov. 14 23:42 structure/ drwxr-xr-x 1 root root 8 nov. 14 23:42 system/ drwxr-xr-x 1 root root 8 nov. 14 23:42 uncached/
- Connectique
Schéma de sortie du DS9490R dans un RJ11 6 contacts:
Pin Signal Name Déscription 1 VDD 5VDC output 2 GND Terre 3 OW 1-wire data 4 GND_OW 1-wire Return 5 SUSO USB Suspend Output 6 N.C. Rien
Utilisation sous Linux
Test interface passive et sonde de température DS18B20
Datasheet: DS18B20
L'interface passive est reliée au port ttyS1 (fonctionne aussi avec un adaptateur USB/série).
Utilisation du programme digitemp (existe sous forme de package sous Debian SID)
- Interrogation du bus
# digitemp_DS9097 -s /dev/ttyS1 -i DigiTemp v3.3.2 Copyright 1996-2004 by Brian C. Lane GNU Public License v2.0 - http://www.brianlane.com Turning off all DS2409 Couplers .. Searching the 1-Wire LAN 28FC1D80010000F3 : DS18B20 Temperature Sensor 2832DD7F010000B6 : DS18B20 Temperature Sensor ROM #0 : 28FC1D80010000F3 ROM #1 : 2832DD7F010000B6 Wrote .digitemprc
Deux DS18B20 relié au bus.
- Lecture température
# digitemp_DS9097 -s /dev/ttyS1 -a DigiTemp v3.3.2 Copyright 1996-2004 by Brian C. Lane GNU Public License v2.0 - http://www.brianlane.com Mar 31 13:12:56 Sensor 0 C: 23.88 F: 74.97 Mar 31 13:12:57 Sensor 1 C: 23.62 F: 74.53
Attention: si utilisateur autre que root erreur CRC Failed à la lecture alors que les droits sont bons sur le ttyS1 !
- Mise en forme dans un fichier log
# digitemp_DS9097 -s /dev/ttyS1 -q -a -d 10 -n 50 -o "%b %d %H:%M:%S Sensor #%s %.2C°" -l /var/log/temperature
# tail /var/log/temperature Apr 05 14:24:24 Sensor #0 22.19° Apr 05 14:24:25 Sensor #1 18.31° Apr 05 14:24:34 Sensor #0 22.19° Apr 05 14:24:35 Sensor #1 18.31° Apr 05 14:24:45 Sensor #0 22.19° Apr 05 14:24:46 Sensor #1 18.31° Apr 05 14:24:54 Sensor #0 22.25° Apr 05 14:24:55 Sensor #1 18.31° Apr 05 14:25:04 Sensor #0 22.19° Apr 05 14:25:05 Sensor #1 18.31°
Test interface active et sonde de température DS18B20
Voir autre article Bus 1-wire sur Linksys Wrt54gl.
Le montage est reliée au port ttyS1 et un Circuit Max232 adapte les niveaux RS232 au 5V.
Utilisation du programme digitemp.
# digitemp_DS9097U -s /dev/ttyS1 -i DigiTemp v3.3.2 Copyright 1996-2004 by Brian C. Lane GNU Public License v2.0 - http://www.brianlane.com Turning off all DS2409 Couplers . Searching the 1-Wire LAN 2828108001000007 : DS18B20 Temperature Sensor ROM #0 : 2828108001000007 Wrote .digitemprc
# digitemp_DS9097U -s /dev/ttyS1 -a DigiTemp v3.3.2 Copyright 1996-2004 by Brian C. Lane GNU Public License v2.0 - http://www.brianlane.com Apr 28 23:32:28 Sensor 0 C: 21.25 F: 70.25
# digitemp_DS9097U -s /dev/ttyS1 -a -q -o "%.2C" 19.31
Utilisation de owfs
owfs est un ensemble de programmes pour gérer les composants 1-wire sous Linux.
Voir autre article Bus 1-wire sur Linksys Wrt54gl avec owfs
- Installation sous Debian
Modop. dispo. sur http://perso.ens-lyon.fr/sebastien.mei/wiki/doku.php?id=documentations:owfs&s=owfs
- Listes des programme disponibles
Daemon et utilitaires:
/usr/local/bin/owdir /usr/local/bin/owfs /usr/local/bin/owftpd /usr/local/bin/owhttpd /usr/local/bin/owmon /usr/local/bin/ownet.php /usr/local/bin/owpresent /usr/local/bin/owread /usr/local/bin/owserver /usr/local/bin/owtap /usr/local/bin/owwrite
Modules OwNet
Lib C: /usr/local/lib/libownet.so PHP: /usr/local/bin/ownet.php Python: /usr/lib/python2.4/site-packages/ownet PERL: /usr/local/share/perl/5.8.8/OWNet.pm
- Utilisation
Aide:
$ owserver --help 1-WIRE access programs by Paul H Alfille and others. Syntax: owserver [options] device clientport Help resources: owserver --help This page owserver --help=device Bus master device options owserver --help=program Program services (mountpoint, port) owserver --help=cache Cache and communication timing owserver --help=job Job control and debugging owserver --help=temperature Temperature scale and device format options man owserver man page for this program and man pages for individual 1-wire devices e.g. 'man DS2409' Copyright 2003-8 GPLv2. See http://www.owfs.org for support, downloads
Lancement du daemon:
# owserver -p 4304 -d /dev/ttyS1
4304 est le port par defaut.
ou
# owserver --error_print 1 --error_level 5 -p 4304 -d /dev/ttyS1
Information
--error_level n Choose verbosity of error/debugging reports 0=low 9=high
--error_print n Where debug info is placed 0-mixed 1-syslog 2-console
Montage du FS virtuel (en donnant l'accès à tout le monde):
# owfs --allow_other -s localhost:4304 /mnt/owfs
Cela permet d'accéder aux composants 1-wire par l'intermédiaire de fichiers.
# l /mnt/owfs total 0 drwxrwxrwx 1 root root 8 avr 11 16:19 28.FC1D80010000/ drwxr-xr-x 1 root root 8 avr 8 16:30 alarm/ drwxr-xr-x 1 root root 8 avr 8 16:30 bus.0/ drwxr-xr-x 1 root root 8 avr 8 16:30 settings/ drwxrwxrwx 1 root root 8 avr 11 16:19 simultaneous/ drwxr-xr-x 1 root root 8 avr 8 16:30 statistics/ drwxr-xr-x 1 root root 30 avr 8 16:30 structure/ drwxr-xr-x 1 root root 8 avr 8 16:30 system/ drwxr-xr-x 1 root root 8 avr 8 16:30 uncached/
Lecture de la température du composant DS18B20 (28.FC1D80010000):
# cat /mnt/owfs/28.FC1D80010000/temperature
22.625
Ou avec une autre commande:
# owread -s localhost:4304 28.FC1D80010000/temperature
22.125
- Exemple d'utilisation du module Perl
Man: http://owfs.org/index.php?page=ownet-pm
#!/usr/bin/perl -w use strict; use warnings; use OWNet ; my $DS18B20_1="28.FC1D80010000" ; my $owserver = OWNet->new( "localhost:4304" ) ; printf("%.2f\n", $owserver->read( "/$DS18B20_1/temperature" ) );
dan@vesta:~$ ./test_ownet.pl 22.62
DS2405 Adressable switch
Circuit d'entrée/sortie (PIO)
Brochage et Documentation
- Datasheet
- Brochage
Shéma du cablâge de test
Lecture avec owfs
- Le DS2405 apparait sous l'id 05.3A9233000000
$ l /mnt/owfs/ total 0 drwxrwxrwx 1 root root 8 mai 2 23:39 05.3A9233000000/ drwxr-xr-x 1 root root 8 mai 2 23:21 alarm/ drwxr-xr-x 1 root root 8 mai 2 23:21 bus.0/ drwxr-xr-x 1 root root 8 mai 2 23:21 settings/ drwxr-xr-x 1 root root 8 mai 2 23:21 statistics/ drwxr-xr-x 1 root root 30 mai 2 23:21 structure/ drwxr-xr-x 1 root root 8 mai 2 23:21 system/ drwxr-xr-x 1 root root 8 mai 2 23:21 uncached/
- Vu des registres du circuit sous OWFS
$ ls /mnt/owfs/05.3A9233000000/ address crc8 family id locator PIO present r_address r_id r_locator sensed type
- Utilisation du DS2405 en sortie
OUT:
echo 1 > /mnt/owfs/05.3A9233000000/PIO => ~Gnd echo 0 > /mnt/owfs/05.3A9233000000/PIO => ~5V (avec R 10k de pullup.)
- Utilisation du DS2405 en entrée
IN:
echo 0 > /mnt/owfs/05.3A9233000000/PIO => necessaire pour lire l'entrée. cat /mnt/owfs/05.3A9233000000/sensed ; echo 1 => ~2.4V - 5V cat /mnt/owfs/05.3A9233000000/sensed ; echo 0 => ~Gnd
sensed remis à jour que tout les ~10s, lire dans uncached/05.3A9233000000/sensed pour valeur courante !
Exemple d'utilisation avec un capteur pyro-électrique
J'ai suivi l'idée d'un internaute sur le forum de : www.touteladomotique.com pour reprendre la partie capteur de mouvement d'une lampe halogène HS. En fait, seule partie alimentation/relais était grillée.
Le détecteur pyro. fonctionne encore. il suffit de l'alimenter en Gnd + 5V (même si sa tension de fonctionnement était de 8V) et de relever le signal de détection sur la troisième broche ( 0V pas de détection, ~5V => détection).
- Shéma du montage
- Vue du montage en test
DS2406 Adressable switch + 1kbit memory
Circuit d'entrée/sortie (PIO) fonctionnant comme le DS2405 et possédant une zone mémoire en plus.
Brochage et Documentation
- Datasheet
- Brochage
Lecture avec owfs
- Le DS2406 apparait sous l'id 12.xxxxxx000000
$ l /mnt/owfs/ $ owdir /12.29435F000000 /12.8B515F000000 /bus.0 /settings /system /statistics /structure /alarm
- Vu des registres du circuit sous OWFS
$ ls /mnt/owfs/12.29435F000000 address crc8 id latch.ALL latch.BYTE memory PIO.A PIO.B power r_address r_locator sensed.ALL sensed.BYTE TAI8570 channels family latch.A latch.B locator pages PIO.ALL PIO.BYTE present r_id sensed.A sensed.B set_alarm type
Voir le man DS2406 pour le détails des registres (extrait):
SPECIAL PROPERTIES
channels
read-only, unsigned integer
Is this a 1 or 2 channel switch? The DS2406 comes in two forms, one has only one PIO pin (PIO.A). Returns 1 or 2.
latch.A latch.B latch.ALL latch.BYTE
read-write, yes-no
The activity latch is set to 1 with the first negative or positive edge detected on the associated PIO channel.
Writing any data will clear latch for all (both)) channels. This is a hardware "feature" of the chip.
ALL references both channels simultaneously, comma separated
BYTE references both channels simultaneously as a single byte, with channel A in bit 0.
memory
read-write, binary
128 bytes of non-volatile, write-once data.
pages/page.0 ... pages/page.3 pages/page.ALL
read-write, binary
Memory organized as 4 pages or 32 bytes. Memory is write-once.
ALL is the aggregate of all 4 pages, sequentially accessed.
PIO.A PIO.B PIO.ALL PIO.BYTE
read-write, yes-no
State of the open-drain output ( PIO ) pin. 0 = non-conducting (off), 1 = conducting (on).
Writing zero will turn off the switch, non-zero will turn on the switch. Reading the PIO state will return the switch setting. To determine the actual logic level at the
switch, refer to the sensed property.
ALL references both channels simultaneously, comma separated.
BYTE references both channels simultaneously as a single byte, with channel A in bit 0.
power
read-only, yes-no
Is the DS2406 powered parasitically =0 or separately on the Vcc pin =1
sensed.A sensed.B sensed.ALL sensed.BYTE
read-only, yes-no
Logic level at the PIO pin. 0 = ground. 1 = high (~2.4V - 5V ). Really makes sense only if the PIO state is set to zero (off), else will read zero.
ALL references both channels simultaneously, comma separated.
BYTE references both channels simultaneously as a single byte, with channel A in bit 0.
PIO.B, sensed.B ne sont utilisables que pour le modèle DS2406 en boitier TSOC.
- Utilisation du DS2406 en sortie
OUT:
echo 1 > /mnt/owfs/12.8B515F000000/PIO.A => ~Gnd echo 0 > /mnt/owfs/12.8B515F000000/PIO.A => ~5V (avec R 10k de pullup.)
- Utilisation du DS2406 en entrée
IN:
echo 0 > /mnt/owfs/12.8B515F000000/PIO.A => necessaire pour lire l'entrée. cat /mnt/owfs/12.8B515F000000/sensed.A ; echo 1 => ~2.4V - 5V cat /mnt/owfs/12.8B515F000000/sensed.A ; echo 0 => ~Gnd
sensed remis à jour que tout les ~10s, lire dans uncached/12.8B515F000000/sensed.A pour valeur courante !
Exemple d'utilisation pour piloter une VMC
Deux DS2406 sont utilisés pour piloter les commandes marche/arrét ainsi que le changement de vitesse de la VMC .
L'interface de commande 220V est faite avec 2 relais opto-couplés (kit T505 vendu sur gotronic.fr. L'option de pouvoir arréter manuellement la VMC est toujours possible puisque un interrupteur est mis en série avec le relais marche/arrét de la VMC.
L'isolation de l'opto-couplage n'est pas utilisé ici puisque la commande opto. et relais utilise la même masse, mais le montage est néanmoins isolé du 220V avec les relais.
La carte supportant les DS2406 en autre est placée dans un boitier pour rail DIN.
Le câble apportant le 1-wire plus le 12v est relié sur RJ45 au boitier électrique.
- Photos de l'installation
- Shéma éléctronique
Shéma 1-wire avec une partie du kit relais
Shéma partie kit relais
- Partie logiciel
Pour piloter la VMC, le programme va écouter les messages XPL provenant du récepteur RF rfxcom concernant l'humidité de la salle de bain (lu par une sonde Oregon thgr228n ) et déclenchera la seconde vitesse de la VMC en conséquence. La VMC pourra être aussi coupée logicielement.
Le programme utilisera la librairie C xPL: xPLLib ainsi que l'API C fourni avec owfs.
EN COURS ...
DS2438 Temperature, A/D Battery Monitor
Brochage et Documentation
- Datasheet
- Brochage
Shéma du cablâge de test
Lecture avec digitemp
- Recherche des composants sur le bus
$ digitemp_DS9097 -s /dev/ttyS1 -i DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane GNU Public License v2.0 - http://www.digitemp.com Turning off all DS2409 Couplers . Searching the 1-Wire LAN 26D050E7000000FF : DS2438 Temperature, A/D Battery Monitor ROM #0 : 26D050E7000000FF Wrote .digitemprc
- Lecture du DS2438
Par default, affiche la valeur VAD en pourcentage comme si un capteur d'humidité était connecté
$ digitemp_DS9097 -s /dev/ttyS1 -qa Apr 25 18:15:45 Sensor 0 C: 22.22 F: 71.99 H: 20%
En mode "raw" (Option -A), affiche la témpérature et les 2 tensions VDD, AD.
$ digitemp_DS9097 -s /dev/ttyS1 -qA -t0 Apr 25 18:18:08 Sensor 0 VDD: 5.09 AD: 1.03 C: 22.28
- Vu du cablâge
L'entrée VAD est reliée à un Module capteur humidite SY-HS-230
Lecture avec owfs
Voir page sur le DS2480 sous OWFS connecté au Wrt54gl
DS2450 Quad A/D Converter
Brochage et Documentation
- Datasheet
- Brochage
Lecture avec owfs
Avec l'interface passive:
- Détection DS2450 sur le bus
$ l /mnt/owfs total 0 drwxrwxrwx 1 root root 8 mai 24 18:15 20.70E50D000000/ drwxr-xr-x 1 root root 8 mai 24 18:14 alarm/ drwxr-xr-x 1 root root 8 mai 24 18:14 bus.0/ drwxr-xr-x 1 root root 8 mai 24 18:14 settings/ drwxrwxrwx 1 root root 8 mai 24 18:15 simultaneous/ drwxr-xr-x 1 root root 8 mai 24 18:14 statistics/ drwxr-xr-x 1 root root 30 mai 24 18:14 structure/ drwxr-xr-x 1 root root 8 mai 24 18:14 system/ drwxr-xr-x 1 root root 8 mai 24 18:14 uncached/
- Registres du DS2450
$ l /mnt/owfs/20.70E50D000000/ total 0 -r--r--r-- 1 root root 16 mai 24 18:14 address drwxrwxrwx 1 root root 8 mai 24 18:17 alarm/ -r--r--r-- 1 root root 2 mai 24 18:14 crc8 -r--r--r-- 1 root root 2 mai 24 18:14 family -r--r--r-- 1 root root 12 mai 24 18:14 id -r--r--r-- 1 root root 16 mai 24 18:14 locator -rw-rw-rw- 1 root root 32 mai 24 18:17 memory drwxrwxrwx 1 root root 8 mai 24 18:17 pages/ -rw-rw-rw- 1 root root 1 mai 24 18:17 PIO.A -rw-rw-rw- 1 root root 7 mai 24 18:17 PIO.ALL -rw-rw-rw- 1 root root 1 mai 24 18:17 PIO.B -rw-rw-rw- 1 root root 1 mai 24 18:17 PIO.C -rw-rw-rw- 1 root root 1 mai 24 18:17 PIO.D -rw-rw-rw- 1 root root 1 mai 24 18:17 power -r--r--r-- 1 root root 1 mai 24 18:17 present -r--r--r-- 1 root root 16 mai 24 18:14 r_address -r--r--r-- 1 root root 12 mai 24 18:14 r_id -r--r--r-- 1 root root 16 mai 24 18:14 r_locator drwxrwxrwx 1 root root 8 mai 24 18:17 set_alarm/ -r--r--r-- 1 root root 32 mai 24 18:14 type -r--r--r-- 1 root root 12 mai 24 18:17 volt2.A -r--r--r-- 1 root root 51 mai 24 18:17 volt2.ALL -r--r--r-- 1 root root 12 mai 24 18:17 volt2.B -r--r--r-- 1 root root 12 mai 24 18:17 volt2.C -r--r--r-- 1 root root 12 mai 24 18:17 volt2.D -r--r--r-- 1 root root 12 mai 24 18:17 volt.A -r--r--r-- 1 root root 51 mai 24 18:17 volt.ALL -r--r--r-- 1 root root 12 mai 24 18:17 volt.B -r--r--r-- 1 root root 12 mai 24 18:17 volt.C -r--r--r-- 1 root root 12 mai 24 18:17 volt.D
- Lecture canal A
$ cat /mnt/owfs/20.70E50D000000/volt.A ; echo
2.0405
- Lecture des 4 canaux analogiques en silmutané
$ cat /mnt/owfs/20.70E50D000000/volt.ALL ; echo
2.03331, 0.117814, 0.049532, 0.043985
- Lecture en direct canal A
$ cat /mnt/owfs/uncached/20.70E50D000000/volt.A ; echo
2.46418
$ cat /mnt/owfs/uncached/20.70E50D000000/volt.A ; echo
3.39247
$ cat /mnt/owfs/uncached/20.70E50D000000/volt.A ; echo
4.27046
$ cat /mnt/owfs/uncached/20.70E50D000000/volt.A ; echo
4.27264
$ cat /mnt/owfs/uncached/20.70E50D000000/volt.A ; echo
1.15049
$ cat /mnt/owfs/uncached/20.70E50D000000/volt.A ; echo
0.172815
$ cat /mnt/owfs/uncached/20.70E50D000000/volt.A ; echo
0.0473445






