0

I have a trouble with following, few lines code. For some reason after few seconds Arduino uno stops responding into void loop section of code. I tried to remove serial communication, all print and println without any success. Is the problem comming from MMA_7455.h?

#include <MMA_7455.h>
#include <Servo.h>

int servoPin = 9;
int servoAngle = 0;

Servo servo;

MMA_7455 accel = MMA_7455();
char yVal;
char yVal_bkp;


void setup() {
    servo.attach(servoPin);
    accel.initSensitivity(2);
    accel.calibrateOffset(1.0, 26.0, -69.0);
}

void loop() {
    yVal = accel.readAxis('y'); //Read out the 'y' Axis

    if(yVal_bkp != yVal + 2 || yVal_bkp != yVal -2)
    {
        servo.write(90 + yVal);
        yVal_bkp = yVal;
    }
}

P.S. Servo is normal G90

2
  • accel.readAxis() returns unsigned char. You are using char which is signed in AVR GCC gcc.gnu.org/wiki/avr-gcc Commented Jul 24, 2016 at 10:24
  • Yes, it returns only positive values, I alredy verified, but if you assign this value to char yVal it returns signed value (ex -12) in Serial.print(yVal, DEC); Commented Jul 24, 2016 at 10:28

1 Answer 1

1

Have you checked that MMA_7455 can handle this many reads?
I had sensors that stop working because I asked to often for feedback.
As the servo needs a 20ms to adjust its location I would add a delay(20) to the loop.

1
  • Thanks for reply. After delay(20); add, correct execution is going for much more time, but anyway stops after. Increased also to 40, same result... Commented Jul 24, 2016 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.