parsing integers through serial
i realise basic question, i've spent last couple of days trying figure out myself , have figured total lack of basic low-lvl programming telling me not skip on fundamentals.
problem need parse integer value python on computer arduino diecimila through serial connection , i'm amazingly confused when i'm parsing strings, bits, bytes, integers , whatever other types there are.
what need value between 700 , 2400 (pwm ms signal) , i'd parse 2 bytes instead of 4 character string containing numbers, can't seem figure out how convert integer in python 2 bytes can send arduino , convert them value again?
i've missed obvious in case i'm sorry wasting time haven't been able find documentation make sense of.
thanks in advance.
cheers
problem need parse integer value python on computer arduino diecimila through serial connection , i'm amazingly confused when i'm parsing strings, bits, bytes, integers , whatever other types there are.
what need value between 700 , 2400 (pwm ms signal) , i'd parse 2 bytes instead of 4 character string containing numbers, can't seem figure out how convert integer in python 2 bytes can send arduino , convert them value again?
i've missed obvious in case i'm sorry wasting time haven't been able find documentation make sense of.
thanks in advance.
cheers
usually send 1 byte @ time on serial.
what send on larger values this:
to send:
unsigned int value = 65535;
byte databyte1 = value & b11111111;
byte databyte2 = (value >>
& b11111111;
serial.print(databyte1);
serial.print(databyte2);
to read:
byte databyte1 = serial.read();
byte databyte2 = serial.read();
unsigned int value = databyte1;
value = value | (databyte2 <<
;
or, little bit shorter if like:
unsigned int value = 65535;
serial.print(value & 0xff);
serial.print((value >>
& 0xff);
and
unsigned int value = serial.read() | serial.read() << 8;
this arduino code, , data types, because i'm not sure how in python. hope you'll idea , write python code yourself.
what send on larger values this:
to send:
unsigned int value = 65535;
byte databyte1 = value & b11111111;
byte databyte2 = (value >>
& b11111111;serial.print(databyte1);
serial.print(databyte2);
to read:
byte databyte1 = serial.read();
byte databyte2 = serial.read();
unsigned int value = databyte1;
value = value | (databyte2 <<
;or, little bit shorter if like:
unsigned int value = 65535;
serial.print(value & 0xff);
serial.print((value >>
& 0xff);and
unsigned int value = serial.read() | serial.read() << 8;
this arduino code, , data types, because i'm not sure how in python. hope you'll idea , write python code yourself.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > parsing integers through serial
arduino
Comments
Post a Comment