5 years, 1 month ago.

How to provide digitalout to the pins based on accelerometer movement

I am new to the mbed system and embedded systems in general. I would like to control the motion of a robotic arm that is made up of 5 motors with a Hbridge controlling the direction of the motors. Each motor has 2 logic pins. I would like to write a output high or low to two pins when a FRM-KL25Z is tilted in the X,Y, or Z direction.

I'm not sure how to do this with the FRM-KL25Z, with an Arduino its very easy as I can just write to whichever pin I want and set it to low and high.

I tried modifying the example code for the Accelerometer provided on Mbed but I wasn't able to get it to work.

All help is appreciated. Thanks for taking the time to read all this.

1 Answer

5 years, 1 month ago.

Hi Mario,

A couple of quick notes:

Writing to DigitalOut

DigitalOut example

#include "mbed.h"
DigitalOut myled(LED1);

int main(void){
    myled = 1;          // set LED1 pin to high
    myled = 0;         // set LED1 pin to low



FRM-KL25Z is tilted in the X,Y, or Z direction., keyword tilted

From experience, I highly recommend working with quaternions. At first they seem unnecessary and complex, but they have a bunch of neat properties that make them wonderful for motion applications. https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation


FYI, the accelerometer example uses a very old version of mbed. I highly recommend updating your project to mbed OS 5. https://os.mbed.com/teams/NXP/code/FRDM_MMA8451Q/ Basically you can just remove the mbed.bld file and run an import mbed-os

Hope this helps, -Michael