Mee_n_Mac:
I simplified your code since you’re not averaging. I’m a little unsure of how to lcd.print a floating point number. If the code below doesn’t work right, I have an idea. Do NOT input voltages >2.54v !!#include <LiquidCrystal.h>
#define DIV_1 1.0 //note it’s 1.0, not 1, to get full floating point accuracy
#define DIV_2 1.0
// ADC reference voltage / calibration value
#define V_REF 2.54 //use the measured Aref voltage
#define LOOPdelay 200 //measure the voltages and update the LCD every xxx msec
#define REDLITE 6
#define GREENLITE 9
#define BLUELITE 10
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//declare the variables used
float voltage1 = 0.0; // calculated voltages
float voltage2 = 0.0; // calculated voltages
void setup()
{
Serial.begin(9600);
lcd.begin(20, 4);
lcd.clear();
delay(LOOPdelay);
pinMode(REDLITE, OUTPUT);
pinMode(GREENLITE, OUTPUT);
pinMode(BLUELITE, OUTPUT);
analogReference(INTERNAL);
}
void loop(){
analogWrite(BLUELITE,0); //Blue brightness 255-0
analogWrite(REDLITE,255); //Red brightness 255-0
analogWrite(GREENLITE,255); //Green brightness 255-0
// sample each channel A0 and A1
voltage1 = DIV_1 * float((analogRead(A0)) * V_REF/1024.0);
voltage2 = DIV_2 * float((analogRead(A1)) * V_REF/1024.0);
// display voltages on LCD
// each voltage is multiplied by the resistor network
// division factor to calculate the actual voltage
// voltage 1 - A (pin A0)
lcd.setCursor(0, 2);
lcd.print("CPU VCORE ");
lcd.print(voltage1, 3);
lcd.print(“v”);
// voltage 2 - B (pin A1)
lcd.setCursor(0, 3);
lcd.print("CPU VRIN ");
lcd.print(voltage2, 3);
lcd.print(“v”);
delay(LOOPdelay); //give LCD time to process data
}
<QUOTE author="Belial88"> > Belial88: > The values wig out when not connected/shorted, but whatever, but when I put it to that same 1.7v AA battery it reads as 2.0v. So how do i get that accurate and how do I get it to read 1.743v. </QUOTE> You had mis-set a constant in the defines. I'm surprised it displayed anything close to reality. You may need to increase the value for LOOPdelay to make things readable. Indeed you can play with that value to see how low it can go before your LCD stops working.
Hmm so… V_REF is based off the 5v pin, unless you write in the loop “analogReference(INTERNAL);” in which case it’l turn to whatever the value is, INTERNAL referencing the AREF pin. So… like I could say “13” if digitalpin 13 lead to a completely stable 5v value.
So the problem was that I wrote “INTERNAL” instead of 2.54v. And the arduino expects vref to be 2.54v because we wrote analogreference(INTERNAL) and Internal = AREF, ie 2.54v in my case and 2.56 usually.
Anyways, the code you wrote seems pretty much like it’s done. I see where the pin assignment is, it displays and is accurate to x.xxx. How did you do that? I don’t see anything where it’s 3 decimal places instead of 1. If anything, i see it say only 1 decimal place in
//declare the variables used
float voltage1 = 0.0; // calculated voltages
float voltage2 = 0.0; // calculated voltages
The loop delay figure, or how often the arduino sends voltage to lcd… i’m not sure why it makes much difference what it’s set to? I mean the difference in microseconds isn’t too big. I guess I could possibly miss a peak of suddenly insane voltage that I’d need to know… but 200msec is pretty quick, i guess I want as quick as possible right… i dont even know what is considered fast or slow.
So now to put it all together. I read that case…switch. So the case1 would be nothing, case2 would be if the button is pressed, ie 2 pins are shorted, for the servo. So starting with just LCD Smartie + Voltage reading:
#include <LiquidCrystal.h>
#define DIV_1 1.0 //note it's 1.0, not 1, to get full floating point accuracy
#define DIV_2 1.0
// ADC reference voltage / calibration value
#define V_REF 2.54 //use the measured Aref voltage
#define LOOPdelay 200 //measure the voltages and update the LCD every xxx msec
#define REDLITE 6
#define GREENLITE 9
#define BLUELITE 10
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//declare the variables used
float voltage1 = 0.0; // calculated voltages
float voltage2 = 0.0; // calculated voltages
//LCD SMARTIE
byte serial_getch(){
int incoming;
while (Serial.available()==0){}
// read the incoming byte:
incoming = Serial.read();
return (byte) (incoming &0xff);
}
void setup()
{
Serial.begin(9600);
lcd.begin(20, 4);
lcd.clear();
delay(LOOPdelay);
pinMode(REDLITE, OUTPUT);
pinMode(GREENLITE, OUTPUT);
pinMode(BLUELITE, OUTPUT);
analogReference(INTERNAL);
}
void loop(){
analogWrite(BLUELITE,0); //Blue brightness 255-0
analogWrite(REDLITE,255); //Red brightness 255-0
analogWrite(GREENLITE,255); //Green brightness 255-0
// sample each channel A0 and A1
voltage1 = DIV_1 * float((analogRead(A0)) * V_REF/1024.0);
voltage2 = DIV_2 * float((analogRead(A1)) * V_REF/1024.0);
//Display Before LCD SMARTIE starts
lcd.setCursor(0,0);
lcd.print("LCD SMARTIE");
lcd.setCursor(0,1);
lcd.print("LCD SMARTIE");
// display voltages on LCD
// each voltage is multiplied by the resistor network
// division factor to calculate the actual voltage
// voltage 1 - A (pin A0)
lcd.setCursor(0, 2);
lcd.print("CPU VCORE ");
lcd.print(voltage1, 3);
lcd.print("v");
// voltage 2 - B (pin A1)
lcd.setCursor(0, 3);
lcd.print("CPU VRIN ");
lcd.print(voltage2, 3);
lcd.print("v");
delay(LOOPdelay); //give LCD time to process data
//LCD SMARTIE
byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte
if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
{
switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
// 'switches' based on that byte
{
case 66: //backlight on (at previously set brightness)
// not implemented
break;
case 70: //backlight off
// not implemented
break;
case 71: //set cursor position
temp = (serial_getch() - 1); //get column byte
switch (serial_getch()) //get row byte
{
//line 1 is already set up
case 2:
temp += 0x40;
break;
case 3:
temp += 0x14;
break;
case 4:
temp += 0x54;
break;
default:
break;
}
lcd.command(0b10000000 + temp);
break;
case 72: //cursor home (reset display position)
lcd.command(2);
break;
}
}
}
Before lcd smartie starts, voltage reads are just frozen at some value (one shorted @0, the other is sometmies the battery value, sometimes just 0.134, for reference i short one and the other i measure the battery, but it isnt hardwired to the battery i just check it). Once lcd smartie starst, the voltage reads seem to work, but lcd smartie isnt