Arduino serial communication with computer

Hello.

I made program with python to pc, and want to send variables to arduino. Arduino would be only for moving servos, servo positions come from computer.

Some reason, i can send numeric value to arduino so that it understand it and move servo right it should, but not value of variable. Also, i get numbers and text from arduino to computer, but some reason numbers wont work right way in code on python, like IF statement X==1 would not work, but X=="text" will work.

From python i send data with command
Arduino.write(str(X).encode('ascii'))

And read in arduino with
X=Serial.parseFloat();

See Serial Input Basics - updated

Thanks, was interesting, but i dont think there was solution for my problem.

I mean i can send numeric value to arduino so it understand it, but if i try send value of variable, some reason that value wont work like number, but more like text.

Example if x=70, and i send it to arduino with command
Arduino.write(str(x).encode('ascii')
Arduino will print value 70 with using Serial.println comand, but it just dont work like number in any if or while function, or nothing else function.

You ARE sending the number as text. You have to convert the text into a number before using it.

Serial Input Basics describes how to do that, and in addition explains how you can be sure where the number is, within the text string.

No, nothing works.

Ok. I get almost everything working with firmata, but i think there is something wrong with my arduino, maybe also with servos, or at least 2 of them are in bad condition and making crackling sound.

Any case, i get every servos moving when i connect only that servo. With firmata test program and my own have same result when testing, 1 good servo connected and it works perfect, also these crackling servos turning with noise when connected alone, but 2 servos connected and its hard to say if they moving right they should, 3 servos connected and not even 1 goes right it should, if even moving at all. I use external power suply for servos so there is no broblem with usb power.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.