First attempt at Python: working towards temp senor with ScrollHD display


#1

I am trying to embed the core temperature reading command within a python script, then use that output as a value to plug into a formula… to convert C to F…

This is literally my first time trying to free style in python. And it is going as well as one would suspect.

It yields

Blockquote

temp=48.3’C
Temperature: 0 Celcius = 32.0 F

Blockquote

It was a triumph to get this far but I cannot figure out where I am going wrong. Any help?

Once I get this building block learned, I will start to look into outputting to Scroll HD


#2

This is because os.system() doesn’t return the output of the command, but rather the status code.

The status code for “Ran without error, exited cleanly” is 0. So your Celcius value will always be 0.

0 Celcius is - according to your conversion formula (9.0/5.0 * 0 + 32) - 32 Farhenheit, which would mean the rest of your code is simply running as intended and you see the results 0 and 32.

You should use os.popen().read() to return the value that vcgencmd produces.

Note- vcgencmd doesn’t return a simple integer, but rather the text string: temp=xx.x'C so you will need to find a way to parse the actual temperature out of this string and convert it to a number.


#3

Could a type conversion work, like int(x)? I’m unclear how much can be shelled

Int(os.system(“/int…”))

?
I’ll have to try it when I get home to my Pi


#4

Okay here’s where I’m at

My output is then:

TypeError: unsupported operable tyoe(s) for *: ‘int’ and ‘file’

I see that the os command is working because it writes:

temp=46.2’C

so I’ve captured/created a file and written it but it’s still not an integer… I’m a bit confused on how to manipulate a file


#5

Could it be a python formatting thing? From mine: (and my reading is a float, not an int but I’m sure you could format it without the decimal places if that’s what you want? Or convert the values from Python?)

print(‘Humidity: {0:0.2F}% Temperature: {1:0.2F}C’.format(humidity, temperature))


#6

os.popen().read() <-- the read() bit is super important, otherwise you’re just opening a process and not actually reading its return value.