RTD Value
Moderator: RevPiModIO
Hello,
i am trying to print the current value of the RTDValue_1 every millisecond, and in the end save the values in a csv sheet.
the code i used:
import revpimodio2
import threading
rpi=revpimodio2.RevPiModIO(autorefresh=True)
temp=rpi.io.RTDValue_1.value
def printit():
threading.Timer(0.1,printit).start()
print(temp)
printit()
When i run m programm the rtd value just stays the same and does not increase or decrease if i heat it up.
Best regards,
troll100
i am trying to print the current value of the RTDValue_1 every millisecond, and in the end save the values in a csv sheet.
the code i used:
import revpimodio2
import threading
rpi=revpimodio2.RevPiModIO(autorefresh=True)
temp=rpi.io.RTDValue_1.value
def printit():
threading.Timer(0.1,printit).start()
print(temp)
printit()
When i run m programm the rtd value just stays the same and does not increase or decrease if i heat it up.
Best regards,
troll100
Hi,
this behavior is correct, as the process image is never refreshed. RevPiModIO has a some nice helper funtions for cyclic tasks:
Depending on your needs it might be better to use an event based approach. For more details have a look into the examples in the RevPiModIO documentation.
Nicolai
this behavior is correct, as the process image is never refreshed. RevPiModIO has a some nice helper funtions for cyclic tasks:
Code: Select all
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import revpimodio2
class RTDDemo():
def __init__(self):
self.rpi = revpimodio2.RevPiModIO(autorefresh=True)
self.rpi.handlesignalend()
# call self.loop() on each cycle (cycletime is configurable)
self.cycleloop(self.loop)
def cycle(self):
print("RTD value: {}".format(self.rpi.io.RTDValue_1.value)
if __name__ == "__main__":
root = RTDDemo()
root.start()
Nicolai
when i run your Code exactly as you wrote it down, i always get an syntaxerror in the "if __name___ == "main":"
I am not familiar with classes and functions in python
I am not familiar with classes and functions in python
I see that I missed a closing bracket in the line with the print statement. Should be
Code: Select all
def cycle(self):
print("RTD value: {}".format(self.rpi.io.RTDValue_1.value))
okay, so how i now call the method ccycle that prints the value of RTD...?
e.g.
a=RTDDemo.cycle()
print(a) does not work. cause cycle needs a positional argument. but what kind of argument :/
e.g.
a=RTDDemo.cycle()
print(a) does not work. cause cycle needs a positional argument. but what kind of argument :/
My fault, here is hopefully the correct version:
Code: Select all
def cycle(self, ct):
print("RTD value: {}".format(self.rpi.io.RTDValue_1.value))
Now i get an Attribute error… RTDDemo has no Attribute rpi …
how would you call the method that gives you the rdtvalue ?
I think im too stupid to get it ...
how would you call the method that gives you the rdtvalue ?
I think im too stupid to get it ...
Hi,
there were some additional mistakes in the code, because I have written it on the mobile. So here is a tested snippet, which also has some comments:
If you want to process the data further, I would recommend to extend the cycle() method.
Nicolai
there were some additional mistakes in the code, because I have written it on the mobile. So here is a tested snippet, which also has some comments:
Code: Select all
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import revpimodio2
class RTDDemo():
def __init__(self):
# create new instance of revpimodio2
self.rpi = revpimodio2.RevPiModIO(autorefresh=True)
# handle ctrl+c and ensure a clean shutdown
self.rpi.handlesignalend()
# start main loop, which calls self.cycle() on each cycle (cycletime is configurable)
self.rpi.cycleloop(self.cycle)
def cycle(self, ct):
# read value of RTDValue_1
value = self.rpi.io.RTDValue_1.value
# print value to stdout
print("RTD value: {}".format(value))
if __name__ == "__main__":
# create new instance of the RTDDemo class above
app = RTDDemo()
Nicolai
Hey Nicolai,
thanks for your efforts.
Now the pogramm runs; and the temp in the Output Changes.
But only when i define rpi = revpimodio2.RevPiModIO(autorefresh=True) before the class RTDDemo()
Witout this i get the traceback RTDDemo hast no attribute rpi.
thanks for your efforts.
Now the pogramm runs; and the temp in the Output Changes.
But only when i define rpi = revpimodio2.RevPiModIO(autorefresh=True) before the class RTDDemo()
Witout this i get the traceback RTDDemo hast no attribute rpi.