adafruit / Adafruit_CircuitPython_PyBadger

Badge-focused CircuitPython helper library for PyBadge, PyBadge LC, PyGamer and CLUE
MIT License
21 stars 26 forks source link

Sensor Data #65

Open emersonsc opened 1 year ago

emersonsc commented 1 year ago

Im trying to display the Temp and humidity data using the sensors built in to the Clue, but i tried using the code bellow, but i get an error: Traceback (most recent call last): File "code.py", line 7, in File "adafruit_clue.py", line 930, in File "adafruit_clue.py", line 195, in init ValueError: P5 in use

# Write your code here :-)
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
from adafruit_pybadger import pybadger
from adafruit_clue import clue
from adafruit_bmp280 import bmp280

temperature = clue.temperature
humidity = clue.humidity

pybadger.badge_background(
    background_color=pybadger.YELLOW,
    rectangle_color=pybadger.BLUE,
    rectangle_drop=0.2,
    rectangle_height=0.6,
)

pybadger.badge_line(
    text="Stingers of Steel", color=pybadger.BLUE, scale=2, padding_above=2
)
pybadger.badge_line(text="Emerson C.", color=pybadger.YELLOW, scale=4, padding_above=4)
pybadger.badge_line(
    text="Mentor / Mechanic", color=pybadger.YELLOW, scale=2, padding_above=2
)
pybadger.badge_line(
    text="Temp: {:.1f} C".format(temperature), color=pybadger.YELLOW, scale=2, padding_above=2
)
pybadger.badge_line(
    text="Humi: {:.1f} %".format(humidity), color=pybadger.YELLOW, scale=2, padding_above=2
)
pybadger.badge_line(
    text="6642", color=pybadger.BLUE, scale=4, padding_above=10
)

display = board.DISPLAY
display.rotation = 180

pybadger.show_custom_badge()

while True:

    if pybadger.button.a:
        pybadger.show_qr_code("https://www.facebook.com/stingers6642")
        pybadger.pixels.fill(pybadger.BLUE)
    if pybadger.button.b:
        pybadger.show_custom_badge()
        pybadger.pixels.fill(pybadger.YELLOW)
emersonsc commented 1 year ago

Is this project dead?

caternuson commented 1 year ago

Only import pybadger here:

from adafruit_pybadger import pybadger
from adafruit_clue import clue

The PyBadge library will auto detect what board is being used and then import any additional libraries as needed.

The second import from the CLUE library is causing hardware that has already been initialized by the PyBadge library (via the first import) to try to be initialized a second time, but the hardware is already in use. That is what is causing the error.

See examples: https://github.com/adafruit/Adafruit_CircuitPython_PyBadger/blob/main/examples/pybadger_clue_custom_badge.py https://github.com/adafruit/Adafruit_CircuitPython_PyBadger/blob/main/examples/pybadger_clue_custom_image_badge.py