Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

11 Accelerometer

5. Dezember 2011

Kalibrierung (horizontale Lage) Auf die drei Achsen wirken folgende Kräfte: X=0g, Y=0g, Z=1g $3F = 64

import processing.serial.*;  // Import the Processing Serial Library for communicating with arduino
Serial myPort;               // The used Serial Port

int xVal,yVal,zVal;
int xPosition;

void setup()
{
background(0);
size(500, 500);
println(Serial.list()); // Prints the list of serial available devices (Arduino should be on top of the list)
myPort = new Serial(this, Serial.list()[0], 9600); // Open a new port and connect with Arduino at 9600 baud
}

void draw()
{
if(xPosition>=width)
{
xPosition = 0;
background(0);
}else{
stroke(255,0,0);
strokeWeight(3);
point(xPosition,xVal+height/2);
stroke(0,255,0);
strokeWeight(3);
point(xPosition,yVal+height/2);
stroke(0,0,255);
strokeWeight(3);
point(xPosition,zVal+height/2);
xPosition++;
}
println(xVal +"\t"+yVal +"\t"+zVal);

}

void serialEvent(Serial myPort) // Is called everytime there is new data to read
{
if (myPort.available() > 0)
{
String completeString = myPort.readStringUntil(10); // Read the Serial port until there is a linefeed/carriage return
if (completeString != null) // If there is valid data insode the String
{
trim(completeString); // Remove whitespace characters at the beginning and end of the string
String seperateValues[] = split(completeString, "\t"); // Split the string everytime a delimiter is received
xVal = int(seperateValues[0]);
yVal = int(seperateValues[1]);
zVal = int(seperateValues[2]);
}
}
}