Python Forum

Full Version: ValueError: could not convert string to float
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Greetings
I'm new to Python and I wrote a little program and I get an error meseg:

Error:
Traceback (most recent call last):    File "C: / Users / micha / Downloads / arduino-python project / ultrasonic sensor", line 11      distance = float (myData) ValueError: could not convert string to float
Can someone explain to me why I'm not doing okay?
Thanks
miki

import serial 
from visual import * 

arduinoSerialData = serial.Serial('com5', 9600) 
measuringRod = cylinder( title="My Meter", radius= .5, length=6, color=color.yellow, pos=(-3,0,0))
while (1==1):  
    rate(20)
    if (arduinoSerialData.inWaiting()>0):  
        myData = arduinoSerialData.readline() 
        print myData 
        distance = float(myData) 
        measuringRod.length=distance
What's myData? This error seems pretty clear, and you definitely need to provide more detail for us. Ideally you would reproduce your problem without any imports.