Hi ,
I want to use a gauge with serial readline() but the interval trigger one time only why ?
this is my code
thanks
Marc
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
import dash_daq as daq
import psutil
import serial
import time
ser = serial.Serial(‘COM29’, 9600)
time.sleep(2)
app = dash.Dash()
app.layout = html.Div([
daq.Gauge(
id='my-gauge',
label="Default",
value=2,
max=5,
min=0),
dcc.Interval(
id='interval-component',
interval=1000, # 1000 milliseconds = 1 seconds
n_intervals=0),
])
@app.callback(Output(‘my-gauge’, ‘value’),
[Input('interval-component', 'n_intervals')])
def update_outout(value):
time.sleep(0.1)
b = ser.readline() # read a byte string
string_n = b.decode() # decode byte string into Unicode
string = string_n.rstrip() # remove \n and \r
flt = float(string)
value = flt*(5.0 / 1023.0) # convert string to float
print(value)
return (value)
if name == ‘main’:
app.run_server()