Transmitting large integers over serial to Arduino

Hi,

I currently have a working java program using rxtx.

I'm trying to send the arduino large numbers, say, like 1000. However any number >127 comes back as something else.

if I send it 128, I get random numbers. Sometimes 194, 195, 208.

What's going on? How do I send it larger numbers? I know there's got to be an easy solution to this..I haven't worked with C for a while.

It sounds like you are using Serial.write() which will only send 8-bit values. Perhaps you want to use Serial.print(). That will send a series of ascii digits which can be converted back into an integer value at the PC end.

Oh, no. I want to send 1000 bit values TO the arduino. I have no problems having the arduino send large values to java. I just send them as strings and convert.

It's an issue because I want to send degree values to servos, so if I want to say, send 179 to a servo, I have problems.

you must split up the integer 100 into 2 bytes on the sending site and reconstruct the int on the receiving site

sender
int x = 1000;
serial.write(x/256);
serial.write(x%256);

receiver
if (serial.available >1)
{
x = serial.read();
x = x * 256 + serial.read();
}

Thanks!

I figured out a different way: I send the integer as a string, then convert it using atoi();