LED 12C not working

I have this code:

//Include LCD library
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup() {

lcd.begin(16, 2);

}

void loop() {

delay(100);

lcd.clear();

lcd.setCursor(0,1);

int Read = analogRead(A0);

float P = pow(10, 1.667 * (2 * Read) - 11.46);
lcd.print(P);
}
and all it does is display inf on the display even when I input a voltage to analog pin 0. I want the code to display the output of that expression at the end in scientific notation to two significant figures, i.e 5.5e-4.

Do the calculation for Read = 1023 and for Read = 0. i.e. the two limit values.

For 123 you get 10 with 3399 zeros. That is out of range of both decimal and scientific notation.
Even with 0 you get a very small number.

I am not sure how the Arduino print() handles scientific output.
Try it on the Serial Terminal.

David.

Edit.

void setup() 
{
    Serial.begin(9600);
    Serial.println(5.5e-4);
    Serial.println(5.5e1500);
}

void loop() 
{
}

displays 0.00 and inf (on an M0 Pro). It will do the same on a Uno.

If you want fancy formatting or scientific notation, you can probably use dtostrf() and dtostre()
You still need to provide valid float numbers.

Aight so what I'm doing here is taking a read value from a single-pin output on a vacuum gauge (0-10v) and using a voltage divider to get it down to readable values (hence the 2 * in the expression) and using a formula provided in the user manual to convert the read voltage into a value in torr. The given conversion expression there is that Pressure=10^(1.66*Voltage-11.46), which gives valid values for 0-10 volts as atmospheric pressure is 760 torr and the gauge reads down to 3.8x10^-9 Torr. The problem I have is with the actual composition of the code, as I have limited experience with C and Arduino. The output basically must be in scientific notation, but since dtostre() isn't exactly a beginner function, I haven't been able to find an easily understandable explanation of its usage in any API on the internet. From what I can gather about its class of function it will store a floating point variable as a string, which would be easily printable, but I have no clue how this would be done.

Pressure=10^(1.66*Voltage-11.46), which gives valid values for 0-10 volts as atmospheric pressure is 760 torr and the gauge reads down to 3.8x10^-9 Torr.

1. The formula for Pressure = 10^(1.66*Voltage-11.46). Is it correct?

2. What is the value of Voltage at A0-pin of the UNO when the Pressure is 760 torr?

3. What is the value of Voltage at A0-pin of the UNO when the Pressure is 3.8x10^-9 torr?

It is required that we know the values of the voltages at two points (v1 and v2) for two known pressures (p1 and p2) in order to have your pressure gauge calibrated.

Calibration of the gauge isn't my biggest issue here. I knew I would have to do all that initially. The calibration issue is one with the gauge itself, as the formula will yield exact values for the pressures assuming the gauge is accurate.

The reason I'm here is that I need to know how to avoid spending $400 on a used gauge controller that I have no guarantee of compatibility with my instrument by programming my own.

  1. the formula was in the manual for the gauge
  2. probably like 10.5v
    3.probably like 1.5v, but if you want to know exact values you can solve the equation.
  1. probably like 10.5v

This value at A0-pin is not acceptable when the VREF (Full Scale) of the ADC is 5V.

Calibration is an important issue to bring down your Pressure Readings into human readable range!

Every system is a Real System, and it has gain and offset. We need to make a two-point calibration to find these parameters in order to derive the response equation -- y = mx + c.

First off, you can just experiment with dtrostre()

void setup()
{
    Serial.begin(9600);
    char buf[20];
    for (float Voltage = 0.0; Voltage < 12; Voltage++) {
        float pressure = pow(10, 1.66 * Voltage - 11.46);
        dtostre(pressure, buf, 3, 0);
        Serial.print("Voltage = ");
        Serial.print(Voltage, 3);
        Serial.print(" Pressure = ");
        Serial.println(buf);
    }
}

void loop()
{
}

and get:

Voltage = 0.000 Pressure = 3.467e-12
Voltage = 1.000 Pressure = 1.585e-10
Voltage = 2.000 Pressure = 7.244e-09
Voltage = 3.000 Pressure = 3.311e-07
Voltage = 4.000 Pressure = 1.514e-05
Voltage = 5.000 Pressure = 6.918e-04
Voltage = 6.000 Pressure = 3.162e-02
Voltage = 7.000 Pressure = 1.445e+00
Voltage = 8.000 Pressure = 6.607e+01
Voltage = 9.000 Pressure = 3.020e+03
Voltage = 10.000 Pressure = 1.380e+05
Voltage = 11.000 Pressure = 6.310e+06

So it looks as if 760 Torr will be displayed when the Voltage is about 8.63V

Read the docs to see how to change the precision. Read the docs to see how to read 0-5V with analogRead()

David.

void setup() {
Serial.begin(9600);
int Re = analogRead(A0);

char buf[20];
dtostre(Re, buf, 3, 0);
Serial.print(buf);
}

void loop() {

}

and I got when reading the 3.3V signal from the board

7.060e+02

706 is not 3.3. This may be my problem, but I'm not sure how to fix. EDIT: I know how to do the conversion from analogRead to an actual voltage now. Shoulda done some quick googling first. This'll probably fix my problems.

In response to the other post, I understand the five volt read limit and I will use a voltage divider and multiply the read voltage by two (I think I said that in an earlier post). The two-point calibration is I believe worked into the conversion expression, as I said earlier. In the documentation after it gives this conversion expression p=10^(1.667V-11.46) it specifies a range of 3.8e-9<p<750 torr. Again, the actual mechanical calibration of the gauge is a far more important issue to determine it's accuracy. I probably will calibrate at low vacuum against a brand-new thermocouple gauge and match the readings using the calibration screw on the gauge head. This will allow me to find that "b" you mentioned. The "m" is probably a non-issue, and if it becomes one I may as well just by a new gauge as it probably is corrupted in some way.

Works great now :stuck_out_tongue:

Thanks all.