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

  • accel.readAxis() returns unsigned char. You are using char which is signed in AVR GCC gcc.gnu.org/wiki/avr-gcc – Mikael Patel Jul 24 '16 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); – Maksym Sadovnychyy Jul 24 '16 at 10:28
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.

  • 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... – Maksym Sadovnychyy Jul 24 '16 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.