Hello,
I've posted similar questions in the "Sensor" section of the forum, but have had little response. I thought I might try posting my code here to see if anyone could be of assistance.
I am running this code with a piezo sensor connected to an Arduino Pro Mini on A1. I also have an MPU9150 connected to the same arduino with all of the correct connections, including the INT pin connected to digital pin 2 on the arduino. I am only wanting to retrieve the (mx) values, and ONLY when my piezo sensor has been tapped. So far all of the adjustments I have tried with the code still give me just a continuous stream of output from the MPU9150 sensor. I understand that the accelerometer can act as a 'tap detect', but I have found no functioning arduino code that works with the MPU9150 for the interrupts.
Thanks in advance for any help!
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;
const byte TAP = A1;
const byte SENSE = 2;
#define LED_PIN 13
bool blinkState = false;
void switchPressed ()
{
if (analogRead (TAP) == LOW)
digitalWrite (SENSE, LOW);
else
digitalWrite (SENSE, HIGH);
}
void setup() {
Wire.begin();
Serial.begin(9600);
Serial.println("Initializing I2C devices...");
accelgyro.initialize();
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
pinMode (TAP, INPUT);
digitalWrite (SENSE, LOW);
attachInterrupt (0, switchPressed, RISING);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
if (analogRead (TAP) == LOW)
accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
Serial.print(mx);
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}