openOBC oil pressure

June 29, 2014

Yeah, I finally got around to installing an oil pressure sensor in my E36 and trying it out with my openOBC. It was one of those really bizarre experiences where everything just worked without a fight.

The pressure sensor I used is a VDO 360-007. It's an 80 psi sensor with M12x1.5 threads and a warning light output at 8.5 psi. It fit perfectly in place of the factory pressure switch I replaced with it and the gauge output on it connects to the analog.in1 or in2 pins of the openOBC board, which are both set up by default to work with grounded resistive sensors like this.


I'm sure there are good guides already on how to actually install the oil pressure sensor. I had to move the alternator out of the way to get the factory pressure switch out, but with the right deep socket you could probably get to it without removing anything else.

The new pressure sensor has two outputs. One is a switched output that works like the factory switch did. It connects to the wire that was connected to the factory swich. The other is the gauge output. It connects to one of the analog inputs on the openOBC.

With the sensor installed, it's just a matter of hooking it up, sprinkling some code, and hoping for the best.

tasks/ObcOilPressure.h


#ifndef OBCOILPRESSURE_H
#define OBCOILPRESSURE_H

#include <ObcUITask.h>

namespace ObcOilPressureState {
    enum state {DisplayCurrent, DisplayLimit, SetLimit};
}

//starts at 0mV; increments by 10mV
const uint16_t pressureLookupTable[] = {
    0,
    0,
    0,
    0,
    11,
    25,
    39,
    53,
    67,
    81,
    95,
    110,
    124,
    139,
    154,
    169,
    184,
    199,
    215,
    230,
    256,
    261,
    278,
    294,
    310,
    327,
    343,
    360,
    377,
    394,
    411,
    428,
    446,
    464,
    482,
    500,
    519,
    537,
    556,
    575,
    594,
    613,
    633,
    653,
    673,
    693,
    713,
    734,
    755,
    776,
    797
};

class ObcOilPressure : public ObcUITask
{

public:
    ObcOilPressure(OpenOBC& obc);
    ~ObcOilPressure();
    
    virtual void runTask();
    virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask);
    
    virtual void wake();
    virtual void sleep();
    
private:
    ObcOilPressureState::state state;
    uint32_t pressureLimit;
    uint32_t pressureLimitSet;

    float getPsiFromVoltage(float voltage);
};

#endif // OBCOILPRESSURE_H

 

tasks/ObcOilPressure.cpp


#include "ObcOilPressure.h"
#include <ObcUI.h>
#include <cmath>
#include <cstdlib>

using namespace ObcOilPressureState;

ObcOilPressure::ObcOilPressure(OpenOBC& obc) : ObcUITask(obc)
{
    setDisplay("ObcTemp");
    
    std::string configState = obc.config->getValueByNameWithDefault("ObcOilPressureState", "DisplayCurrent");
    if(configState == "DisplayCurrent")
        state = DisplayCurrent;
    
    pressureLimit = strtoul(obc.config->getValueByNameWithDefault("ObcOilPressureLimit", "8").c_str(), NULL, 0);
}

void ObcOilPressure::sleep()
{
    obc.config->setValueByName("ObcOilPressureLimit", "%i", pressureLimit);
    if(state == DisplayCurrent)
        obc.config->setValueByName("ObcOilPressureState", "DisplayCurrent");
}

void ObcOilPressure::runTask()
{
    float currentPsi = getPsiFromVoltage(obc.analogIn1->read());
    
    
    if(state == DisplayCurrent)
    {
        setDisplay("oil: %02.0f psi", currentPsi);
    }
    else if(state == SetLimit)
    {
        setDisplay("set limit % 3i psi", pressureLimitSet);
    }
    
}

void ObcOilPressure::buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask)
{
    if(focus == ObcUITaskFocus::background)
    {
        if(buttonMask == BUTTON_TEMP_MASK)
            obc.ui->setActiveTask(this);
        return;
    }
    
    if(buttonMask == BUTTON_TEMP_MASK)
    {
        if(state == DisplayCurrent)
            state = DisplayLimit;
        else if(state == DisplayLimit)
            state = DisplayCurrent;
    }
    
    else if(buttonMask == BUTTON_SET_MASK)
    {
        if(state == DisplayLimit)
        {
            pressureLimitSet = pressureLimit;
            state = SetLimit;
        }
        else if(state == SetLimit)
        {
            pressureLimit = pressureLimitSet;
            state = DisplayLimit;
        }
    }

}

float ObcOilPressure::getPsiFromVoltage(float voltage)
{
    if(voltage < 0.04)
        return -1;
    if(voltage > 0.5)
        return 999;
    
    float currentPsi = (float)pressureLookupTable[(uint)(voltage * 100)] / 10;
    return currentPsi;
}

Well, it works! Now I just need to do a more permanent wiring job and clean up the code.

3 Comments

Justin

May 13, 2019, 3:43 p.m.

Very impressive. Have you ever looked into fixing the dead units..??? IE the unit display module that you show in the picture.?

benemorius

May 14, 2019, 7:38 p.m.

I have actually looked at that. All of the failures I've encountered have been due to the lcd cable detaching from the glass as the conductive adhesive wears out after years of service. Probably someone can find a solution to fix that, but it's not something I've tried. It's really too bad because it seems like a lot of them are starting to fail right about now and it's hard to find one that isn't either failed already or ready to fail as soon as you handle it too much.

Aron

May 6, 2019, 6:31 a.m.

This is awesome. What are the tools needed to learn this?

Leave a comment