Ina226 i²c-Sensor Spannung und Strom auslesen und in eine Datei schreiben

Heute ist Stammtischzeit:
Jeden Donnerstag 20:30 Uhr hier im Chat.
Wer Lust hat, kann sich gerne beteiligen. ;)
  • 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.

  • Ina226 i²c-Sensor Spannung und Strom auslesen und in eine Datei schreiben? Schau mal ob du hier fündig wirst!

  • So, nun einmal den "Umweg" über Notepad++ und alle Einrückungen usw. eingefügt

    und jetzt kommt

  • Nun kommt

    Code
    root@rpi3:/home/pi/SpannungStromMesser# python3 ina226_Abfrage.py
    Traceback (most recent call last):
    File "ina226_Abfrage.py", line 42, in <module>
    main()
    File "ina226_Abfrage.py", line 37, in main
    data = sensor.measure()
    AttributeError: 'INA226' object has no attribute 'measure'
    root@rpi3:/home/pi/SpannungStromMesser#
  • Ähm 1524260921.9602647 ist doch keine Uhrzeit und Datum

    Wie kann man die Spannung auf 2 Stellen hinterm Komma und die Leistung auf 3 Stellen hinterm Komma kürzen?

    Der Strom ist ja schon auf 3 Stellen hinterm Komma ...was ich gut finde :)

  • Ähm 1524260921.9602647 ist doch keine Uhrzeit und Datum

    Hab ich auch nie gesagt. Unix-Zeitstempel sagte ich. Kannst du im Falle von Unwissen auch googlen: https://de.wikipedia.org/wiki/Unixzeit

    Wie kann man die Spannung auf 2 Stellen hinterm Komma und die Leistung auf 3 Stellen hinterm Komma kürzen?

    Auch suchen. "python round number", "python round decimal". Suchmaschinen beißen wirklich nicht. Ich kaue das hier nicht nochmal durch, sorry.

    Ich logge mich mal aus, bis irgendwann in 1-2 Wochen mal. Vielleicht hilft Pertl ja noch.

  • Jup kann gerne aushelfen, war nur die Tage bisschen viel Arbeit - die Selbstständigkeit hat mal wieder mit SELBST und STÄNDIG zugeschlagen :shy:

    Hab jetzt mal blos alles kurz überflogen - ab Montag sollte es wieder leichter gehen bei mir... Aber kurz mal eine kleine Hilfe vorab ins Blaue.

    Auch suchen. "python round number", "python round decimal". Suchmaschinen beißen wirklich nicht. Ich kaue das hier nicht nochmal durch, sorry.


    Ich logge mich mal aus, bis irgendwann in 1-2 Wochen mal. Vielleicht hilft Pertl ja noch.

    Zahlen Runden machst du am besten über die Methode format()

    Code
    gekuerzt = "{:.2f}".format(zahl)

    Die Funktion wandelt dir die Zahl in einen String um {:.2f} steht in dem Beispiel als Platzhalter eine Fließkommazahl mit 2 Nachkommastellen.

    Soweit ich das in aller kürze sehe, dürfte es zu keinen größeren Problemen kommen, wenn du anstelle einer Zahl einen String mit einer Zahl in deinem Code verwendest. Wichtig ist Zahlen immer erst ganz am Ende für die Ausgabe vorbereiten (z.B. mit format-Methode) da du mit Strings nicht rechnen kannst ;)

  • Scheint zu funktionieren :)

  • Hi to all,

    i read all this thread and also the japan source, I didn't see any reference to INA 226 calibration according to shunt resistor value, so I decided to write because I need help, and I'm not able to find anything of useful on internet.

    What I want to do is reading voltage and current of battery and in the same way voltage and current produced by a solar panel (it's a self powered remote installation). I bought this board https://www.espruino.com/INA226 for the scope, board is correctly detected from raspberry

    Code
    pi@raspberrypi:~/dev/testina/i2c_sensor $ i2cdetect -y 1
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --

    But when I try to read values I get useless results

    I'm trying to read 12V and a load of approximately 0,2 A, tried different calibration values in script, firstly the original japan code (that is for 0,002 ohm shunt) and others, but results is always the same, no usable values. Tried also other two boards, so faulted board is excluded.

    Any help will be appreciated, thanks
    FunMan

  • Please write in German as this is the German Raspberry pi forum ;)

    Unfortunately I don't know German, I'm Italian and I think that it's better to write in a reasoned english rather than italian to german google translated one. The reason I write here is because this is the only thread I found about INA226 and raspberry. If english use is not allowed I remove the trouble, anyway I hope someone speaking english can help me.

    Thanks in advance

    FunMan

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!