Skip to content

PComp Lab: Serial Output

December 17, 2011
For this lab, I experimented with an ITG3200 gyroscope. The Arduino code looked like this:

#include <Wire.h>
#include <itg3200.h>

ITG3200 gyro;

void setup(){

void loop(){

Here’s my processing code:

float offset = 2.23;
float rot = 0.0;
import processing.serial.*;

Serial myPort;        // The serial port

void setup() {
  size(600, 800);
  myPort = new Serial(this, Serial.list()[0], 115200);

void draw() {
  translate(width/2, height/2);
  rect(-100, -300, 200, 600);

void serialEvent (Serial myPort) {
  String inString = myPort.readStringUntil('\n');
  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // convert to an int and map to the screen height:
    float inByte = float(inString); 
    inByte = inByte - offset;
    rot = inByte/-300;
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: