Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
erolfr
@erolfr
is this a normal time? Or I do something wrong
Timo Furrer
@timofurrer
Can you check how long it takes to read the sensor file directly?
erolfr
@erolfr
its an raspi 3b+
Timo Furrer
@timofurrer
Do you know where the sensor files are?
Can you measure how long it takes to do sudo on your raspi?
time sudo echo "Hello"
erolfr
@erolfr

time cat /sys/bus/w1/devices/28-0416c21372ff
cat: /sys/bus/w1/devices/28-0416c21372ff: Ist ein Verzeichnis

real 0m0,008s
user 0m0,001s
sys 0m0,007s

pi@raspberrypi:~ $ time sudo echo "Hello"
Hello

real 0m0,131s
user 0m0,023s
sys 0m0,017s

Timo Furrer
@timofurrer
Can you read the w1_slave file from the directory?
Where it said "Is ein Verzeichnis" ?
erolfr
@erolfr

pi@raspberrypi:~ $ time cat /sys/bus/w1/devices/28-0416c21372ff/w1_slave
a0 01 4b 46 1f ff 1f 10 e6 : crc=e6 YES
a0 01 4b 46 1f ff 1f 10 e6 t=26000

real 0m0,938s
user 0m0,001s
sys 0m0,032s

sry
Timo Furrer
@timofurrer
And how long did your 5 sensor read take?
erolfr
@erolfr
like 5 seconds :D. That means is normal?
Timo Furrer
@timofurrer
Seems like it - reading the w1_slave file from the kernel modules takes almost 1s itself ... (> real 0m0,938s)
so adding up those 5 sequential sensor reads - 5 seconds seems pretty much possible
You could do some threading to read those
since it's IO, threading helps
This summer I'll take some time to implement asyncio support into w1thermsensor
that would help to if you are in an asyncio environment
erolfr
@erolfr
thank you
Timo Furrer
@timofurrer
Bitte :)
erolfr
@erolfr
w1thermsensor precision funktioniert macht in der Abfragezeit nur kein Unterschied :(
sergeantpol
@sergeantpol
Hello and thanks for that beautiful code. Do you know how can I only use the 12-bits resolution?
sergeantpol
@sergeantpol

oh I found it, Some w1 therm sensors support changing the resolution for the temperature reads. w1thermsensor enables to do so with the W1ThermSensor.set_resolution() method:

sensor = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, "00000588806a")
sensor.set_resolution(9)

Timo Furrer
@timofurrer
Great!
cf-programmers
@cf-programmers
"It also works on a Beagle Bone". Did anybody actually tested this package on BeagleBone? If yes please add the Beaglebone setup process.
Timo Furrer
@timofurrer
I haven't tried it myself. But know from other people who got it to work. Also, I've found this issue dating quite a while back: timofurrer/w1thermsensor#16
maybe it helps
I'll check if I can find more material
Haasjes
@Haasjes
Hello,
How can i separe 2 sensor values to int?
this is the code i use for 2 sensors

import time
from w1thermsensor import W1ThermSensor
sensor = W1ThermSensor()

while True:
for sensor in W1ThermSensor.get_available_sensors ():
print("Sensor %s has temperature %.2f" % (sensor.id, sensor.get_temperature()))
time.sleep(0.01)

Timo Furrer
@timofurrer
Hi @Haasjes ... I didn't quite understand. What do you want to do?
Haasjes
@Haasjes
I have 2 temp sensors, and i used the code above to read these sensors. But i want the temp value in a Integer so i can do same calulations.
im not sure how i can get only the value for these 2 temp sensors
Timo Furrer
@timofurrer
you can assign sensor.get_temperature() to a variable:
temperature = sensor.get_temperature()
Haasjes
@Haasjes
But how can u do this for 1 second sensor?
Its not temperature2 = sensor2.get_temperature() right ?
Timo Furrer
@timofurrer
no, not unless the second W1ThermSensor object is assigned to the variable sensor2
I suggest that you assign the two sensors based on the id to variable
sensor1 = W1ThermSensor(id="first-sensor-id")
sensor2 = W1ThermSensor(id="second-sensor-id")
Haasjes
@Haasjes
But when we replace a sensor with a new one, we need to manual assign the sensor id?
Timo Furrer
@timofurrer
Yes
Another way would be to unpack the list of sensors into variables (as long as the number of sensor stays the same)
sensor1, sensor2 = W1ThermSensor.get_available_sensors()
Haasjes
@Haasjes
I've almost done it, only the value in the label doesn't change. It stays around the first value when I run the program. What am I doing wrong here?

import tkinter as tk
from PIL import ImageTk
from PIL.ImageTk import PhotoImage
from tkinter import Button
from tkinter import simpledialog
from tkinter import Entry, END, Frame, Toplevel, StringVar
from tkinter import Label
from w1thermsensor import W1ThermSensor
import time

root = tk.Tk()
canvas = tk.Canvas(root, width=600, height=420, background="Black")
canvas.pack()
canvas.create_image(400, 240)

sensor1, sensor2 = W1ThermSensor.get_available_sensors()

Label3 = Label(text=sensor1.get_temperature())
Label3_window = canvas.create_window(100, 100, anchor="nw", window=Label3)

Label4 = Label(text=sensor2.get_temperature())
Label4_window = canvas.create_window(200, 200, anchor="nw", window=Label4)

root.mainloop()

Timo Furrer
@timofurrer
Well, there is no code here which would update that Label ... so it remains the initial value.