I am using two devices on an Arduino Uno:
Sparkfun ADXL362 Accelerometer
Sparkfun Flexible OLED 1.81"
The goal is to use the accelerometer for accel data as well as putting the arduino to sleep and use the OLED to display data.
Both examples work fine separate even with all the hardware connected but I no longer get data from the accelerometer when combining the code. The only thing I changed when combining the code was a different CS pin for the OLED.
/*
ADXL362_SimpleRead.ino - Simple XYZ axis reading example
for Analog Devices ADXL362 - Micropower 3-axis accelerometer
go to http://www.analog.com/ADXL362 for datasheet
License: CC BY-SA 3.0: Creative Commons Share-alike 3.0. Feel free
to use and abuse this code however you'd like. If you find it useful
please attribute, and SHARE-ALIKE!
Created June 2012
by Anne Mahaffey - hosted on http://annem.github.com/ADXL362
Modified May 2013
by Jonathan Ruiz de Garibay
Connect SCLK, MISO, MOSI, and CSB of ADXL362 to
SCLK, MISO, MOSI, and DP 10 of Arduino
(check http://arduino.cc/en/Reference/SPI for details)
*/
#include <SPI.h>
#include <ADXL362.h>
flexibleOLED(6, 9); //10-->Changed to 6 (10 is CS on ADXL362) = CS, 9 = RES
ADXL362 xl;
int16_t temp;
int16_t XValue, YValue, ZValue, Temperature;
///////Added from OLED example////////////
#include <SSD1320_OLED.h>
SSD1320
void setup(){
Serial.begin(9600);
xl.begin(10); // Setup SPI protocol, issue device soft reset
xl.beginMeasure(); // Switch ADXL362 to measure mode
Serial.println("Start Demo: Simple Read");
/////////Added from OLED example//////////////
Serial.begin(115200);
flexibleOLED.begin(160, 32); //Display is 160 wide, 32 high
flexibleOLED.clearDisplay(); //Clear display and buffer
flexibleOLED.setFontType(1); //Large font
flexibleOLED.setCursor(28, 12);
flexibleOLED.print("Hello World!");
flexibleOLED.setFontType(0); //Small font
flexibleOLED.setCursor(52, 0);
flexibleOLED.print("8:45:03 AM");
flexibleOLED.display();
}
void loop(){
// read all three axis in burst to ensure all measurements correspond to same sample time
xl.readXYZTData(XValue, YValue, ZValue, Temperature);
Serial.print("XVALUE=");
Serial.print(XValue);
Serial.print("\tYVALUE=");
Serial.print(YValue);
Serial.print("\tZVALUE=");
Serial.print(ZValue);
Serial.print("\tTEMPERATURE=");
Serial.println(Temperature);
delay(100); // Arbitrary delay to make serial monitor easier to observe
}