I have connected arduinoUno with tinkerkitShiekd and tinkerkitGyroscope(64). The sensor works fine and I get the reading in arduiniIDE but I need to graph the outcome so I have installed Processing and I have tried with the coded posed in arduino.cc for tk gyro and processing. No lucky.
I get the below error: Exception in thread "Animation Thread" java.lang.NullPointerException at GyroGUIfromArduino.draw(GyroGUIfromArduino.java:100) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PApplet.run(Unknown Source) at java.lang.Thread.run(Thread.java:662)
I know that this forum is more for processing in Java than for arduino, but someone herte has got the answer for my problem
The code is as follows (Processing marks the line text("[Y] GYRO_Y speed: "+temp[1]+"°/s", 10, 70); ):
/* -------+ TinkerKit! Gyroscope Module T000062 Dashboard +------- This processing sketch grab data from an analog 2-axis Gyroscope connected to Arduino, plot the angular rate readings into a graph; then transform them into an angular position (inclination) trought integration over time, dislpaying them into gauges. Look on the product page for the Gyroscope specifiations: http://store.arduino.cc/ww/index.php?main_page=product_info&cPath=16&products_id=94 Connect the gyroscope with two Toolkit wires to the Tinkerkit! sensor shield into I0 and I1. Mount the shield over an Arduino board then upload on it the "Standard Firmata" sketch, then you are ready to go. Processing, in order to work with Firmata protocol requires that there is a library installed on your environment. Find the library here: http://www.arduino.cc/playground/Interfacing/Processing created 17 Sept 2011 by Federico Vanzati This example code is in the public domain. */
import processing.serial.*; // Enable processing to use the serial port
Serial myPort; // Create object from Serial class String myString = null; String[] temp; int lf = 10;
// Timing variables int refreshScreen = 0;
// Variables to transform data into physical measurement int rollSpeed, rollAngle, pitchSpeed, pitchAngle; int offsetX, offsetY;
// Variables for displayng data int[] y_rateVideoBuffer, x_rateVideoBuffer; String str_yAngle, str_yGyroRate, str_xAngle, str_xGyroRate;
void setup() { size(700, 440);
String portName = Serial.list()[2]; myPort = new Serial(this, portName, 57600); // wait a little to give time to Arduino to be initialized delay(500);
frameRate(30);
y_rateVideoBuffer = new int[width]; x_rateVideoBuffer = new int[width];
PFont font; font = loadFont("Monospaced.bold-26.vlw"); textFont(font);
// call the function that plot the angular velocities, with few screen settings graphMeThis(rollSpeed, y_rateVideoBuffer, 140, 300, 140); graphMeThis(pitchSpeed, x_rateVideoBuffer, 140, 100, 140); }
/* This function plot data over screen in a xPos and yPos given position. [ySpan] is expressed in pixel and indicates the heigth that you give to the graph */ void graphMeThis(float inData, int[] graphBuffer, int xPos, int yPos, int ySpan) { // For each frame the buffer that contains the older samples are shifted by one position for (int i=0; i<(width-xPos)-1; i++) graphBuffer = graphBuffer[i+1]; // Store the new entry data graphBuffer[(width-xPos)-1] = (int)map(inData, -3000, 3000, -ySpan/2, ySpan/2); //salvo il nuovo dato...che plotto alla fine del grafico stroke(#E2F520, 150); strokeWeight(2); // plot the graph that goes from right to left for (int x=(width-xPos); x>1; x--) line( x, (height-yPos)-graphBuffer[x-1], x+1, (height-yPos)-graphBuffer