Code Monkey home page Code Monkey logo

ltc2990's Introduction

LTC2990

I2C comms with Linear LTC 2990 Quad I2C Voltage, Current and Temperature Monitor

This project describes how to access and obtain register data from a LTC2990 IC. It is preconfigured to run on mode 0b1011111, it means: V1, V2, V3, V4; All Measurements per Mode, Single Acquisition and Temperature reported in Celsius.

Don't forget to read the datasheet!

Sample output:

root@raspberrypi:~# python i2c-ltc2990.py
Int. Temp. : 30 C
Voltage V1 : 3.29624918 V
Voltage V2 : 3.29624918 V
Voltage V3 : 3.29624918 V
Voltage V4 : 3.29624918 V
Vin        : 3.2949939 V

RepRap Ltd created a forked version that provides continous readings

ltc2990's People

Contributors

rfrht avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

willyouth

ltc2990's Issues

Continuous faster reading

Hi! This is really useful. Thanks!

We have used it as part of a robot project here: https://github.com/RepRapLtd/Walking-robots/tree/main/Petoi

We have made your code a Python class, and changed the A to D conversions from single shot to continuous, which makes everything faster (a read gives the last complete conversion the chip did when it's converting in a continuous internal loop).

I haven't done a pull request for this, as a pull from all of our robot code would not be very useful.

So here's the class if it would be useful to you or others:

###########################################################################################
#
# The LTC 2990 Quad I2C Voltage, Current and Temperature Monitor is used to
# measure the output from the Hall effect sensors that determine if a foot is touching a 
# surface or not.
#

# 
# LTC 2990 Quad I2C Voltage, Current and Temperature Monitor
# Retrieves LTC2990 register and performs some basic operations.
# Specs: http://www.linear.com/product/LTC2990
# Source: https://github.com/rfrht/ltc2990
#
# Copyright (C) 2015 Rodrigo A B Freire
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
# USA.
#
#--------------------------------------------------------
#
# Updated to Python3 and made into a class by
#
# Adrian Bowyer
# RepRap Ltd
# https://reprapltd.com
#
# 26 May 2022
#


class AToD:
 
 def __init__(self):
  self.bus = smbus.SMBus(1)   # 512-MB RPi the bus is 1. Otherwise, bus is 0.

# Pro tip: Ensure that ADR0 and ADR1 are grounded. Do not let them
# open. Otherwise, the i2c address will randomly change.

  self.address = 0x4c         # I2C chip address
#  self.mode = 0x5f            # Register 0x01 mode select - single aquisition
  self.mode = 0x1f            # Register 0x01 mode select - repeated aquisition
  err = ""

  try:
   if self.bus.read_byte_data(self.address, 0x01) != self.mode: # If current IC mode != program mode
    self.bus.write_byte_data(self.address, 0x01, self.mode)    # Initializes the IC and set mode
    self.bus.write_byte_data(self.address, 0x02, 0x00)    # Trigger a initial data collection
    time.sleep(1)				# Wait a sec, just for init
  except (IOError, err):
   print(err)
   
# Check for a specific bit value
   
 def GetBit(self, number, bit):
  return (number >> bit) & 1 
  
# 2 bytes to Chip temperature

 def GetTemperature(self, msb, lsb):
  msb = format(msb, '08b')
  msb = msb[3:]
  lsb = format(lsb, '08b')
  temp = msb + lsb
  temp = int(temp, 2)/16
  return temp

# 2 bytes to voltage
 
 def GetVoltage(self, msb, lsb):
  msb = format(msb, '08b')
  msb = msb[1:]
  lsb = format(lsb, '08b')
  signal = self.GetBit(int(msb, 2),6)
  #print "positive:0 negative:1 %s" %signal
  volt = msb[1:] + lsb
  volt = int(volt, 2) * 0.00030518
  return volt

# Return everything the chip knows as a printable string

 def GetAllValues(self):
  if self.mode is 0x5f:
   self.bus.write_byte_data(self.address, 0x02, 0x00) # Trigger a data collection
   time.sleep(0.1)
  r0 = self.bus.read_byte_data(self.address, 0x00) # Status
  r1 = self.bus.read_byte_data(self.address, 0x01) # Control - mode select
  r4 = self.bus.read_byte_data(self.address, 0x04) # Temp. Int. MSB
  r5 = self.bus.read_byte_data(self.address, 0x05) # Temp. Int. LSB
  r6 = self.bus.read_byte_data(self.address, 0x06) # V1, V1 - V2 or TR1 MSB
  r7 = self.bus.read_byte_data(self.address, 0x07) # V1, V1 - V2 or TR1 LSB
  r8 = self.bus.read_byte_data(self.address, 0x08) # V2, V1 - V2 or TR1 MSB
  r9 = self.bus.read_byte_data(self.address, 0x09) # V2, V1 - V2 or TR1 LSB
  ra = self.bus.read_byte_data(self.address, 0x0a) # V3, V3 - V4 or TR2 MSB
  rb = self.bus.read_byte_data(self.address, 0x0b) # V3, V3 - V4 or TR2 LSB
  rc = self.bus.read_byte_data(self.address, 0x0c) # V4, V3 - V4 or TR2 MSB
  rd = self.bus.read_byte_data(self.address, 0x0d) # V4, V3 - V4 or TR2 LSB
  re = self.bus.read_byte_data(self.address, 0x0e) # Vcc MSB
  rf = self.bus.read_byte_data(self.address, 0x0f) # Vcc LSB
  result = "Status register: " + hex(r0) + "\n"
  result += "Control register: " + hex(r1) + "\n"
  result += "Int. Temp. : " + str(self.GetTemperature(r4,r5)) + " Celsius\n"
  result += "Voltage V0 : " + str(self.GetVoltage(r6,r7)) + " V\n"
  result += "Voltage V1 : " + str(self.GetVoltage(r8,r9)) + " V\n"
  result += "Voltage V2 : " + str(self.GetVoltage(ra,rb)) + " V\n"
  result += "Voltage V3 : " + str(self.GetVoltage(rc,rd)) + " V\n" 
  result += "Supply: " + str(self.GetVoltage(re,rf) + 2.5) + " V\n"

  # If you want to use TR, use the temperature(msb,lsb) function to get the
  # value. I.e., if you have set the mode TR1 & TR2 (mode 0x5d),
  # Comment the print "Voltage" lines and uncomment these ones:
  # TR1
  # print "Temperature TR1: %s Celsius" %temperature(r6,r7)
  # TR2
  # print "Temperature TR2: %s Celsius" %temperature(ra,rb)
  
  return result

#
# Voltage on one of the four channels.
#

 def Voltage(self, channel):
  msb = channel*2 + 0x06
  lsb = msb + 1
  if self.mode is 0x5f:
   self.bus.write_byte_data(self.address, 0x02, 0x00) # Trigger a data collection
   time.sleep(0.1) # 100 ms is horribly long...
  msb = self.bus.read_byte_data(self.address, msb)
  lsb = self.bus.read_byte_data(self.address, lsb)  
  return self.GetVoltage(msb, lsb)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.