loading

Step 3: Test the code and calibrate sensor range

1.Use the following code in processing:

import processing.serial.*;
import cc.arduino.*;

Arduino arduino; //creates arduino object

color back = color(64, 218, 255); //variables for the 2 colors

int sensor= 0;
int read;

float value;


void setup() {
  size(800, 600);
  arduino = new Arduino(this, Arduino.list()[0], 57600); //sets up arduino
    arduino.pinMode(sensor, Arduino.INPUT);//setup pins to be input (A0 =0?)
   
    background(back);
}

void draw() {
 
 
  read=arduino.analogRead(sensor);
  background(back);
  println (read);
  value=map(read, 0, 680, 0, width); //use to callibrate  
  ellipse(value, 300,30, 30);
  

}


2. Use the “println” command to output your sensor’s minimum and maximum values. They will be different depending on the context. Plug the min and max values in your map() function.
<p>Instead of an accelerometer, I'm using a gyroscope. The circuit is basically the same as an accelerometer. I have a functioning circuit but when combined with processing it is not working. It is reading 0 values</p>
<p>Hi, </p><p>Nice work here.</p><p>Can you help me with plotting xyz values on Processing ? I am using an ADXL345. I am quite new to Embedded systems and processing ... </p><p>Would appreciate any help ..thanks</p>
<p>I am receiving 0 values all across the board when I put the first sample code in.</p>
<p>Hi Zac,</p><p>I think it depends on which accelerometer you are using. The connections might be different. If you are not getting any values it might be that the accelerometer is connected wrong (see image for a different accelerometer).</p><p>I made a more detailed manual here: <a href="http://snebtor.org/sensing4viz/sensing_for_visualization_big.pdf" rel="nofollow">http://snebtor.org/sensing4viz/sensing_for_visuali...</a></p>
<p>Here is the link to some information i've found.</p><p>I've had the same issue using analogRead(A0);<br>You can translate the a0 pin to a 14, a1 to 15 and so on until a7 wich is 21.</p><p><br>http://electronics.stackexchange.com/questions/67087/analogread0-or-analogreada0</p>
<p>Good catch! -Thank you. I got confused when they added the A1 thing</p>

About This Instructable