Im trying to represent the value of a sensor I have from an Arduino program using Vpython. An error occurs when changing the tube length to represent the new values. How do I fix this? The error occurs on the tube.length lines.
import time, serial
from vpython import *
arduinoData = serial.Serial("COM5", 115200)
tube = cylinder(color=color.cyan, radius=1.0, axis=vector(0, 0.2, 0))
legend = label(text="", box=False, pos=vector(0, 0.2, 0))
time.sleep(1)
while True:
# scalingFactor = vector(1, 0.1, 1) # Adjust 0.1 for desired scaling
while (arduinoData.inWaiting() == 0):
pass
dataPacket = arduinoData.readline()
dataPacket = str(dataPacket, 'utf-8')
dataPacket = (dataPacket.strip('\r\n'))
splitPacket = dataPacket.split(",")
bNum = int(splitPacket[0])
tempC = float(splitPacket[1])
tempF = float(splitPacket[2])
humidity = float(splitPacket[3])
tempC = round(tempC, 1)
tempF = round(tempF, 1)
humidity = round(humidity, 1)
print("Celcius =", tempC, "Farenheit = ", tempF, "Humidity = ", humidity, "X = ", bNum)
if bNum == 1:
tube.color = color.green
tube.length = tempC
legend.text = str(tempC) + " Celcius"
if bNum == 2:
tube.color = color.cyan
tube.length = tempF
legend.text = str(tempF) + " Fahrenheit"
if bNum == 3:
tube.color = color.blue
tube.length = humidity
legend.text = str(humidity) + " Humidity"