Python GUI not accepting Values from RTD sensor
Posted: 15 Mar 2024, 19:35
Hello,
I am trying to write a simple script that will create a python GUI to monitor some system voltage and current levels, along with the temperature. I figured I would start with the RTD sensor and get that working to make sure everything works.
I am using the Connect 4, with 1 AIO module. I have a simple program that is working, that reads 'RTDValue_1' and prints it to a python terminal. This mini program is working fine.
Below is the program I am having trouble with. for some reason the RTDValues do not want to be utilized with the GUI.
I am getting an error on line 43, saying AttributeError: module 'revpimodio2.io' has no attribute 'RTDValue_1'
import PySimpleGUI as sg
import time
import revpimodio2 as rpi
sg.theme('SystemDefault')
layout = [[sg.Txt('Select Desired Frequency: (1kHz-10kHz)'), sg.Slider(range=(1000,10000),default_value=1000, orientation='h', key=('frequency'), enable_events=True)],
[sg.Txt('Enter Desired Setpoint(1-100)'), sg.Slider(range=(1,100),default_value=1000, orientation='h', key=('-SETPOINT-'), enable_events=True)],
[sg.Button('Submit', bind_return_key=True)],
[sg.Txt('The first positive wave form lasts....'), sg.Txt(size=(8, 1), key='-OUTPUT1-')],
[sg.Txt('The first negative wave form lasts....'), sg.Txt(size=(8, 1), key='-OUTPUT2-')],
[sg.Txt('The rest period after the positive half is..'), sg.Txt(size=(8, 1), key='-OUTPUT3-')],
[sg.Txt('The rest period after the negitive half is..'), sg.Txt(size=(8, 1), key='-OUTPUT4-')],
[sg.Txt('Ambient Temperature: '), sg.Txt(size=(8, 1), key='RTDValue_1')],
[sg.Txt('Voltage Measurement: '), sg.Txt(size=(8, 1), key='Voltage_Input_1')],
[sg.Txt('Current Measurement: '), sg.Txt(size=(8, 1), key='Voltage_Input_2')]]
window = sg.Window('MFPC', layout, size=(1980,1080),element_justification='center',finalize=True)
window.Maximize()
while (True):
event, values = window.read(timeout=0)
if event != sg.WIN_CLOSED:
try:
# Inputs
frequency = int(values['frequency'])
if frequency < 1000 or frequency > 10000:
raise ValueError("Frequency must be between 1kHz and 10kHz")
setpoint = int(values['-SETPOINT-'])
if setpoint < 1 or setpoint > 100:
raise ValueError("Setpoint must be between 1 and 100")
# wave calculations
intermediate_setpoint = (setpoint / 100)
period = (1 / frequency)
voltage_on_time = (period * intermediate_setpoint) / 2
set_point_off = ((1 - intermediate_setpoint) * period) / 2
temper = rpi.io.RTDValue_1.value
print(temper)
x = input('Hello')
window['RTDValue_1'].update(temper)
except ValueError as e:
print(f"error:e")
else:
break
window.close()
If any python wizzards are out there any help would be great. I feel as if the program is very close.
I am trying to write a simple script that will create a python GUI to monitor some system voltage and current levels, along with the temperature. I figured I would start with the RTD sensor and get that working to make sure everything works.
I am using the Connect 4, with 1 AIO module. I have a simple program that is working, that reads 'RTDValue_1' and prints it to a python terminal. This mini program is working fine.
Below is the program I am having trouble with. for some reason the RTDValues do not want to be utilized with the GUI.
I am getting an error on line 43, saying AttributeError: module 'revpimodio2.io' has no attribute 'RTDValue_1'
import PySimpleGUI as sg
import time
import revpimodio2 as rpi
sg.theme('SystemDefault')
layout = [[sg.Txt('Select Desired Frequency: (1kHz-10kHz)'), sg.Slider(range=(1000,10000),default_value=1000, orientation='h', key=('frequency'), enable_events=True)],
[sg.Txt('Enter Desired Setpoint(1-100)'), sg.Slider(range=(1,100),default_value=1000, orientation='h', key=('-SETPOINT-'), enable_events=True)],
[sg.Button('Submit', bind_return_key=True)],
[sg.Txt('The first positive wave form lasts....'), sg.Txt(size=(8, 1), key='-OUTPUT1-')],
[sg.Txt('The first negative wave form lasts....'), sg.Txt(size=(8, 1), key='-OUTPUT2-')],
[sg.Txt('The rest period after the positive half is..'), sg.Txt(size=(8, 1), key='-OUTPUT3-')],
[sg.Txt('The rest period after the negitive half is..'), sg.Txt(size=(8, 1), key='-OUTPUT4-')],
[sg.Txt('Ambient Temperature: '), sg.Txt(size=(8, 1), key='RTDValue_1')],
[sg.Txt('Voltage Measurement: '), sg.Txt(size=(8, 1), key='Voltage_Input_1')],
[sg.Txt('Current Measurement: '), sg.Txt(size=(8, 1), key='Voltage_Input_2')]]
window = sg.Window('MFPC', layout, size=(1980,1080),element_justification='center',finalize=True)
window.Maximize()
while (True):
event, values = window.read(timeout=0)
if event != sg.WIN_CLOSED:
try:
# Inputs
frequency = int(values['frequency'])
if frequency < 1000 or frequency > 10000:
raise ValueError("Frequency must be between 1kHz and 10kHz")
setpoint = int(values['-SETPOINT-'])
if setpoint < 1 or setpoint > 100:
raise ValueError("Setpoint must be between 1 and 100")
# wave calculations
intermediate_setpoint = (setpoint / 100)
period = (1 / frequency)
voltage_on_time = (period * intermediate_setpoint) / 2
set_point_off = ((1 - intermediate_setpoint) * period) / 2
temper = rpi.io.RTDValue_1.value
print(temper)
x = input('Hello')
window['RTDValue_1'].update(temper)
except ValueError as e:
print(f"error:e")
else:
break
window.close()
If any python wizzards are out there any help would be great. I feel as if the program is very close.