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

Modificatino during test esp. voltage sensor

parent 7bd98cee
No related branches found
No related tags found
1 merge request!3Apsct production
......@@ -55,7 +55,7 @@ class I2C:
return ret_ack, ret_value
def read_last_reg(self, bytes_to_read):
def read_last_reg(self, bytes_to_read, print_on = DEBUG):
bus = smbus.SMBus(self.bus_nr)
rd_value = []
ret_value = ''
......@@ -68,12 +68,12 @@ class I2C:
except IOError:
ret_ack = 0
rd_value.append(0)
if DEBUG:
print("Reading error")
if print_on:
print(f"Reading IOerror {rd_value}")
except err:
ret_ack = 0
rd_value.append(0)
if DEBUG:
if print_on:
print("Reading error")
for cnt in range(bytes_to_read):
ret_value += (hex(rd_value[cnt])[2:])
......
......@@ -406,6 +406,8 @@ class ApsctSensors:
if not (15 < self.temperature < 50):
result = False
print(f"Error temperature read {self.temperature:4.2f} °C")
else:
print(f"OK temperature read {self.temperature:4.2f} °C")
return result
def read_voltage(self, input_channel=0):
......@@ -422,9 +424,8 @@ class ApsctSensors:
if DEBUG:
stri = "Word to select sens input is 0x{0:x}".format(channel_select_word)
print(stri)
sleep(0.2)
self.dev_i2c_sensor.write_bytes(channel_select_word, 0xB8)
sleep(0.2)
sleep(0.3) # Wait for device to take snapshot
ret_ack, ret_value = self.dev_i2c_sensor.read_last_reg(3)
if DEBUG:
stri = "Return value input 0 : 0x{0} ".format(ret_value)
......@@ -434,10 +435,11 @@ class ApsctSensors:
else:
steps = (int(ret_value, 16) & 0x1FFFFF) >> 6
voltage = one_step * steps
voltage = ((4.7+2.2)/2.2)*2*voltage
voltage = ((4.7+2.2)/2.2)*2*voltage # Resistor network + half swing
if DEBUG:
string = "Voltage sens line {1} is {0:.4f} V".format(voltage, input_channel)
print(string)
sleep(0.2) # wait for device to go to sleep
return voltage
def read_temp(self):
......@@ -448,9 +450,12 @@ class ApsctSensors:
#
Vref = 3.0
temp_slope = 93.5E-6 * 2**(16+1) / Vref
sleep(1.0)
self.dev_i2c_sensor.write_bytes(0xA0, 0xC0)
sleep(1.0)
ret_ack = self.dev_i2c_sensor.write_bytes(0xA0, 0xC0)
sleep(0.5)
self.temperature = 9999
loops = 0
while (self.temperature > 100 ) & (loops < 2):
loops = loops + 1
ret_ack, ret_value = self.dev_i2c_sensor.read_last_reg(3)
if ret_ack:
raw_value = (int(ret_value, 16) & 0x1FFFFF) >> 6
......@@ -458,6 +463,7 @@ class ApsctSensors:
self.temperature = temperature_K-273
else:
self.temperature = 9999
sleep(0.2)
return self.temperature
class PpsClass:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment