Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8026

Automation, sensing and robotics • Re: Can't measure resistors

$
0
0

Code:

 import boardimport busioimport timeimport adafruit_ads1x15.ads1115 as ADSfrom adafruit_ads1x15.analog_in import AnalogInimport RPi.GPIO as PiGPIOi2c = busio.I2C(board.SCL, board.SDA)ads = ADS.ADS1115(i2c, gain=1, data_rate=860)ads.mode = 00PiGPIO.setmode(PiGPIO.BCM)PiGPIO.cleanup()shunt = 330PiGPIO.setup(23, PiGPIO.OUT)PiGPIO.setup(24, PiGPIO.OUT)PiGPIO.setup(27, PiGPIO.OUT)PiGPIO.setup(22, PiGPIO.OUT)PinSwitch = False    count = 0while True:    PiGPIO.output(23, PinSwitch)       PiGPIO.output(27, PinSwitch)    PiGPIO.output(24, not PinSwitch)    PiGPIO.output(22, not PinSwitch)    time.sleep(.5)    chan = AnalogIn(ads, ADS.P0)    chan2 = AnalogIn(ads, ADS.P1)    chan3 = AnalogIn(ads, ADS.P2)        if PinSwitch == True:                 MaxVoltage1= chan3.voltage         loadVoltage1 = chan.voltage         shuntVoltage1 = MaxVoltage1 - loadVoltage1         loadRes1 = shunt * (loadVoltage1 / shuntVoltage1)         print("load res1", loadRes1)         print(" ")    else:                MaxVoltage2 = chan2.voltage        shuntVoltage2 = chan.voltage        loadVoltage2 = MaxVoltage2 - shuntVoltage2        loadRes2 = shunt*(loadVoltage2 / shuntVoltage2)        print("load res2", loadRes2)        print(" ")            time.sleep(1)        PinSwitch = not PinSwitch
CircuitDiagram.png

Statistics: Posted by TTSB — Fri May 03, 2024 10:29 pm



Viewing all articles
Browse latest Browse all 8026

Trending Articles