GithubHelp home page GithubHelp logo

Comments (4)

RobTillaart avatar RobTillaart commented on June 11, 2024

@Maratinhos

I quickly changed one of the examples, it compiles but not tested with hardware (yet).
please give it a try. If it works for you I will add it to the library

//
//    FILE: GY521_two_sensors.ino
//  AUTHOR: Rob Tillaart
// PURPOSE: read angleX, angleY, angleZ from two sensors

#include "GY521.h"

GY521 sensor1(0x68);
GY521 sensor2(0x69);

uint32_t counter = 0;

void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.println(__FILE__);
  Serial.print("GY521_LIB_VERSION: ");
  Serial.println(GY521_LIB_VERSION);

  Wire.begin();

  //  INITIALIZE SENSOR 1
  delay(100);
  while (sensor1.wakeup() == false)
  {
    Serial.print(millis());
    Serial.println("\tCould not connect to sensor1");
    delay(1000);
  }
  sensor1.setAccelSensitivity(2);  //  8g
  sensor1.setGyroSensitivity(1);   //  500 degrees/s

  sensor1.setThrottle();
  Serial.println("start...");

  //  set calibration values from calibration sketch.
  sensor1.axe = 0.574;
  sensor1.aye = -0.002;
  sensor1.aze = -1.043;
  sensor1.gxe = 10.702;
  sensor1.gye = -6.436;
  sensor1.gze = -0.676;

  //  INITIALIZE SENSOR 2
  delay(100);
  while (sensor2.wakeup() == false)
  {
    Serial.print(millis());
    Serial.println("\tCould not connect to sensor2");
    delay(1000);
  }
  sensor2.setAccelSensitivity(2);  //  8g
  sensor2.setGyroSensitivity(1);   //  500 degrees/s

  sensor2.setThrottle();
  Serial.println("start...");

  //  set calibration values from calibration sketch.
  sensor2.axe = 0.574;
  sensor2.aye = -0.002;
  sensor2.aze = -1.043;
  sensor2.gxe = 10.702;
  sensor2.gye = -6.436;
  sensor2.gze = -0.676;
}

void loop()
{
  //  READ SENSOR 1
  sensor1.read();
  float x1 = sensor1.getAngleX();
  float y1 = sensor1.getAngleY();
  float z1 = sensor1.getAngleZ();

  //  READ SENSOR 2
  sensor2.read();
  float x2 = sensor1.getAngleX();
  float y2 = sensor1.getAngleY();
  float z2 = sensor1.getAngleZ();

  //  OPTIONAL TIME / NR
  //  Serial.print(millis);
  //  Serial.print('\t');
  //  Serial.print(counter);
  //  Serial.print('\t');
  Serial.print(x1, 1);
  Serial.print('\t');
  Serial.print(y1, 1);
  Serial.print('\t');
  Serial.print(z1, 1);
  Serial.print('\t');
  Serial.print('\t');
  Serial.print(x2, 1);
  Serial.print('\t');
  Serial.print(y2, 1);
  Serial.print('\t');
  Serial.print(z2, 1);
  Serial.println();

  counter++;
}

//  -- END OF FILE --

from gy521.

RobTillaart avatar RobTillaart commented on June 11, 2024

example is also in develop branch - https://github.com/RobTillaart/GY521/tree/develop

from gy521.

Maratinhos avatar Maratinhos commented on June 11, 2024

Perfect! It works!

from gy521.

RobTillaart avatar RobTillaart commented on June 11, 2024

you're welcome!

from gy521.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.