Hmm, running Circuit Playground library stops me using the tft library. Had a sounding out with Mick and came to same conclusion to bypass Circuit Python, he said they wrapped it around code for the accelerometer anyway.
So went looking at the Circuit Playground source code on github:
- https://github.com/adafruit/Adafruit_CircuitPlayground/blob/master/Adafruit_CircuitPlayground.cpp
- https://github.com/adafruit/Adafruit_CircuitPlayground/blob/master/Adafruit_Circuit_Playground.h
I noticed in the header file it included Adafruit_CPlay_LIS3DH.h
, so I commented looked for examples that use LIS3DH libraries, and thankfully there were a few out there, so I added
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
plus the following declarations
// Used for software SPI
#define LIS3DH_CLK 13
#define LIS3DH_MISO 12
#define LIS3DH_MOSI 11
// Used for hardware & software SPI
#define LIS3DH_CS 10
// software SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
// hardware SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
// I2C
Adafruit_LIS3DH lis = Adafruit_LIS3DH(&Wire1);
Not sure if the additional code worked for LIS3DH, so I found the following snippet to check if it was found or not:
if (! lis.begin(0x19)) { // change this to 0x19 from 0x18 for alternative i2c address
Serial.println("Couldnt start");
while (1) yield();
}
Serial.println("LIS3DH found!");
And that's where I got stuck... no matter what iterations of commenting out and in I did, or change the i2C address, it came back with
"Couldnt start"
😫 This was head-wrecking for most of the day.'
Later that evening
Still having problems getting to connect with the accelerometer. I needed another pair of eyes... well, in truth, I wasn't going to turn in for bed (it was getting really late) as I was being stubborn on trying to figure this out. So Mick took a look as well, and spotted the CPP file I had open in the "begin" function to see how they declared it. Now this was staring in my face the whole time
lis = Adafruit_CPlay_LIS3DH(&Wire1);
Why didn't I try putting &Wire1
as an argument?! 😳
Added the argument, saved and compiled. Hit that upload button, held breath when no errors appeared and.... IT WORKED!
Sample Output from Accelerometer
X: 608 Y: 5344 Z: -15376
Screen should be blue now!
X: 592 Y: 5296 Z: -15584
Screen should be blue now!
X: 752 Y: 5248 Z: -15456
Screen should be blue now!
X: 512 Y: 5184 Z: -15424
Screen should be blue now!
X: 608 Y: 5200 Z: -15488
💤 Bedtime! #KThxBai
Top comments (0)