I sat down during the weekend and followed the ideas on this forum. I am now sending the values from Arduino to Pure data through Serial port. As promised, here is my code:
#include <Wire.h> // I include Wire library for I2C protocol
#include <SparkFun_MMA8452Q.h> // I include the accel library
/* Begin using the library by creating an instance of the accel class. */
MMA8452Q SOL;
/* Setup function simply starts serial and initializes the accel */
/* I declare the variables */
int x;
int y;
int z;
void setup(){
Serial.begin(9600); /* I start the serial */
//Serial.println("MMA8452Q TESTO");
SOL.init(SCALE_4G, ODR_12); /* Initialize the accelerometer */
}
void loop(){
if (SOL.available()){
SOL.read(); /Read the new variables/
printAccels(); /Print digital readings/
}
Serial.write(x); /Serial port send/
}
void printAccels(){
x = SOL.cx*100; // Calculated acceleration values in units of g's. I multiply x 100 to get audible data in pd
if ((x <= -8)&&(x >=-10 )){ // Values when not moving
x = 0;
}
}
/*************************************************************************
I am just sending the x value. Tried y and z and it works. Thank you so much for your help! I just got the ESP8266, so I'll give that a go while wemos arrives. I'll keep you posted. ![]()