Hi all,
First off (I'm a noob) apologies up front. Thanks in advance!
I have a teensy 4.1 that I'm using to develop a Yanmar diesel digital engine panel. I'm going to display RPM, oil pressure, water temp., and alternator voltage. I've got a 7" TFT (RA8875) hooked up already and gauges already working (just feed them random(x, xn)). I've got voltage working via a vcc<25v voltage sensor to A0, and currently trying to get the oil pressure sender working.
I have a bench test setup w/ the sender hooked up to a bicycle pump (gauge) so I can generate up to about 30psi.
My issue is trying to figure out the hookup. The sender gives a resistance of 25(80psi) to 240(0 psi) range. I understand that I have to convert this to volts somehow. The Interweb shows a lot of discussion on dividers and such, but I'm having trouble applying what I've read.
Assuming I connect teensy 3.3v to the sender (which has a lead pt at the top, and is grounded to the motor in the test I just wire the ground of the bread board to the sender)
where do I attach the A1?
I've tried 330, 220, 100, 50 resistors between the sender lead and the A1 (teensy 3.3 > resistor > sender > teensy gnd).
I've looked at the https://ohmslawcalculator.com/voltage-divider-calculator and used an input of 3.3v R1 of 20, and tried the range of R2 of 1-300 and the voltage out is 0.15-3.094 respectively. So, I tried 20ohms for R1 assuming that the sender represents R2. On the bread board the A1 tap is between the 20ohm resistor and the sender.
Here's a snippet of the data output not much changes when i pump:
<removed bad data... see next post!>
I blatantly ripped this from an example. I understand that R2 is wrong, but I don't know what to set it to as it represents a range?
#define PORT_OIL_PRESSURE_PIN A1
#define STAR_OIL_PRESSURE_PIN A3
float oil_ref_voltage = 3.3;
float R1_oil = 20.0;
float R2_oil = 200.0;
double readOilPressure(ENG_LOC portOStar) {
// Floats for ADC voltage & Input voltage
float adc_oilPressure = 0.0;
float oilPressure = 0.0;
int PIN;
(portOStar == PORT) ? PIN = PORT_OIL_PRESSURE_PIN : PIN = STAR_OIL_PRESSURE_PIN;
// Read the Analog Input
int adc_value = analogRead(PIN);
if (adc_value <= 0) {return 0;}
Serial.print("adc oil value: "); Serial.print(adc_value);
// Determine voltage at ADC input
adc_oilPressure = (adc_value) * ref_voltage / 1023;
Serial.print(", adc oil pressure: "); Serial.print(adc_oilPressure);
// Calculate voltage at divider input
oilPressure = adc_oilPressure / (R2_oil / (R1_oil + R2_oil)) ;
Serial.print(", oilPressure: "); Serial.println(oilPressure);
return oilPressure;
}
First off (I'm a noob) apologies up front. Thanks in advance!
I have a teensy 4.1 that I'm using to develop a Yanmar diesel digital engine panel. I'm going to display RPM, oil pressure, water temp., and alternator voltage. I've got a 7" TFT (RA8875) hooked up already and gauges already working (just feed them random(x, xn)). I've got voltage working via a vcc<25v voltage sensor to A0, and currently trying to get the oil pressure sender working.
I have a bench test setup w/ the sender hooked up to a bicycle pump (gauge) so I can generate up to about 30psi.
My issue is trying to figure out the hookup. The sender gives a resistance of 25(80psi) to 240(0 psi) range. I understand that I have to convert this to volts somehow. The Interweb shows a lot of discussion on dividers and such, but I'm having trouble applying what I've read.
Assuming I connect teensy 3.3v to the sender (which has a lead pt at the top, and is grounded to the motor in the test I just wire the ground of the bread board to the sender)
where do I attach the A1?
I've tried 330, 220, 100, 50 resistors between the sender lead and the A1 (teensy 3.3 > resistor > sender > teensy gnd).
I've looked at the https://ohmslawcalculator.com/voltage-divider-calculator and used an input of 3.3v R1 of 20, and tried the range of R2 of 1-300 and the voltage out is 0.15-3.094 respectively. So, I tried 20ohms for R1 assuming that the sender represents R2. On the bread board the A1 tap is between the 20ohm resistor and the sender.
Here's a snippet of the data output not much changes when i pump:
<removed bad data... see next post!>
I blatantly ripped this from an example. I understand that R2 is wrong, but I don't know what to set it to as it represents a range?
#define PORT_OIL_PRESSURE_PIN A1
#define STAR_OIL_PRESSURE_PIN A3
float oil_ref_voltage = 3.3;
float R1_oil = 20.0;
float R2_oil = 200.0;
double readOilPressure(ENG_LOC portOStar) {
// Floats for ADC voltage & Input voltage
float adc_oilPressure = 0.0;
float oilPressure = 0.0;
int PIN;
(portOStar == PORT) ? PIN = PORT_OIL_PRESSURE_PIN : PIN = STAR_OIL_PRESSURE_PIN;
// Read the Analog Input
int adc_value = analogRead(PIN);
if (adc_value <= 0) {return 0;}
Serial.print("adc oil value: "); Serial.print(adc_value);
// Determine voltage at ADC input
adc_oilPressure = (adc_value) * ref_voltage / 1023;
Serial.print(", adc oil pressure: "); Serial.print(adc_oilPressure);
// Calculate voltage at divider input
oilPressure = adc_oilPressure / (R2_oil / (R1_oil + R2_oil)) ;
Serial.print(", oilPressure: "); Serial.println(oilPressure);
return oilPressure;
}
Last edited: