Adafruit ht16k33

Python auf Einplatinencomputer wie Raspberry Pi, Banana Pi / Python für Micro-Controller
Antworten
steven@seesen
User
Beiträge: 2
Registriert: Sonntag 16. September 2018, 12:58

Hallo und Hi Python Forum,

Heute sind meine ersten Gehversuche mit Python und einen Raspberry Zero.

Ziel soll sein, eine kleine Uhr zu bauen, mit Temp/Luftfeuchtigkeit und dimmbaren 7 Segment Display

Auf der haben Seite
Rasp. Zero W
DHT 22
Adafruit 7 segment (ht16k33)

Probleme fangen aber schon bei dem ersten example an, das ist der Beispielcode von der Adafruit webseite.

Code: Alles auswählen

import time

# Import all board pins.
import board
import busio

# Import the HT16K33 LED segment module.
from adafruit_ht16k33 import segments


# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# Create the LED segment class.
# This creates a 7 segment 4 character display:
#display = segments.Seg7x4(i2c)
# Or this creates a 14 segment alphanumeric 4 character display:
#display = segments.Seg14x4(i2c)
# Finally you can optionally specify a custom I2C address of the HT16k33 like:
display = segments.Seg7x4(i2c, address=0x72)

# Clear the display.
display.fill(0)

# Can just print a number
display.print(42)
time.sleep(2)

# Or, can set indivdual digits / characters
# Set the first character to '1':
display[0] = '1'
# Set the second character to '2':
display[1] = '2'
# Set the third character to 'A':
display[2] = 'A'
# Set the forth character to 'B':
display[3] = 'B'
Als Ausgabe gibt es aber nur eine Fehlermeldung....

Code: Alles auswählen


display.print(42)
            ^
SyntaxError: invalid syntax

Nun geht es zu verstehen, warum SyntaxError...
Könnte mich einer auf die richtige Spur lenken.

Mfg Steven
Benutzeravatar
__blackjack__
User
Beiträge: 14325
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

@steven@seesen: Du versuchst das mit Python 2 auszuführen, wo ``print`` ein Schlüsselwort ist und daher nicht als Name verwendet werden kann/darf. Entweder Du verwendest Python 3, oder Du musst noch ein ``from __future__ import print_function`` als ersten Import in dem Quelltext machen, dann ist auch in Python 2.7 `print` ein ganz normaler Name.
„Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.“ — Brian W. Kernighan
steven@seesen
User
Beiträge: 2
Registriert: Sonntag 16. September 2018, 12:58

Nabend und Hallo @__blackjack__

Das wäre ja "einfach", ich probiere es morgen einmal aus. Wer weiß was dann nicht geht wenn Python 3 am start ist.
Antworten