Я использую акселерометр memsic2125 с Arduino Uno и пытаюсь преобразовать показания акселерометра в сервоприводы. После некоторой калибровки возвращается правильная угловая мера (по шкале от -90 до 90 градусов) и затем преобразуется в шкалу от 0 до 360 для непрерывного сервопривода, но сервопривод не будет двигаться вообще. Я не могу предоставить фотографию схемы, но я считаю, что моя проводка и компоненты в порядке. У меня есть программа, основанная на: http://www.arduino.cc/en/Tutorial/Memsic2125 . Извините, если ошибка действительно очевидна или вопиющая, я новичок в Arduino. Спасибо.
//AccelerometerServoControlDelta
//Uma
//Based on source code from:
//http://www.arduino.cc/en/Tutorial/Memsic2125
//Using a Memsic2125 accelerometer
#include <Servo.h>
Servo myservo;
const xPin = 2; //X-axis output
const yPin = 3; //Y-axis output
void setup() {
myservo.attach(9); //Servo is connected to I/O pin 9
Serial.begin(9600); //Initaialize serial monitor communications
pinMode(xPin, INPUT); //Initialize accelerometer pins
pinMode(yPin, INPUT);
}
void loop() {
int pulseX, pulse Y; //Reads pulse width for x-axis and y-axis
int accelerationX, accelrationY; //Variables which will contain the acceleration
int servoX;
int servoY;
pulseX = pulseIn(xPin, HIGH); //Read and assign the x and y pulses from the accelerometer
pulseY - pulseIn(yPin, HIGH);
accelerationX = (((pulseX / 9.81) - 500) * 8) / 11) - 2; //Division by the earth's acceleration
accelerationY = (((pulseY / 9.81) - 500) * 8) / 11) - 7; //Calculations after * 8 are for calibration purposes
Serial.print(accelerationX); //Printing x and y axis degrees of rotaion to serial monitor
Serial.print("\t");
Serial.print(accelerationY);
Serial.println();
delay(100);
servoX = map(accelerationX, -90, 90, 0, 360); //Converting the degree measurement of the axis from -90 - +90 to 0 - +360
myservo.write(servoX); //Using the converted value and sending it to the servo as a degree of rotation
delay(15);
}
Задача ещё не решена.
Других решений пока нет …