Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

  • Accelerometer ADXL335, arduino and processing

    Please check previous posts:

    https://forum.processing.org/two/search?Search=ADXL335

    You can also check under the arduino section. For code for your device, you can also explore the arduino forum.

    Kf

  • Accelerometer ADXL335, arduino and processing

    Hello everyone, I ask for help: using arduino uno and accelerometer ADXL335, you need to rewrite this code:

    float xmag, ymag = 0; float newXmag, newYmag = 0;
    void setup() { size(640, 360, P3D); noStroke(); colorMode(RGB, 1); }
    void draw() { background(0.5);
    pushMatrix(); translate(width/2, height/2, -30);
    newXmag = mouseX/float(width) * TWO_PI; newYmag = mouseY/float(height) * TWO_PI;
    float diff = xmag-newXmag; if (abs(diff) > 0.01) { xmag -= diff/4.0; } diff = ymag-newYmag; if (abs(diff) > 0.01) { ymag -= diff/4.0; } rotateX(-ymag); rotateY(-xmag);
    scale(90); beginShape(QUADS); fill(0, 1, 1); vertex(-1, 1, 1); fill(1, 1, 1); vertex( 1, 1, 1); fill(1, 0, 1); vertex( 1, -1, 1); fill(0, 0, 1); vertex(-1, -1, 1); fill(1, 1, 1); vertex( 1, 1, 1); fill(1, 1, 0); vertex( 1, 1, -1); fill(1, 0, 0); vertex( 1, -1, -1); fill(1, 0, 1); vertex( 1, -1, 1); fill(1, 1, 0); vertex( 1, 1, -1); fill(0, 1, 0); vertex(-1, 1, -1); fill(0, 0, 0); vertex(-1, -1, -1); fill(1, 0, 0); vertex( 1, -1, -1); fill(0, 1, 0); vertex(-1, 1, -1); fill(0, 1, 1); vertex(-1, 1, 1); fill(0, 0, 1); vertex(-1, -1, 1); fill(0, 0, 0); vertex(-1, -1, -1); fill(0, 1, 0); vertex(-1, 1, -1); fill(1, 1, 0); vertex( 1, 1, -1); fill(1, 1, 1); vertex( 1, 1, 1); fill(0, 1, 1); vertex(-1, 1, 1); fill(0, 0, 0); vertex(-1, -1, -1); fill(1, 0, 0); vertex( 1, -1, -1); fill(1, 0, 1); vertex( 1, -1, 1); fill(0, 0, 1); vertex(-1, -1, 1); endShape(); popMatrix(); }

    so that when you turn the accelerometer arduino sent a signal to turn the cube. I will be grateful for the code for arduino and processing

  • Processing Equivalent of analogReference()?

    Hello,

    Recently, I bought my first Arduino and ADXL335 and was able to make a basic program that calibrates the accelerometer.

    int sample = 1000;
    
    boolean isCalibrated = false;
    const int xPin = A0;
    const int yPin = A1;
    const int zPin = A2; 
    int dim = 3;
    float average[3];
    float total[3];
    
    
    void setup() {
      // initialize serial communications at 9600 bps:
      Serial.begin(9600);
      analogReference(EXTERNAL); 
    }
    
    void loop() {
    
      if (!isCalibrated) {
        for (int i = 0; i < dim; i++){
          for (int j = 0; j < sample; j++){
            if (i == 0) 
            total[i] += analogRead(xPin);        
            if (i == 1) 
            total[i] += analogRead(yPin);
            if (i == 2) 
            total[i] += analogRead(zPin);    
          }
        }
    
        for (int i = 0; i < dim; i++){
          average[i] = total[i]/sample;
        }
    
        isCalibrated = true;
      }
    
    
      Serial.print(analogRead(xPin) - average[0]);
      Serial.print("\t");
    
      Serial.print(analogRead(yPin) - average[1]);
      Serial.print("\t");
    
      Serial.print(analogRead(zPin) - average[2]);
      Serial.println();
    
      delay(10);                     
    
    }
    

    I want to translate this to Processing to some graphics stuff. Most of the stuff seems pretty easy to translate, but the one thing that has me really scared is making sure I get the equivalent of analogReference(EXTERNAL); in the sketch. On the wiring section of the ADXL, it states this It seems if I don't include this, I'll short my Arduino. After searching I can't find any equivalency of it. Does anyone know of the equivalency of what I should do?

    Thanks

  • Need a simple accelerometer visualization example!

    Hello!

    I'm doing a project using the ADXL335 accelerometer from SparkFun. The actual project I'm using P5 and it's working great. I'm running workshops in parallel and want to demo the chip in real-time but am currently out of time to build something from scratch. I'm desperate for a simple processing (or something else) sketch that takes my x, y, z values being printed to the serial port from Arduino and visualizes them in some way. Can anyone point me to anything that won't need a lot of coding time and effort just now?

    Thank you! Claudia

  • How do I get an 3-Axis Accelerometer to control processing game? - Please Help

    Hi I am very new to arduino and processing and just about understand the basics. I have a school project and I just cant get my head around it. I am using Arduino Uno

    I want to use an Accelerometer (3-5V GY-61 ADXL335 Module 3-Axis Analog Output Accelerometer Angular Transducer) to control a simple processing game. So instead of the mouse curser I want the Accelerometer to control the game by tilting left and right.

    This is the arduino code I uploaded to the board;

    const int groundpin = 18; // analog input pin 4 -- ground const int powerpin = 19; // analog input pin 5 -- voltage const int xpin = A3; // x-axis of the accelerometer const int ypin = A2; // y-axis const int zpin = A1; // z-axis (only on 3-axis models)

    void setup() { // initialize the serial communications:

    Serial.begin(9600);

    }

    void loop() { // print the sensor values: Serial.print(analogRead(xpin));

    // print a tab between values: Serial.print("\t"); Serial.print(analogRead(ypin));

    // print a tab between values: Serial.print("\t"); Serial.print(analogRead(zpin)); Serial.println();

    // delay before next reading: delay(100); }

    And here is the processing code that I am using - its a very simple game, move the penguin to overlap as many fish as you can.

    int numfish = 3; //number of fish you want in the game fish[] fishArray; //array of fish PImage bg; //background image PImage jf; //fish image PImage sb; //penguin image int fishSize = 50; //size of target fish int score = 0; //current score int timeLeft = 1000; //duration of each game (app. timeLeft / 100 in seconds) boolean gameStart = false; //if true, game is in progress PFont Font; //declaring the font used in the gameplay text int endOfGameDelayCycles = 300; //how long the end screen lasts boolean endScreenActive = false; //is the end screen currently showing? true if yes

    //setting up the game, this only runs once void setup() { size(900, 700); noCursor();

    //initializing the array fishArray = new fish[numfish]; for (int i = 0; i < numfish; i++) { fishArray[i] = new fish(); }

    //loading the images bg = loadImage("background.jpg"); jf = loadImage("fish.png"); sb = loadImage("penguin.png"); }

    //this is the loop which will keep running again and again until you stop playing void draw() { background(bg); textSize(11);

    //start game menu if (gameStart == false) { fill(255);

    ellipse(460, 300, 500, 500);
    
    fill(0);
    textSize(30);
    text("Press 'A' to start", 220, 300);
    
    if (keyPressed) {
      if (key == 'a' || key == 'A') {
        gameStart = true;
      }
    }
    

    }

    //while the game is on, between the start and end screen if ((gameStart == true) && (endScreenActive == false)) {

    for (int i = 0; i < numfish; i++)
    { 
      fishArray[i].drawfish();
    }
    movepenguin ();
    
    fill(0);
    textSize(15);
    text("Score: " + score, 20, 20);
    text("Time Left: " + timeLeft/100, 200, 20);
    

    }

    //end screen if (timeLeft < 10) { endScreenActive = true; fill(255); fill(255);

    ellipse(460, 300, 500, 500);
    
    fill(0);
    textSize(30);
    text("Well Done! Your Score is", 300, 300);
    text(score, 450, 450);
    
    endOfGameDelayCycles--;
    
    if (endOfGameDelayCycles < 5) {
      timeLeft = 2000;
      endOfGameDelayCycles = 300;
    
      gameStart = false;
      score = 0;
      endScreenActive = false;
    }
    

    } }

    //this function moves penguin when called void movepenguin () {

    //put the penguin image on the screen image(sb, mouseX, mouseY, 190, 153);

    //check whether penguin is overlapping any of the fish, if so, add the score and delete the fish for (int i = 0; i < numfish; i++) { if ((abs(mouseX - fishArray[i].getXLoc()) < 35) && (abs(mouseY - fishArray[i].getYLoc()) < 35)) { fishArray[i].setLifeStatus(false); fill(224, 27, 96); score++; } } timeLeft--; }

    //create a fish object class fish {

    //x location, y location, how long it will stay on screen, dead (0) or alive (1) float xLoc, yLoc, lifeDuration; boolean lifeStatus;

    fish() { xLoc = random(fishSize, width - (fishSize + 10)); yLoc = random(fishSize, height - (fishSize + 10));

    lifeDuration = random(25, 100);
    
    lifeStatus = true;
    

    }

    float getXLoc() { return xLoc; }

    float getYLoc() { return yLoc; }

    void setLifeStatus(boolean tempLifeStatus) { lifeStatus = tempLifeStatus; }

    void drawfish() { lifeDuration--;

    if ((lifeDuration >= 0) && (lifeStatus == true))
      image(jf, xLoc, yLoc, fishSize, fishSize);
    
    else {
      xLoc = random(fishSize, width - (fishSize + 10));
      yLoc = random(fishSize, height - (fishSize + 10));
    
      lifeDuration = random(25, 100);
    
      lifeStatus = true;
    }
    

    } }

    Thank you so much for helping if anyone can I would really appreciate it. :)

  • cureently stuck in axis rotation

    I am extremely new to processing and am currently trying to get a cube to mimic the rotation of an ADXL335 accelerometer. I have the code for Arduino sending the angle in degrees to processing and the cube responding . however the cube isn't responding the way I need it to. when rotating the accelerometer the cube rotate differently to my movement. ( when splitting up the axis the x axis mimics fine until I add the y or z axis)

    here is my code for processing

    import processing.serial.*;
    Serial myPort;  
    String SerialBuffer;
    Float X = 0.0;
    Float Y = 0.0;
    Float Z = 0.0;
    float[] degs;
    
    void setup()
    {
    size(500,500,P3D);
    myPort = new Serial(this,"COM15",4800); 
    myPort.bufferUntil('\n');
    delay(1000);
    }
    void serialEvent (Serial myPort)
    {
      SerialBuffer = myPort.readString();
      degs = float(split(SerialBuffer, ','));
      println(" working = " + SerialBuffer + degs[1]); //print it out in the console
      X=degs[0];
      Y=degs[1];
      Z=degs[2];
    }
    void draw()
    {
      background(255);
      stroke(0);
      fill(229,131,2);
      translate(width/2,height/2);
      rotateX(-PI*degs[0]/180);   // x axis works 
      rotateY(PI*degs[1]/180);
      rotateZ(-PI*(degs[0]+degs[1]/2)/180);
      rectMode(CENTER);
      box(100,20,100);
    }