TypeError with Cartesian
MBottinIUT opened this issue · 7 comments
Hi,
I tried to add a Cartesian to a ST7735 display.
All the elements (axis, tick, labels...) appear, but when I tried to add some points, I've got a 'TypeError' message.
I post this on Adafruit forum but someone told me to post an issue here.
This is my code
import time
import board
import displayio
import pwmio
import analogio
import busio
import adafruit_st7735r
import terminalio
from adafruit_display_text import label
from adafruit_progressbar.verticalprogressbar import (VerticalProgressBar,VerticalFillDirection,)
import adafruit_simplemath
from adafruit_displayio_layout.widgets.cartesian import Cartesian
luminosite_led = pwmio.PWMOut(board.LED)
potentiometre = analogio.AnalogIn(board.A0)
displayio.release_displays()
# Création des objets nécessaires au pilotage de l'écran
bus_spi = busio.SPI(clock=board.GP10, MOSI=board.GP11, MISO=board.GP12)
bus_affichage = displayio.FourWire(bus_spi, command=board.GP15, chip_select=board.GP13, reset=board.GP14)
ecran = adafruit_st7735r.ST7735R(bus_affichage, width=160, height=128, colstart=2, rowstart=1, rotation=90, bgr=True)
# Création du groupe pour les éléments graphiques sur l'écran
groupe_elements = displayio.Group()
# Création d'un label de texte
Valeur_volt = label.Label(terminalio.FONT, text="V = +x.xx V", color=0xFFFFFF, x=55, y=5)
groupe_elements.append(Valeur_volt)
# Création d'une barre de progression verticale
niveau_tension = VerticalProgressBar((10, 18), (15, 100), direction=VerticalFillDirection.BOTTOM_TO_TOP)
groupe_elements.append(niveau_tension)
# Création d'un graphique cartésien
graphique = Cartesian(
x=50, # coordonnée x du coin supérieur gauche du graphique
y=18, # coordonnée y du coin supérieur gauche du graphique
width=100, # largeur du graphique
height=100, # hauteur du graphique
axes_color=0xFFFFFF, # couleur des axes
axes_stroke=2, # épaisseur des axes en pixels
tick_color=0xFFFFFF, # couleur des graduations
major_tick_stroke=1, # largeur des graduations en pixels
major_tick_length=5, # longueur des graduations en pixels
tick_label_font=terminalio.FONT, # police pour les graduations
font_color=0xFFFFFF, # couleur de la police
pointer_radius = 1,
)
groupe_elements.append(graphique)
# Affichage du groupe sur l'écran
ecran.show(groupe_elements)
point_x = 0
point_y = 0
while True :
# variation de la luminosité de la LED avec le potentiomètre
luminosite_led.duty_cycle = potentiometre.value
# Affichage de la tension sur l'écran
tension = round(((potentiometre.value*3.3)/65535),2)
Valeur_volt.text = f"V = +{tension} V"
# Affichage du niveau de tension
valeur_pourcentage = int(adafruit_simplemath.map_range(potentiometre.value, 0, 65535, 0, 100))
niveau_tension.value = valeur_pourcentage
# Affichage d'un point sur le graphique
point_y = valeur_pourcentage
graphique.update_pointer(10, 10)
#graphique._draw_pointers(point_x, point_y)
point_x = point_x + 1
if point_x == 100 :
pointx = 0
# Pause entre deux points de mesure
time.sleep(0.05)
Hope you can find what's wrong.
Mike
Thanks for opening an issue. This is due to an incompatibility with the current API for vectorio
module. I've created #60 to update this library to resolve it.
i tested this on a PyBadge and with the fix the simple example is working.
(i modified the position of the plan so it fits on the small pybadge 160x128 screen..)
@MBottinIUT There is work underway to draw lines in the cartesian widget. See PR #62 for the current status. I'll be looking into it more over the upcoming weekend so I will probably get merged into the library soon. But you can grab it now from the branch of that PR if you want to give it a try sooner.
Hi Mike,
i had exactly this issue:
issue #61
and created a fix and an example:
- pullrequest #62
- fixed cartesian.py
- example: examples/displayio_layout_cartesian_lineplot.py
you can copy the cartesian.py and delete the cartesian.mpy file in your library folder to test it...
FoamyGuy was faster with typing ;-)