Mindsensors Pressure Sensor PPS58-Nx

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

Moderators: imaqine, 99jonathan, roger

fussel_dlx
New User
Posts: 7
Joined: Fri Feb 15, 2013 1:51 pm

Mindsensors Pressure Sensor PPS58-Nx

Postby fussel_dlx » Fri Feb 15, 2013 1:59 pm

Hello,

I'm currently trying to get the pressure sensor from mindsensors to work without success.

I tried to translate the NXC Classes from their download page to java:
http://www.mindsensors.com/index.php?mo ... ent_id=188

I have some basics in java and I got other sensors to work but I stuck with this thing.

Could someone help to just read the raw values?

many thanks

skoehler
leJOS Team Member
Posts: 1550
Joined: Thu Oct 30, 2008 4:54 pm

Re: Mindsensors Pressure Sensor PPS58-Nx

Postby skoehler » Fri Feb 15, 2013 2:07 pm

You should probably post the code you're using right now to read the raw values. Maybe someone can spot the error.

fussel_dlx
New User
Posts: 7
Joined: Fri Feb 15, 2013 1:51 pm

Re: Mindsensors Pressure Sensor PPS58-Nx

Postby fussel_dlx » Fri Feb 15, 2013 4:30 pm

This is my actual code with the c method in the comment:

Code: Select all

import lejos.nxt.I2CPort;
import lejos.nxt.I2CSensor;

public class PressureSensor extends I2CSensor {

   //Method in C:
   //unsigned int PPS_ReadValue(byte port, byte reg, byte count, byte addr) {
   //  unsigned int result = 0;
   //  byte outBuf[], cmdBuf[];
   //  ArrayBuild(cmdBuf, addr, reg);
   //  if (I2CBytes(port, cmdBuf, count, outBuf)) {
   //    if (count == 2)
   //      result = outBuf[1]*256 + outBuf[0];
   //    else
   //      result = outBuf[0];
   //  }
   //  return result;
   //}


   public PressureSensor(I2CPort port) {
      super(port);
      // TODO Auto-generated constructor stub
   }
   
   public int GetPressure()
   {
      //Method Header: PPS_ReadValue(byte port, byte reg,          byte count, byte addr)
      //Method Call:   PPS_ReadValue(S1,        PPS_REG_PRESS_ABS, 2,     PPS_ADDR)
      //Constants:              0x43             0x18
      
      byte[] outBuf = new byte[2];
      byte[] cmdBuf = new byte[2];

      cmdBuff[0] = 0x18;
      cmdBuff[1] = 0x43;

      //getData has no overload to input cmdBuff Array :/
      this.getData(0x43, outBuf, 2);

      int result = outBuf[1]*256 + outBuf[0];
      return result;
   }
   

}

skoehler
leJOS Team Member
Posts: 1550
Joined: Thu Oct 30, 2008 4:54 pm

Re: Mindsensors Pressure Sensor PPS58-Nx

Postby skoehler » Fri Feb 15, 2013 6:51 pm

So in the constructor, you don't initialize the I2C address of the sensor. It is 0x18. You can use a call to the super constructor to initialize the I2C address.

Secondly, use this.getData(0x53, outBuf, 4); According to the userguide at mindsensors.com, that will give you the 4 bytes of the RAW reading (pressue in pascal).
Use the class EndianTools to convert the 4 byte array into an 32bit integer. According to the NXC examples, the 4 bytes will be little endian.

You don't need a cmdBuff array. In NXC, the first byte of the cmdBuff is the address of the sensor (0x18), and the second byte is the register (0x53). Using getData(0x53, ...) does the same thing, as long as the address of the sensor has been configured properly.

The mind sensors userguide recommends, that using the raw value at 0x53 instead of the converted value at 0x43 provides the best resolution. Hence, I would use 0x53 and convert pascal to PSI, bar, or whatever as needed in Java.

fussel_dlx
New User
Posts: 7
Joined: Fri Feb 15, 2013 1:51 pm

