BOWIE 发表于 2014-1-3 16:19:25

請問如何將MPU-6050(陀螺儀)控制28BYJ_48(步進馬達)?

各位先進大家好!請問如何用ARDUINO的程式,用MPU-6050(陀螺儀)控制28BYJ_48(步進馬達)?

迷你强 发表于 2014-1-3 16:48:22

这个问题不好回答。。。。。。。没有明确的目标

BOWIE 发表于 2014-1-3 17:32:10

本帖最后由 BOWIE 于 2014-1-22 01:59 编辑

謝謝您的答覆。我先試了一顆終於運轉了,但是我希望它轉動後會在我陀螺儀的角度固定,而不是一直轉!
以下是我的程序:

#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"

int motorPin1 = 8;         int motorPin2 = 9;   
int motorPin3 = 10;      int motorPin4 = 11;

int motorSpeed = 1200;//variable to set stepper speed
int count = 0;          // count of steps made
int countsperrev = 512; // number of steps per full revolution

int lookup={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};//逆时针
int lookup1={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};//顺时针

void anticlockwise()
{for(int i = 0; i < 8; i++)
{ setOutput(i);    delayMicroseconds(motorSpeed);}   }

void clockwise()
{for(int i = 7; i >= 0; i--)
{ setOutput(i);    delayMicroseconds(motorSpeed);}   }

MPU6050 mpu;

int16_t ax, ay, az;
int16_t gx, gy, gz;

int valy;
int valx;
int prevValy;
int prevValx;

void setOutput(int out)//set pins to ULN2003 high in sequence from 1 to 4
{ digitalWrite(motorPin1, bitRead(lookup, 0));
digitalWrite(motorPin2, bitRead(lookup, 1));
digitalWrite(motorPin3, bitRead(lookup, 2));
digitalWrite(motorPin4, bitRead(lookup, 3));    }

void setup()
{
pinMode(motorPin1, OUTPUT);    pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);    pinMode(motorPin4, OUTPUT);
Wire.begin();
Serial.begin(9600);

mpu.initialize();
}

void loop()
{
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
valy = map(ay, -34000, 34000, 0, 179);

if(valy < 90 )
   {anticlockwise();}

else if(valy > 90)
{clockwise();}

else
{ delayMicroseconds(motorSpeed*5);}

Serial.print(valy);
prevValy = valy;
}

BOWIE 发表于 2014-1-22 01:57:03

我希望將陀螺儀的數據給步進馬達,並調到跟陀螺儀一樣的角度,請各位高手解答一下,謝謝!
页: [1]
查看完整版本: 請問如何將MPU-6050(陀螺儀)控制28BYJ_48(步進馬達)?