Dexter Industries DPressure Sensor lejos support

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc.

Moderators: 99jonathan, roger, imaqine

Dexter Industries DPressure Sensor lejos support

Postby rsdavis » Thu Feb 10, 2011 7:18 pm

I would like to purchase one of the Dexteries Industries dPressure 250 but there is no lejos driver for the device.

http://www.dexterindustries.com/Products-dPressure.html

I assume that this is just an A/D device on I2C port. A RobotC driver has been developed so I imagine a port from RobotC to lejos would be fairly trivial. I am a software engineer and my son and I are dablling in a project where we need to control a compressor based on pressure and the dPress 250 seems ideal but lejos out of the box does not support this third party sensor. Any help would be appreciated.

RobotC driver below:

#ifndef __DPRESS_DRIVER_H__
#define __DPRESS_DRIVER_H__

/** \file DPRESS-driver.h
* \brief ROBOTC dPressure Sensor Driver
*
* DPRESS-driver.h provides an API for the Dexter Industries dPressure Sensor.
*
* Changelog:
* - 0.1: Initial release
*
* Credits :
* - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
*
* License: You may use this code as you wish, provided you give credit where its due.
*
* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 2.00 AND HIGHER.
* \author Xander Soldaat (mightor@gmail.com)
* \date 13 June 2010
* \version 0.1
* \example DPRESS-test1.c
*/

#pragma systemFile

#define DPRESS_VREF 4.85 /*!< The voltage reference is assumed to be around 4V85 */

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function prototypes
bool DPRESSreadPress250kPa(tSensors link, float &pressure);
bool DPRESSreadPress250PSI(tSensors link, float &pressure);
bool DPRESSreadPress500kPa(tSensors link, float &pressure);
bool DPRESSreadPress500PSI(tSensors link, float &pressure);

/**
* Read the pressure in kiloPascals\n
* Note: This function is for the dPressure 250
* @param link the dPressure Sensor port number
* @param pressure the pressure in kiloPascals
* @return true if no error occured, false if it did
*/

bool DPRESSreadPress250kPa(tSensors link, float &pressure) {
float Vout = 0.0;

int val = 0;

// dPressure sensor type must absolutely be set to sensorAnalogInactive
if (SensorType[link] != sensorAnalogInactive)
return false;

// Pressure is calculated using Vout = VS x (0.00369 x P + 0.04)
// => P
// Where Vs is assumed to be equal to around 4.85 on the NXT

// Get raw sensor value
val = SensorValue[link];

// Calculate Vout
Vout = ((val * DPRESS_VREF) / 1023);

pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.00369;
return true;
}


/**
* Read the pressure in kiloPascals\n
* Note: This function is for the dPressure 250
* @param link the dPressure Sensor port number
* @param pressure the pressure in Pounds per Square Inch
* @return true if no error occured, false if it did
*/
bool DPRESSreadPress250PSI(tSensors link, float &pressure) {
return true;
}


/**
* Read the pressure in kiloPascals\n
* Note: This function is for the dPressure 500
* @param link the dPressure 500 Sensor port number
* @param pressure the pressure in kiloPascals
* @return true if no error occured, false if it did
*/
bool DPRESSreadPress500kPa(tSensors link, float &pressure) {
float Vout = 0.0;

int val = 0;

// dPressure sensor type must absolutely be set to sensorAnalogInactive
if (SensorType[link] != sensorAnalogInactive)
return false;

// Pressure is calculated using Vout = VS x (0.0018 x P + 0.04)
// => P
// Where Vs is assumed to be equal to around 4.85 on the NXT

// Get raw sensor value
val = SensorValue[link];

// Calculate Vout
Vout = ((val * DPRESS_VREF) / 1023);

pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.0018;
return true;
}


/**
* Read the pressure in kiloPascals\n
* Note: This function is for the dPressure 500
* @param link the dPressure 500 Sensor port number
* @param pressure the pressure in Pounds per Square Inch
* @return true if no error occured, false if it did
*/
bool DPRESSreadPress500PSI(tSensors link, float &pressure) {
return true;
}


#endif // __DPRESS_DRIVER_H__


RobotC test program below:

#pragma config(Sensor, S1, DPRESS, sensorAnalogInactive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/**
* DITMP-driver.h provides an API for the Dexter Industries dPressure sensor. This program
* demonstrates how to use that API.
*
* Changelog:
* - 0.1: Initial release
*
* Credits:
* - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
*
* License: You may use this code as you wish, provided you give credit where it's due.
*
* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 2.00 AND HIGHER.
* Xander Soldaat (mightor_at_gmail.com)
* 13 June 2010
* version 0.1
*/

#include "drivers/DPRESS-driver.h"

task main() {
float pressure;
byte state = 0;

nxtDisplayTextLine(0, "Dexter Industries");
nxtDisplayCenteredTextLine(1, "dPressure 250");
nxtDisplayCenteredTextLine(3, "Test 1");
nxtDisplayCenteredTextLine(5, "Connect sensor");
nxtDisplayCenteredTextLine(6, "to S1");
wait1Msec(2000);
eraseDisplay();

nxtDisplayTextLine(0, "Dexter Industries");
nxtDisplayCenteredTextLine(7, "< switch scale >");
//loop to read temp
while (true) {
switch(nNxtButtonPressed) {
// If the right button is pressed, cycle through the scales
case kRightButton:
if (++state > 1)
state = 0;
while (nNxtButtonPressed != kNoButton) EndTimeSlice();
break;

// If the left button is pressed, cycle through the scales in reverse
case kLeftButton:
if (--state < 0)
state = 1;
// debounce the button
while (nNxtButtonPressed != kNoButton) EndTimeSlice();
break;
}


nxtDisplayCenteredBigTextLine(1, "Pressure:");
switch(state) {
// if state: 0, display temp in degrees celcius
case 0: DPRESSreadPress250kPa(DPRESS, pressure);
nxtDisplayCenteredBigTextLine(3, "%4.2f", pressure);
nxtDisplayCenteredBigTextLine(5, "kPa");
break;

// if state: 1, display temp in Fahrenheit
case 1: DPRESSreadPress250PSI(DPRESS, pressure);
nxtDisplayCenteredBigTextLine(3, "%4.2f", pressure);
nxtDisplayCenteredBigTextLine(5, "PSI.");
break;
}
wait1Msec(10);
}
}
rsdavis
New User
 
Posts: 9
Joined: Mon Jan 17, 2011 4:18 pm

Re: Dexter Industries DPressure Sensor lejos support

Postby lawrie » Sun May 15, 2011 9:17 pm

It looks easy to support this sensor.

You could read the value with something like:

// Get raw sensor value
double rawVal = SensorPort.S1.readRawValue(); // Change port as required

// Calculate vOut
double DPRES_VREF = 4.85;
double vOut = ((rawVal * DPRESS_VREF) / 1023);

double pressure = ((vOut / DPRESS_VREF) - 0.04) / 0.00369;
lawrie
leJOS Team Member
 
Posts: 909
Joined: Mon Feb 05, 2007 1:27 pm


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff