So I am trying to combine the screen I have with readings I am taking on an IMU. Seperately I can make both devices work well. I am using the UTFT library with the screen and can load pictures without issues. I believe I am using SPI to interface with the shield but if someone has a better idea about this sheild it would be a good help.
With the IMU I am using I2C interface and can successfully measure the acceleration in all 3 axis.
The issue comes when I combine the two sketches. Evertime I call the imu.begin() function the screen goes dim and any screen related functions after this imu.begin() no longer work with the screen.
Can anyone help me with a key theory I may be missing or improving the code that will fix my issue
#include <UTFT.h>
#include <avr/pgmspace.h>
// Declare which fonts we will be using
extern uint8_t BigFont[];
UTFT myGLCD(ILI9325D_8, A5,A4,A3,A2,A1);
extern unsigned int Paper_Mario[4096];
extern unsigned int Yoshi[4096];
#include "SPI.h"
#include <Wire.h>
#include <SparkFunLSM9DS1.h>
const int chipSelect = A3;
#define LSM9DS1_M 0x1E // Would be 0x1C if SDO_M is LOW
#define LSM9DS1_AG 0x6B // Would be 0x6A if SDO_AG is LOW
LSM9DS1 imu;
const int alpha = 0.5;
float threshold =1.2;
float px = 0;
float py = 0;
float pz = 0;
float x = 0;
float y = 0;
float z = 0;
double totalaccel = 0;
const int axoffset = 0.02;
const int ayoffset =0.03;
const int azoffset = 0;
void setup()
{
randomSeed(analogRead(0));
myGLCD.InitLCD(LANDSCAPE);
myGLCD.setFont(BigFont);
myGLCD.clrScr();
myGLCD.fillScr(0, 255, 0);
// drawpic();
delay(1000);
imu.begin();
Serial.begin(38400);
imu.settings.device.commInterface = IMU_MODE_I2C;
imu.settings.device.mAddress = LSM9DS1_M;
imu.settings.device.agAddress = LSM9DS1_AG;
imu.settings.accel.scale = 8;
}
void drawpic(){
// Clear the screen and draw the frame
myGLCD.clrScr();
myGLCD.fillScr(0, 0, 0);
myGLCD.setColor(255, 255, 255);
myGLCD.print("Welcome to the", CENTER, 200);
myGLCD.print("lift game", CENTER, 220);
myGLCD.drawBitmap (86, 10, 64, 64, Paper_Mario,2);
}
void loop()
{
drawpic();
while (1) {
imu.readAccel();
x = ((imu.calcAccel(imu.ax) + axoffset) * alpha) + (px * (1 - alpha));
y = ((imu.calcAccel(imu.ay) + ayoffset) * alpha) + (py * (1 - alpha));
z = ((imu.calcAccel(imu.az) + azoffset) * alpha) + (pz * (1 - alpha));
totalaccel = sqrt( pow(x,2) + pow(y,2) + pow(z,2));
Serial.print("Total accel: "); Serial.print(totalaccel);
Serial.print(", Time(s): ");Serial.println((float(millis())/1000));
px = imu.calcAccel(imu.ax);
py = imu.calcAccel(imu.ay);
pz = imu.calcAccel(imu.az);
if(totalaccel < threshold){
myGLCD.clrScr();
myGLCD.fillScr(255, 0, 255);
}
delay(100);
}
}