title: Openframeworks, reading serial data from Arduino
body: <p>I'm trying to read serial data from an Arduino UNO using an <code>ofSerial</code>object and assign it as an <code>int</code>.
  I am able to read in individual bytes, however, the values I'm receiving in the openframeworks console are not the same as the values I'm reading in the Arduino serial monitor.</p>
  
  <p>I have provided screenshots of the respective consoles:</p>
  
  <p><img src="https://i.stack.imgur.com/XynCF.jpg" alt="Arduino Serial Monitor"></p>
  
  <p><img src="https://i.stack.imgur.com/lqKk1.jpg" alt="openframeworks console"></p>
  
  <p>My Arduino code is simply the basic "AnalogReadSerial" example available with the Arduino IDE.</p>
  
  <pre><code>// the setup routine runs once when you press reset:
  void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
  }
  
  // the loop routine runs over and over again forever:
  void loop() {
      // read the input on analog pin 0:
      int sensorValue = analogRead(A0);
      // print out the value you read:
      Serial.println(sensorValue);
      delay(1);        // delay in between reads for stability
  }
  </code></pre>
  
  <p>Whereas my C++ code is mostly copied from the documentation for the <a href="http://openframeworks.cc/documentation/communication/ofSerial.html#show_readByte" rel="nofollow noreferrer">ofSerial readByte</a> function.</p>
  
  <pre><code>void serialReader::setup()
  {
      serial.listDevices();
      vector &lt;ofSerialDeviceInfo&gt; deviceList = serial.getDeviceList();
  
      serial.setup("COM4", 9600); //open the first device and talk to it at 9600 baud
  }
  
  
  void serialReader::printByteToConsole()
  {
      int myByte = 0;
      myByte = serial.readByte();
      if ( myByte == OF_SERIAL_NO_DATA )
          printf("\nno data was read");
      else if ( myByte == OF_SERIAL_ERROR )
          printf("\nan error occurred");
      else
          printf("\nmyByte is %d ", myByte);
  }
  </code></pre>
  
  <p>Any insight into what may be causing this disparity between the readings would be greatly appreciated. Thank you.</p>