Re: Mindsensors Pressure Sensor PPS58-Nx

Postby fussel_dlx » Fri Feb 15, 2013 9:29 pm

I've changed the code as you described:

Code: Select all

import lejos.nxt.I2CPort;
import lejos.nxt.I2CSensor;
import lejos.util.EndianTools;

public class PressureSensor extends I2CSensor {

   public PressureSensor(I2CPort port) {
      super(port,0x18, MODE_RAW, TYPE_CUSTOM);
      // TODO Auto-generated constructor stub
   }
   
   public int GetPressure()
   {
      byte[] outBuf = new byte[4];
      this.getData(0x53, outBuf, 4);
      
      return EndianTools.decodeIntLE(outBuf, 0);
   }
   
}


But it always returns 0, could you tell me what I have to type as "int off" in decodeIntLE?

skoehler
leJOS Team Member
Posts: 1550
Joined: Thu Oct 30, 2008 4:54 pm

Re: Mindsensors Pressure Sensor PPS58-Nx

Postby skoehler » Fri Feb 15, 2013 9:48 pm

Please try
super(port, 0x18, I2CPort.LEGO_MODE, TYPE_LOWSPEED);

MODE_RAW and TYPE_CUSTOM won't work.

The off (which is short for offset) is the index of the first byte within the array. You use 0, which is correct.
Also, make sure to check the return value of getData() for errors.

fussel_dlx
New User
Posts: 7
Joined: Fri Feb 15, 2013 1:51 pm

Re: Mindsensors Pressure Sensor PPS58-Nx

Postby fussel_dlx » Sat Feb 16, 2013 12:59 pm

skoehler wrote:Please try
super(port, 0x18, I2CPort.LEGO_MODE, TYPE_LOWSPEED);

MODE_RAW and TYPE_CUSTOM won't work.

The off (which is short for offset) is the index of the first byte within the array. You use 0, which is correct.
Also, make sure to check the return value of getData() for errors.


thank you very much its working now :D

Here's my final code for RAW output:

Code: Select all

import lejos.nxt.I2CPort;
import lejos.nxt.I2CSensor;
import lejos.util.EndianTools;

public class PressureSensor extends I2CSensor {

   public PressureSensor(I2CPort port) {
      super(port, 0x18, I2CPort.LEGO_MODE, TYPE_LOWSPEED);
      // TODO Auto-generated constructor stub
   }
   
   
   public int GetPressureInPascal()
   {
      byte[] outBuf = new byte[4];
      this.getData(0x53, outBuf, 4);
      
      return EndianTools.decodeIntLE(outBuf, 0);
   }
   
}

skoehler
leJOS Team Member
Posts: 1550
Joined: Thu Oct 30, 2008 4:54 pm

Re: Mindsensors Pressure Sensor PPS58-Nx

Postby skoehler » Sat Feb 16, 2013 2:39 pm

Well, congratulations! Thanks for posting the code.
Do you object, if we include the driver with leJOS?
Could you try, whether you can use I2CPort.HIGH_SPEED instead of I2CPort.LEGO_MODE and it still works?

fussel_dlx
New User
Posts: 7
Joined: Fri Feb 15, 2013 1:51 pm

Re: Mindsensors Pressure Sensor PPS58-Nx

Postby fussel_dlx » Sat Feb 16, 2013 7:51 pm

That would be very nice, feel free to use it.

I've tried your change and it's still working, I couldn't see any changes.

I hope this will help other noobs like me :)

skoehler
leJOS Team Member
Posts: 1550
Joined: Thu Oct 30, 2008 4:54 pm

Re: Mindsensors Pressure Sensor PPS58-Nx

Postby skoehler » Sat Feb 16, 2013 9:20 pm

This class will be part of the next leJOS release:
https://sourceforge.net/p/lejos/code/69 ... ensor.java


Return to “NXJ Hardware”

Who is online

Users browsing this forum: No registered users and 1 guest