What do you have to lose right ? When you started this post you had nothing. Now your down to tweaking. That's a lot of progress in my book.
Yes it is and a fun learning process.
Are you in the USA ?
Yes in normal,IL.
I'm slowly raising 1023 up. Getting close to what it should read. Will see in a minute if it stays linear.
This is getting so close.
int results = map(raw,0,1098,0,500); // scale voltage to 0-500
That puts me 5 mV out up to 4.65 V then stops reading. Time to play with the 500 #.
If you were on the other side of the world I was going to say isn't wierd to be able to consult people all over the world at all hours of the day and night FREE ?
If you were on the other side of the world I was going to say isn't wierd to be able to consult people all over the world at all hours of the day and night FREE ?
You got to love the Internet.
Man I really thought we almost had it. Adjusted 1026 up got the readout spot on up to 4.66V then it would not read any higher.
Then I adjusted 500 up got it to read 5V after that I had to readjust what I had in the 1026 spot like I figured I might. I got it spot on again and now it will only read 4.66V again.
Ok. Let's stop and think about this. If you are saying that there is definate repeatable ratio between the voltage measure and the voltage displayed, why do you just multiply the 4.66 by the float value 1.0729613733905579399141630901288 before displaying it?
I was wondering if I could throw some math in there but not sure if it will throw off the reading below 4.66V.
Use a 1.5V AAA battery to test it. Measure it first with a meter , then with the float math conversion factor.
I'm testing with a precision veritable bench power supply.
I'm not sure if I know how to do float math.
Would it be something like
float (466 * 1.0729613733905579399141630901288);
I don't think so. The 4.66 would have to be a float also. You would have to
http://arduino.cc/en/Reference/Float
Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38. They are stored as 32 bits (4 bytes) of information.
Floats have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point.
PASTE THIS INTO YOUR IDE AND RUN IT !
void setup()
{
Serial.begin(9600);
}
void loop()
{
float myfloat;
float sensorCalbrate = 1.07296;
int battv=466;
int x;
int y;
float z;
float batteryV;
x = battv;
y = 100.00;
// y now contains 0, ints can't hold fractions
z = (float)x / y; // z now contains .5 (you have to use 2.0, not 2)
batteryV=z*sensorCalbrate;
Serial.println(z,4);
Serial.println(batteryV,4);
delay(5000);
}
Ok let me give it a go.
I see its converting 4.66 to 5.00.
That's right. That's your conversion code to run on the value from the analog read.
It then needs to be rounded to an int. I'm researching that now.
OK cool
This is what i have that puts me spot on up to 4.66V.
int getBandgap(void) // Returns actual value of Vcc (x 100) 415 = 4.15v
{
int raw = analogRead(15);
int results = map(raw,0,1096,0,500); // scale voltage to 0-500
return results;
}
Voltage readout.
battv = getBandgap(); // read the voltage getBandgap
itoa (battv, voltage, 10); // converts integer to string
decimate(voltage, 2); // converts string to decimal point
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.setCursor(25, 213);
tft.println(voltage);
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.setCursor(13, 213);
tft.println("V");
Batt bar.
void drawbatt() {
battv = getBandgap(); // read the voltage
if (battv < battold) { // if the voltage goes down, erase the inside of the battery
tft.fillRect(298, 2, 18, 6, BLACK);
}
battfill = map(battv, 300, 415, 2, 18); // map the battery voltage 300 is the low, 415 is the high
battfill = constrain(battfill, 2, 18); // constrains batt display limits
if (battfill > 7) { // if the battfill value is between 8 and 18, fill with green
tft.fillRect(298, 2, battfill, 6, GREEN);
}
else { // if the battfill value is below 8, fill with red
tft.fillRect(298, 2, battfill, 6, RED);
}
battold = battv; // this helps determine if redrawing the battfill area is necessary
}
Just to recap.
PASTE THIS INTO YOUR IDE AND RUN IT !
void setup()
{
Serial.begin(9600);
}
void loop()
{
float myfloat;
float sensorCalbrate = 1.07296;
int battv=466;
int temp=battv;
int x;
int y;
float z;
float batteryV;
x = battv;
y = 100.00;
// y now contains 0, ints can't hold fractions
z = (float)x / y; // z now contains .5 (you have to use 2.0, not 2)
batteryV=z*sensorCalbrate;
Serial.println(z,4);
Serial.println(batteryV,4);
temp = (batteryV*100) + .5;
Serial.println(temp);
battv=temp;
Serial.println(temp);
delay(5000);
}
Note that I had to declare battv =466; at the beginning so my code could pick up where your code leaves off. At the end of my code I assign the result (temp) to battv just before the delay. It prints the temp first to show the result of the floating point conversion and back to int and then prints battv after it has been assigned the value of temp. If you insert this whole block of code between where your code leaves off with and int called "results" then at that time results would =466 and at the end of my code where battv =temp, you could assign "results=battv;" and it would then contain 500. I left it the way it is because this code does not know about your code and so at the beginning of this code your "results " as it were, doesn't exist. Run the code above to see the result and then paste it in after the code you just posted and change the variable names or leave it and just assign "battv=results" at the beginning of my code and at the end of my code assign results = temp and your code can pick up from there. Got it ? (that sounds a little confusing but if you run the above code your get it. Then you have to test it by measuring a 1.5V AA battery with a meter and recording the BEFORE value and then read the AFTER value on your display.
Ok Ill have a play with it.