Outils pour utilisateurs

Outils du site


informatique:projets:python-ads1115

Python ADS1115

python-ads1115 est une classe d'abstraction permettant de communiquer avec un ADS1115 via le bus i2c (d'un Raspberry Pi par exemple).

L'ADS1115 est un petit convertisseur analogique/numérique 16bit 4 ports fabriqué par Texas Instruments.

Une version pour MicroPython est également disponible (uads1115). Cette version reprend le même code que la version classique mais sans les commentaires et options de debug afin d'être la plus légère possible.

Cette classe possède un mode 'debug' qui permet d'obtenir un certain nombre de messages utiles (communication avec le circuit, résultat de mesures, etc…).

ADS1115 Datasheet

Documentation

L'ensemble du code est commenté de manière suffisamment explicite, et le code est compatible PyDOC. Un simple 'help(ads1115.ads1115)' devrait permettre d'avoir un minimum d'informations sur la syntaxe.

Un programme de test est fourni à titre d'exemple et permet de voir le fonctionnement de la classe.

test_ads1115.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
# Test program to illustrate ADS1115 class usage
 
import ads1115
 
if __name__ == "__main__":
 
  # Connecting to ADS1115 in Debug mode
  chip = ads1115.ads1115(debug=True)
 
  # Read single ended on port 0 (FSR=6144, SPS=860)
  chip.ReadSingleEnded()
 
  # Read single ended on port 1 (FSR=4096, SPS=128)
  chip.ReadSingleEnded(port=1, fsr=4096, sps=128)
 
  # Read differential between ports 0 and 1
  chip.ReadDifferential()
 
  # Read differential between ports 0 and 1 (FSR=4096, SPS=64)
  chip.ReadDifferential(ports='0-1', fsr=4096, sps=64)
Résultat
[DEBUG] Accessing ADS1115 at address 0x48 on bus 1
 
[DEBUG] Reading single ended measurement on port 0 with FSR=6144mV
[DEBUG] > Writing 2 bytes to register 0x1 [0xC1 0xE3]
[DEBUG] > Reading 2 bytes from register 0x0
[DEBUG] > ADS1115 response : [0x25 0x70]
[DEBUG] Voltage on port 0 is 1797.0mV
 
[DEBUG] Reading single ended measurement on port 1 with FSR=4096mV
[DEBUG] > Writing 2 bytes to register 0x1 [0xD3 0x83]
[DEBUG] > Reading 2 bytes from register 0x0
[DEBUG] > ADS1115 response : [0x12 0x4C]
[DEBUG] Voltage on port 1 is 585.5mV
 
[DEBUG] Reading differential measurement on ports 0-1 with FSR=6144mV
[DEBUG] > Writing 2 bytes to register 0x1 [0x81 0xE3]
[DEBUG] > Reading 2 bytes from register 0x0
[DEBUG] > ADS1115 response : [0x29 0x3D]
[DEBUG] Differential voltage on ports 0-1 is 1979.4375mV
 
[DEBUG] Reading differential measurement on ports 0-1 with FSR=4096mV
[DEBUG] > Writing 2 bytes to register 0x1 [0x83 0x63]
[DEBUG] > Reading 2 bytes from register 0x0
[DEBUG] > ADS1115 response : [0x3D 0xDC]
[DEBUG] Differential voltage on ports 0-1 is 1979.5mV

Téléchargement

Changelog

informatique/projets/python-ads1115.txt · Dernière modification : 2022/11/27 17:19 de lestat

Outils de la page