Zeig mal dein ganzes Script, evtl ein Copy-Paste-Fehler? Oder such mal z.B. hiermit https://www.soscisurvey.de/tools/view-chars.php nach unsichtbren Zeichen.
Python
#!/usr/bin/env python
import time
from ina226 import INA226
DATA_FILE = '/home/pi/data.txt'
def measure(sensor):
"""Read voltage, current and power from the given sensor and
return these along with a unix timestamp in a four element tuple
(timestamp first).
"""
voltage = sensor.get_voltage()
current = sensor.get_current()
power = sensor.get_power()
return time.time(), voltage, current, power
def save(data, filename):
"""This saves all values from the collection 'data' as a
new line to the file 'filename', each separated by a comma.
"""
with open(filename, 'a+') as f:
f.write(','.join(str(val) for val in data))
def main():
"""Main Function. Available parameters for the INA226 class:
sensor = INA226(debug=False, adr=0x40, bus=1)
This function initializes the sensor, reads voltage, current
and power and saves these along with a timestamp in DATA_FILE.
"""
sensor = INA226()
data = sensor.measure()
save(data, DATA_FILE)
if __name__ == '__main__':
main()
Alles anzeigen