Outils pour utilisateurs

Outils du site


informatique:projets:python-cw2015

Python CW2015

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

Le CW2015 est un capteur de charge de batterie Lithium (1 cellule) avec un algorithme permettant de déterminer l'état de santé de l'accumulateur ainsi que de déclencher une alerte de seuil. Ce capteur est fabriqué par Cellwise.

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

CW2015 Datasheet

Documentation

L'ensemble du code est commenté de manière suffisamment explicite, et le code est compatible PyDOC. Un simple 'help(cw2015.cw2015)' 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_cw2015.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
# Test program to illustrate CW2015 class usage
 
import cw2015
 
if __name__ == "__main__":
 
    # Connecting to CW2015 in Debug mode
    chip = cw2015.cw2015(debug=True)
 
    # Retrieve firmware version
    chip.GetFirmwareVersion()
 
    # Retrieve battery voltage
    chip.GetCellVoltage()
 
    # Retrieve battery SoC
    chip.GetStateOfCharge()
 
    # Retrieve estimated battery runtime
    chip.GetRemainingRunTime()
 
    # Get defined alert threshhold
    chip.GetAlertThreshold()
 
    # Set alert threshold to 5%
    chip.SetAlertThreshold(5)
 
    # Perform a Quick Start on chip
    chip.SetModeRegister(chip.MODE_QSTRT)
Résultat
[DEBUG] Accessing CW2015 at address 0x62 on bus 1
 
[DEBUG] Reading firmware version
[DEBUG] > Reading 1 bytes from register 0x0
[DEBUG] > CW2015 response : [0x70]
[DEBUG] CW2015 version : 112
 
[DEBUG] Reading cell voltage
[DEBUG] > Reading 2 bytes from register 0x2
[DEBUG] > CW2015 response : [0x2F 0x6B]
[DEBUG] Cell voltage is 3682.875mV
 
[DEBUG] Reading State Of Charge
[DEBUG] > Reading 2 bytes from register 0x4
[DEBUG] > CW2015 response : [0x13 0x4A]
[DEBUG] SOC = 19.29%
 
[DEBUG] Reading Remaining Runtime
[DEBUG] > Reading 2 bytes from register 0x6
[DEBUG] > CW2015 response : [0x00 0x57]
[DEBUG] Estimated Runtime is 87 minutes (ALERT flag is off)
 
[DEBUG] Reading alert threshold from config register
[DEBUG] > Reading 1 bytes from register 0x8
[DEBUG] > CW2015 response : [0x28]
[DEBUG] Threshold set to 5%
 
[DEBUG] Setting alert threshold to 5%
[DEBUG] > Writing 1 bytes to register 0x8 [0x28]
 
[DEBUG] Configuring mode register with '0x30'
[DEBUG] > Reading 1 bytes from register 0xa
[DEBUG] > CW2015 response : [0x00]
[DEBUG] Current mode value is '0x0'
[DEBUG] > Writing 1 bytes to register 0xa [0x30]
[DEBUG] Setting mode to '0x30'

Téléchargement

Changelog

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

Outils de la page