I am reading three analog channels in, A0, A1 and A2. I am taking each input ten samples of each input, getting a sum and dividing by 10 for an average. All of that seems to work just fine. Here is my current code:
As shown it takes the data and does exactly what I would expect with the exception of a refresh. It's like my code runs once and does not loop. Here is an example of my display:
The displayed numbers are three voltage readings which do not change when I tilt an axis. They are actually changing as I can watch them on a DMM but my display never updates. I added some Serial.Print functions to see what was going on and same, when I open the Serial Monitor the data displays but will not update. Eventually there will be more to this but until I get this much working there is nop sense on adding to the code.
I am not, nor was I ever a programming type. If my eating would have depended on my coding abilities I would have starved long ago at my desk in the workplace. What little coding I did was mostly VB 6.0. Now obviously I have something very wrong or missing in what I have here. I would appreciate any suggestions.
I also have tried it removing the delays to no avail.
Thank You
Ron
Code:
//Libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address.
// number of analog samples to take per reading
#define NUM_SAMPLES 10
int sum1 = 0; // sum of samples taken
int sum2 = 0;
int sum3 = 0;
unsigned char sample_count1 = 0; // current sample number
unsigned char sample_count2 = 0;
unsigned char sample_count3 = 0;
float voltage1 = 0.0; // calculated voltage
float voltage2 = 0.0;
float voltage3 = 0.0;
void setup(){
Serial.begin(9600);
lcd.begin(20,4); // iInit the LCD for 20 chars 4 lines
lcd.backlight(); // Turn on the backligt (try lcd.noBaklight() to turn it off)
lcd.setCursor(1,0); //First line
lcd.print("3 Axis Measurement");
}
void loop(){
// take a number of analog samples and add them up
while (sample_count1 < NUM_SAMPLES) {
sum1 += analogRead(A0);
sample_count1++;
delay(10);
}
while (sample_count2 < NUM_SAMPLES) {
sum2 += analogRead(A1);
sample_count2++;
delay(10);
}
while (sample_count3 < NUM_SAMPLES) {
sum3 += analogRead(A2);
sample_count3++;
delay(10);
}
// calculate the voltage
// use 5.0 for a 5.0V ADC reference voltage
// 4.880V is the calibrated reference voltage
voltage1 = ((float)sum1 / (float)NUM_SAMPLES * 4.880) / 1024.0;
voltage2 = ((float)sum2 / (float)NUM_SAMPLES * 4.880) / 1024.0;
voltage3 = ((float)sum3 / (float)NUM_SAMPLES * 4.880) / 1024.0;
lcd.setCursor(1,0); //First line
lcd.print("3 Axis Measurement");
lcd.setCursor(0,1); //Second line
lcd.print(voltage1);
lcd.setCursor(0,2); //Third line
lcd.print(voltage2);
lcd.setCursor(0,3); //Fourth line
lcd.print(voltage3);
Serial.println (voltage1);
Serial.println (voltage2);
Serial.println (voltage3);
delay (100);
}
The displayed numbers are three voltage readings which do not change when I tilt an axis. They are actually changing as I can watch them on a DMM but my display never updates. I added some Serial.Print functions to see what was going on and same, when I open the Serial Monitor the data displays but will not update. Eventually there will be more to this but until I get this much working there is nop sense on adding to the code.
I am not, nor was I ever a programming type. If my eating would have depended on my coding abilities I would have starved long ago at my desk in the workplace. What little coding I did was mostly VB 6.0. Now obviously I have something very wrong or missing in what I have here. I would appreciate any suggestions.
I also have tried it removing the delays to no avail.
Thank You
Ron
Last edited: