• 0
Sign in to follow this  
peter h

ISNS20 negative current?

Question

HI,

I'm having trouble getting sensible output from my ISNS20.  I'm using the code below, modified for raspberry pi SPI channel 1 cs 2. 


#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (c) 2017 RS Components Ltd
# SPDX-License-Identifier: MIT License

#"""
#Interface for PmodISNS20 module (ADC7476 + Allegro ACS722).
#"""

import spidev
CAP = 'SPI'
PHY = '1x6'

class PmodISNS20:

    def __init__(self, DSPMod6):

        self.port = DSPMod6
        self.cs = 7 # self.port.pin1
      #  self.miso = self.port.pin3
      #  self.sclk = self.port.pin4

        self.spi = spidev.SpiDev()
        self.__startSPI()

    def __startSPI(self):
        if self.cs == 7: #CE1
            self.spi.open(1,2)
        elif self.cs == 8: #CE0
            self.spi.open(1,1)
        else:
            #throw exception here
            return
        self.spi.max_speed_hz = 100000
        self.spi.mode = 0b00

    def __stopSPI(self):
        self.spi.close()

    def __spiRead16(self):
            resp = self.spi.xfer2([0x00, 0x00])
            w = resp[0]
            w <<= 8
            w |= resp[1]
            return w

    def readAmps(self):
            w = self.__spiRead16()

            refV = 3.0
            lsb =  refV/4096
            mV= (w-2048)*lsb*1000
            amps = mV/66
            return amps

    def readMilliAmps(self):
            return self.readAmps() * 1000

    def cleanup(self):
            self.__stopSPI()

import time
sensor =  PmodISNS20(1)
while 1:
        print(sensor.readAmps())
        time.sleep(1)


Here is the output measuring current of a soldering station.  (120V AC)

./ISNS20.py
0.06658380681818182
33.291903409090914
-0.09987571022727272
-122.0703125
-0.13316761363636365
-177.5568181818182
-0.3329190340909091
-355.1136363636364
-0.244140625
-188.6541193181818
-0.022194602272727272
11.097301136363637
0.14426491477272727
177.5568181818182
0.18865411931818182
221.94602272727275
0.3662109375
399.5028409090909
0.2996271306818182
266.3352272727273
0.08877840909090909
55.48650568181819

I have both jumpers enabled as was suggested in another post.  

 

What is up with these readings?   

 

Thanks much,

Peter

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this