Thank you for the tips and the code!
I have collaged it into the sketch I am working with.
The 8 bit LSM is counting up (or down depending on how it is sitting on the bench) and I need to starting counting it as it wraps around. Would this be best done with Timer1 counting it?
#include <LiquidCrystal.h>
LiquidCrystal lcd(10, 9, 8, 7, 6, 5); // put your pin numbers here
byte index = 0;
int DMM_ARRAY[6]; // Where to store the Bytes read
byte c;
//char SETUP = 0x65;
int n = 0;
float previousValue = 0;
float currentValue = 0;
uint32_t t = 0; // Time record was received '2', '3', '4', '5', '6', '7', '8', '9', ' ', 'L'};
void setup() {
pinMode(11, OUTPUT); // LCD CONTRAST PIN
pinMode(2, OUTPUT); // Clear To Send PIN
pinMode(3, OUTPUT); // Request Sample PIN
analogWrite(11, 50); //LCD CONTRAST AMOUNT
Serial.begin(1000000);
lcd.begin(16, 2);
lcd.print("GG1320AN21 TEST");
lcd.clear();
}
void loop() {
float deltaTheta;
static unsigned long previousMicros=0;
unsigned long currentMicros = micros(); // you could do this with millis() too, depends on the precision you want
if (currentMicros - previousMicros >= 1000000ul) { // 1s in µs
unsigned long deltaT = currentMicros - previousMicros; // that will be give or take 1s
digitalWrite(2, HIGH); // CTS Open
digitalWrite(3, HIGH); // RS
delayMicroseconds( 50 );
digitalWrite(3, LOW); //RS
delayMicroseconds( 200 );
digitalWrite(2, LOW); // CTS Close
// time to get a new read
Get_data(); //Read the Serial bytes coming in
currentValue = DMM_ARRAY[2];
// ... your code here and use deltaT for elapsed time since last measure (of course convert into the right unit)
deltaTheta =((previousValue - currentValue)* 1.113065); // count * 1.113065 ARC SEC / SEC
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(deltaTheta / (deltaT / 1000000)); //3 decimal place values
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print( DMM_ARRAY[2]);// Print btye 3 (LSB)
lcd.print(" ");
previousMicros = currentMicros;
previousValue = currentValue;
}
}
void Get_data() {
if (Serial.available() >= 6) {
for (int i = 0; i < 6; i++) {
DMM_ARRAY[i] = Serial.read();
}
}
}