Hello friends, I commented that I am developing a project that I have to read data sent by the Arduino serial communication right through to a program in python that has to take numerical data and perform math ...
But the problem in question is next, take the arduino sends data right through the serial interface as "string" but I can not with any command to convert a numeric variable of type "int" or "float" in order to perform math operations ...
If anyone can help me do this conversion or directly take the data in numerical form, I will be very Agreco, as from now thank you very much.
Here I leave the code I'm using to read the data.
#Declaracion de librerias a utilizar
import serial
import win32api
import time
import math
#Clases para la ventana
#Inicializacion Serial
ser = serial.Serial(3)
ser.baudrate = 115200
ser.bytesize = 8
ser.parities = 0
ser.stopbits = 1
ser.xonxoff = 0
ser.rtscts = 0
ser.timeout = 1
print "Inicializando..."
loopVar = True
if (ser.isOpen()):
# Inicio del programa - void loop()
cout=0
while(loopVar):
ser.write('x')
ejeX = ser.readline()
ser.write('y')
ejeY = ser.readline()
ser.write('z')
ejeZ = ser.readline()
while(cout!=1): #intento de transformar a int
try:
x = int(ejeX)
y = int(ejeY)
z = int(ejeZ)
break
except ValueError:
x = 0
y = 0
z = 0
cout = cout + 1
print " EjeX = %d EjeY = %d EjeZ = %d " % (x,y,z)
Thx! ;)