Hello,
I'm using an ADXL362 accelerometer and it works great until I try to use it with a Bluetooth (HC-06) serial connection. The SPI setup protocol for it makes the bluetooth go crazy, sometimes flashing slowly as if in AT command mode, and sometimes (very rarely) actually working. I've tried the Bluetooth both with hardware and softwareserial connection, and on a Sparkfun Pro Micro and SAMD21 mini. All of the connections are working fine, as when I switch to printing an analogue channel over bluetooth or the ADXL362 via USB serial ports it works perfectly.
I'm hoping there is a trick to getting it to work. If anyone could provide any help that would be appreciated. The code is below:
#include <SPI.h>
#include <ADXL362.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9); // RX, TX
ADXL362 xl;
int16_t XValue, YValue, ZValue, Temperature;
long interval = 2500;
long previousMillis = 0;
void setup(){
mySerial.begin(115200);
// This setup section below is what is causing the issue
xl.begin(10); // Setup SPI protocol, issue device soft reset
xl.setNoise(ADXL362_ULTRALOWNOISE);
xl.setODR(ADXL362_RATE_400);
xl.beginMeasure(); // Switch ADXL362 to measure mode
}
void loop(){
unsigned long currentMillis = micros();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
xl.readXYZTData(XValue, YValue, ZValue, Temperature);
mySerial.print(XValue);
mySerial.print(" ");
mySerial.print(YValue);
mySerial.print(" ");
mySerial.println(ZValue);
}
}