Skip to content
Snippets Groups Projects
Commit ffab720b authored by Gijs Schoonderbeek's avatar Gijs Schoonderbeek
Browse files

Added script reading Voltage sensor

parent c2de62f0
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ READ_LOCK = True
READ_ALL = False
CHECK_EEPROM = True
PWR_RST = True
READ_SENSOR = True
CLK_FREQ = '200MHz'
dev_i2c_eeprom = I2C(0x50)
......@@ -203,6 +204,41 @@ def wr_rd_eeprom(value=0x34):
print(stri)
return True
def apsct_sensors():
addr = 0x74
Vref = 3.0
one_step = Vref/(2**(16+1))
I2C_device = I2C(addr, BUSNR=I2CBUSNR)
I2C_device.write_bytes(0xB8, 0xB0)
sleep(1)
ret_ack, ret_value = I2C_device.read_last_reg(3)
if ret_ack:
stri = "Return value input 0 : 0x{0} ".format(ret_value)
print(stri)
if int(ret_value, 16) >= 0xC00000:
print("over range")
else:
steps = (int(ret_value, 16) & 0x1FFFFF) >> 6
voltage = one_step * steps
string = "Voltage is {0:.4f}".format(voltage)
print(string)
else:
print("ACK nok")
sleep(1)
temp_slope = 93.5E-6 * 2**(16+1) / Vref
I2C_device.write_bytes(0xA0, 0xE0)
sleep(1)
ret_ack, ret_value = I2C_device.read_last_reg(3)
if ret_ack:
raw_value = (int(ret_value, 16) & 0x1FFFFF) >> 6
temperature_K = (raw_value/temp_slope)
temperature = temperature_K-273
stri = "Return value : 0x{0} Temperature : {1:.2f} gr. C".format(ret_value, temperature)
print(stri)
else:
print("ACK nok")
if CHECK_EEPROM :
wr_rd_eeprom()
......@@ -228,3 +264,5 @@ if READ_LOCK:
else:
print("Not locked --> PLL Error")
if READ_SENSOR:
apsct_sensors()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment