user51679: I am trying to display the values i get from reading a potentiometer (0-1023) in the program called 'processing'.
when I just use Serial.write(integer) and display the value on a line graph in 'processing' the line will max out at 256 and loop back around to 0 as i vary the potentiometer. 
I understand that this is because the serial.write can only write in bytes(8 bits) so I would need to package the 16 bit integer into 2 bytes. 
i was considering using a union but as you can probably guess i am very new to arduino so i haven't been able to make that work.
here is the code i have tried:
union Data{  uint16_t now; } data;

void setup() {   // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(A1, INPUT);


}

void loop() {   // put your main code here, to run repeatedly:
    uint16_t sensorVal = analogRead(A1);
     union Data data; 

    data.now = sensorVal;

    Serial.println(data.now);

    //Serial.write(sensorVal);
    delay(10); }


user313: You need to send the uint16_t as the two the individual bytes it is composed of, one at a time, in whatever order your Arduino code and the code on the PC agree on: (MSB first, aka, big-endian; or LSB first, aka little-endian).
Since it would be possible for the two devices to get out of sync, you may also want to package up the two bytes with a third, or "start-byte". Pick some fixed value (such as 0xCC) that has a couple of its MSbits set, then the MSB, then the LSB. Your receiver can know to look for that fixed value, then the MSB (which it knows can't have those high bits set because the analog data is only 10-bits), then the LSB (which could have any value).
The PC should only accept a three-byte packet when it has received one that fits that scheme. Otherwise it waits for another 0xCC (or whatever value you choose), collects two more bytes, and tries again.

user7689: Send the 16-bit value as two 8-bit values (with a start byte as per JRobert's answer):
Serial.write(0xCC); // Send the start byte
Serial.write((sensorVal >> 8) & 0xFF); // Send the upper byte first
Serial.write((sensorVal & 0xFF); // Send the lower byte


51679: <p>I am trying to display the values i get from reading a potentiometer (0-1023) in the program called 'processing'.</p>

<p>when I just use Serial.write(integer) and display the value on a line graph in 'processing' the line will max out at 256 and loop back around to 0 as i vary the potentiometer. </p>

<p>I understand that this is because the serial.write can only write in bytes(8 bits) so I would need to package the 16 bit integer into 2 bytes. </p>

<p>i was considering using a union but as you can probably guess i am very new to arduino so i haven't been able to make that work.</p>

<p>here is the code i have tried:</p>

<pre><code>union Data{  uint16_t now; } data;

void setup() {   // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(A1, INPUT);


}

void loop() {   // put your main code here, to run repeatedly:
    uint16_t sensorVal = analogRead(A1);
     union Data data; 

    data.now = sensorVal;

    Serial.println(data.now);

    //Serial.write(sensorVal);
    delay(10); }
</code></pre>
 313: <p>You need to send the uint16_t as the two the individual bytes it is composed of, one at a time, in whatever order your Arduino code and the code on the PC agree on: (MSB first, aka, big-endian; or LSB first, aka little-endian).</p>

<p>Since it would be possible for the two devices to get out of sync, you may also want to package up the two bytes with a third, or "start-byte". Pick some fixed value (such as 0xCC) that has a couple of its MSbits set, then the MSB, then the LSB. Your receiver can know to look for that fixed value, then the MSB (which it knows can't have those high bits set because the analog data is only 10-bits), then the LSB (which could have any value).</p>

<p>The PC should only accept a three-byte packet when it has received one that fits that scheme. Otherwise it waits for another 0xCC (or whatever value you choose), collects two more bytes, and tries again.</p>
 7689: <p>Send the 16-bit value as two 8-bit values (with a start byte as per <strong>JRobert</strong>'s answer):</p>

<pre><code>Serial.write(0xCC); // Send the start byte
Serial.write((sensorVal &gt;&gt; 8) &amp; 0xFF); // Send the upper byte first
Serial.write((sensorVal &amp; 0xFF); // Send the lower byte
</code></pre>
