Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Peguino Gyrosensor Brick
#1
Peguino Gyrosensor Brick

This Peguino unit houses and delivers a gyroscope sensor for your project. It allows a broad range of toy brick project integration variations e.g. as a movement sensor, position in space, acceleration and angle of your project. You can build for example a gimbal by using three Peguino Microservo Bricks.


image coming soon...



Notes:

The Brick communicates with the I2C protocol and uses the address 0x68.

More informations soon...


Examples for Peguino Uno Nano and ESP32 V1:
Code:
/*
  Gyrosensor Brick
  (C) 2018 by Peguino LTD

  Version 0.3

  Note: Use the Serial Monitor to see the Data
  Connect a Peguino Microservo Brick on Port C1


  Peguino Uno Nano Board Pinout       Peguino Uno ESP 32 Development Board Pinout
             ┌─╥─┐                          ┌─╥─┐
     D_13  1 │     │ 30  D_12       3.3     1 │     │ 30  5V
    3.3 V  2 │     │ 29  D_11       GND     2 │     │ 29  GND
     AREF  3 │     │ 28  D_10       GPIO15  3 │     │ 28  GPIO13
 D_14 A_0  4 │     │ 27  D_9        GPIO2   4 │     │ 27  GPIO12
 D_15 A_1  5 │     │ 26  D_8        GPIO4   5 │     │ 26  GPIO14
 D_16 A_2  6 │     │ 25  D_7        GPIO16  6 │     │ 25  GPIO27
 D_17 A_3  7 │     │ 24  D_6        GPIO17  7 │     │ 24  GPIO26
 D_18 A_4  8 │     │ 23  D_5        GPIO5   8 │     │ 23  GPIO25
 D_19 A_5  9 │     │ 22  D_4        GPIO18  9 │     │ 22  GPIO33
      A_6 10 │     │ 21  D_3        GPIO19 10 │     │ 21  GPIO32
      A_7 11 │     │ 20  D_2        GPIO21 11 │     │ 20  GPIO35
       5V 12 │     │ 19  GND        GPIO3  12 │     │ 19  GPIO34
    Reset 13 │     │ 18  Reset      GPIO1  13 │     │ 18  GPIO39
      GND 14 │     │ 17  D_0 RX     GPIO22 14 │     │ 17  GPIO36
 Power In 15 │     │ 16  D_1 TX     GPIO23 15 │     │ 16  Chip enable
             └───┘                          └───┘
  Visit https://www.peguino.com  
*/


#include<Wire.h>
#include <math.h>
//#include <ESP32Servo.h>                       // for ESP32 Development Board V1
#include <Servo.h>                              // for Arduino Nano
const int MPU = 0x68;                           // Default I2C address for this Brick
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
double pitch, roll;
Servo servo1;
Servo servo2;
int minUs = 500;
int maxUs = 2400;
int servo1Pin = 5;
int pos1 = 0;
int servoangle01 = 950;
int servoangle02 = 0;
int servoangle02a = 0;
int servoangle02b = 0;
int servoangle02c = 0;
int servoangle02d = 0;
int servoangle02e = 0;
int servoangle03 = 0;


void setup() {
  Serial.begin(9600);
  Serial.println("Peguino Gyrosensor");
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  servo1.attach(servo1Pin, minUs, maxUs);      // In this example we use Port C1
}
void loop() {
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 14, true);

  int AcXoff, AcYoff, AcZoff, GyXoff, GyYoff, GyZoff;
  int temp, toff;
  double t, tx, tf;

  //Acceleration data correction
  AcXoff = -950;
  AcYoff = -300;
  AcZoff = 0;

  //Temperature correction
  toff = -1600;

  //Gyro correction
  GyXoff = 480;
  GyYoff = 170;
  GyZoff = 210;

  //read accel data
  AcX = (Wire.read() << 8 | Wire.read()) + AcXoff;
  AcY = (Wire.read() << 8 | Wire.read()) + AcYoff;
  AcZ = (Wire.read() << 8 | Wire.read()) + AcYoff;

  //read temperature data
  temp = (Wire.read() << 8 | Wire.read()) + toff;
  tx = temp;
  t = tx / 340 + 36.53;
  tf = (t * 9 / 5) + 32;

  //read gyro data
  GyX = (Wire.read() << 8 | Wire.read()) + GyXoff;
  GyY = (Wire.read() << 8 | Wire.read()) + GyYoff;
  GyZ = (Wire.read() << 8 | Wire.read()) + GyZoff;

  //get pitch/roll
  getAngle(AcX, AcY, AcZ);
  servoangle02 = ((((AcY / 10) / 1.72631) + servoangle01) + 550); // funny range calculation to match the servo

  servoangle02e = servoangle02d;
  servoangle02d = servoangle02c;
  servoangle02c = servoangle02b;
  servoangle02b = servoangle02a;
  servoangle02a = servoangle02;

  servoangle03 = (servoangle02 + servoangle02a + servoangle02b + servoangle02c + servoangle02d + servoangle02e) / 6;
 
  if (servoangle03 < 550)
  { servoangle03 = 550;
  }
  if (servoangle03 > 2400)
  { servoangle03 = 2400;
  }

  Serial.print("a: ");
  Serial.print(servoangle02);
  Serial.print(", ");
  Serial.print("b: ");
  Serial.println(servoangle03);
 
  servo1.write(servoangle03);

  delay(50);
}

void getAngle(int Vx, int Vy, int Vz) {
  double x = Vx;
  double y = Vy;
  double z = Vz;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)