Here is my main.cpp code
/*
*/
#include “mbed.h”
#include “TextLCD.h”
#include “ADXL345_I2C.h”
#include “ITG3200.h”
#include “RecordData.h”
#include “GetAccelerometer.h”
#include “GetGyro.h”
/*
#define g0 9.812865328
//Number of samples to average.
#define SAMPLES 4
//Number of samples to be averaged for a null bias calculation
//during calibration.
#define CALIBRATION_SAMPLES 128
//Convert from radians to degrees.
#define toDegrees(x) (x * 57.2957795)
//Convert from degrees to radians.
#define toRadians(x) (x * 0.01745329252)
//ITG-3200 sensitivity is 14.375 LSB/(degrees/sec).
#define GYROSCOPE_GAIN (1 / 14.375)
//Full scale resolution on the ADXL345 is 4mg/LSB.
#define ACCELEROMETER_GAIN (0.004 * g0)
//Sampling gyroscope at 200Hz.
#define GYRO_RATE 0.002
//Sampling accelerometer at 200Hz.
#define ACC_RATE 0.002
//Updating filter at 100Hz.
#define FILTER_RATE 0.01
#define CORRECTION_MAGNITUDE 50
*/
/*
Ticker accelerometerTicker;
Ticker gyroscopeTicker;
Ticker filterTicker;
Ticker dataTicker;
Ticker algorithmTicker;
DigitalOut led1(LED1, “led1”);
DigitalOut led2(LED2, “led2”);
DigitalOut led4(LED4, “led4”);
*/
// Use this if using Tera Term
//Serial pc(USBTX, USBRX);
//SDFileSystem sd(p5,p6,p7,p8,“sd”); //MOSI, MISO, SCLK, CS
//Set up I2C comms and devices
I2C i2c(p9,p10);//p28,p27
I2C i2c_lcd(p9,p10); // sda, scl
DigitalOut Status_1(LED1);
#define LED_ON 1
#define LED_OFF 0
//float gyro_buffer[480];
int err;
int samples = 120; //(check wait in while loop)
int file_open = 0;
/*
Be sure to read Wim Huiskamps notes about the LCD type you are using
and adjust the function call to match your LCD type display.
*/
TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD20x4); // I2C bus, 2004A Slaveaddress 0x4E, LCD Type
//Function declaration
//void calibrateAccelerometer(void);
void calibrateAccelerometer();
//Global Variables
int readings[3] = {0, 0, 0};
int buffer_a[3] = {0, 0, 0};
int *buffer_aptr;
int buffer_g = {0, 0, 0};
int *buffer_gptr;
int a_xBias, a_x = 0;
int a_yBias, a_y = 0;
int a_zBias, a_z = 0;
float gx, gy, gz = 0;
int main() {
// ...... you will need to set time first!
set_time(1490126860); // Set RTC time from unixtimestamp.com --1489651200
// These are here to test whether any of the initialization fails. It will print the failure
if (accelerometer.setPowerControl(0x00)){
//pc.printf("didn't intitialize power control\n");
lcd.printf("didn't intitialize power control\n");
return 0; }
//Full resolution, +/-16g, 4mg/LSB.
thread_sleep_for(100);
if(accelerometer.setDataFormatControl(0x0B)){
//pc.printf("didn't set data format\n");
lcd.printf("didn't set data format\n");
return 0; }
thread_sleep_for(100);
//3.2kHz data rate.
if(accelerometer.setDataRate(ADXL345_3200HZ)){
//pc.printf("didn't set data rate\n");
lcd.printf("didn't set data rate\n");
return 0; }
thread_sleep_for(100);
//Measurement mode.
if(accelerometer.setPowerControl(MeasurementMode)) {
//pc.printf("didn't set the power control to measurement\n");
lcd.printf("didn't set the power control to measurement\n");
return 0; }
//First calibrate your device. The ADXL350 datasheet explains about offset.
calibrateAccelerometer();
//GYRO set up starts here!
//Set highest bandwidth.
gyro.setLpBandwidth(LPFBW_42HZ); //was gyro1.seLpBandwidth
//Set LCD integrted backlight to ON
lcd.setBacklight(TextLCD::LightOn);
//t.start();
while (1){
accelerometer.getOutput(readings);
//Put the 'raw' values into Ax,Ay and Az vaiables _nb (no bias).
int Ax_nb = (int16_t)readings[0];
int Ay_nb = (int16_t)readings[1];
int Az_nb = (int16_t)readings[2];
//Subtract the offset from the non biased raw values
int Ax = Ax_nb - a_xBias;
int Ay = Ay_nb - a_yBias;
int Az = Az_nb - a_zBias;
//Put results in a buffer
buffer_a[0] = Ax;
buffer_a[1] = Ay;
buffer_a[2] = Az;
buffer_aptr = &buffer_a[0];
/*pc.printf("Ax%2.2i\n",buffer_aptr[0]);
wait(3);
buffer_aptr = &buffer_a[1];
pc.printf("Ay%2.2i\n",buffer_aptr[1]);
wait(3);
buffer_aptr = &buffer_a[2];
pc.printf("Az%2.2i\n",buffer_aptr[2]);
*/
//wait(3);
/*
To get acceleration due to gravity in the 3 axis multiply the
the offset adjusted raw value by the resolution 4mg per LSB
noting 250 is 1g.
*/
gx = Ax * 0.004;
gy = Ay * 0.004;
gz = Az * 0.004;
int Gx = GyroReading_x();
int Gy = GyroReading_y();
int Gz = GyroReading_z();
buffer_g[0] = Gx;
buffer_g[1] = Gy;
buffer_g[2] = Gz;
buffer_gptr = &buffer_g[0];
Datarecord(buffer_aptr, buffer_gptr, sizeof (buffer_a), sizeof (buffer_g));
Status_1 = LED_ON;
//Lets look at some results if they make any sense!
lcd.cls();
//lcd.printf("ITG3200 DevID 0x%02X\n",gyro.getWhoAmI()); //was gyro1.getWhoAmI()
//lcd.printf("ADXL DevID is: 0x%02X\n", accelerometer.getDeviceID());
//Output of ADXL345 without calibration function
lcd.locate(0,1);
//lcd.printf("Ax%i Ay%i Az%i\n", Ax_nb, Ay_nb, Az_nb);
//lcd.locate(0,2);
//lcd.printf("xB%i yB%i zB%i\n",a_xBias, a_yBias, a_zBias);
//lcd.locate(0,3);
//Output of ADXL345 with calibration function
lcd.printf("AxB%i AyB%i AzB%i\n", Ax, Ay, Az);
lcd.locate(0,3);
/*
Outut of each axis in terms of force due to gravity. By looking at the
reference document AN-177 and orientating the chip to match you should
see each of the axis display 1g aginst its orientation.
*/
lcd.printf("gx%03.2f gy%03.2f gz%03.2f\r\n", gx, gy, gz);
//lcd.printf("gz%04.3f\n",gz);
//lcd.printf("Gx%i Gy%i Gz%i\n\r", Gx, Gy, Gz);
/*
This temperature is included for completeness refer to the ADXL350
datasheet for temperature effects.
*/
//lcd.printf("Temperature %2.1f \n",gyro.getTemperature());
thread_sleep_for(1000);
}
}
RecordData.h is clearly in my project folder.
I now get the following Errors I never had before?
Use of undeclared identifier ‘accelerometer’
Use of undeclared identifier ‘gyro’
Use of undeclared identifier ‘GyroReading_x’
Sturggling to find a reason why under OS6.15.1?
Regards,
Degs