Advertisement
KRITSADA

Raspberry pi OHM Meter VEC No6

Dec 24th, 2015
4,485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. import spidev
  2. import time
  3. analog_ch = 1
  4. spi = spidev.SpiDev()
  5. spi.open(0,0)
  6. Vin=3.3
  7. R1=1000
  8. def readADC(adcnum):
  9.     if adcnum > 7 or adcnum < 0:
  10.             return -1;
  11.     r = spi.xfer2([4 | 2 | (adcnum >> 2), (adcnum & 3) << 6, 0])
  12.     adcout = ((r[1] & 15) << 8) + r[2]
  13.     return adcout
  14. while True:
  15.     value = readADC(analog_ch)
  16.     voltage = value*3.3/4096
  17.     if voltage > 0:
  18.         ohm = (R1 * (Vin-voltage))/voltage
  19.         #ohm = ((Vin*R1)/voltage)-R1
  20.         print("R? = %d"  % ohm)
  21.     time.sleep(0.3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement