B & B Thermotechnik DRMOD-I2C-RxB Pressure Sensor Module

Share code examples with other users

B & B Thermotechnik DRMOD-I2C-RxB Pressure Sensor Module

Postby Timbo » Wed Mar 04, 2015 2:02 pm

This device is a pressure sensor that has a i2c interface built in. So far I'm really quite impressed with it.

The ASIC inside does all the A/D conversions and linearizations and can output a 15bit representation of the pressure (only 12 are used). They do make a range of devices that uses the ASIC so I would imagine this code will work with all of them.

This is a link to the info on the ASIC http://www.produktinfo.conrad.com/daten ... ERATUR.pdf

Serial Digital Interface of HYGROSENS ASIC

Big thanks to Dave for the code.

Code: Select all
// tested on Firewing for PIC24 board R2, compiler Firewing 16
// configure then import module...
#option I2C_SCL = _D2   ' 5v tolerent on PIC24, PIC32
#option I2C_SDA = _D3   ' 5v tolerent on PIC24, PIC32
#option I2C_DELAY_US = 3
imports I2c             

// device constants...
private const START_CYC_RAM as byte = &H02
private const CFG_SIF_TO_I2C as byte = &H52
private const START_NOM as byte = &H71
private const I2C_DEVICE_ADDRESS as byte = &H78 << 1

// program entry point...
Sub Main()

   // Start measurement cycle including initialization from
   // RAM - processing time is 220us
   I2C.Start()
   I2C.WriteByte(I2C_DEVICE_ADDRESS)
   I2C.WriteByte(START_CYC_RAM)   
   I2C.Stop()
   delayms(1)
         
   // Configure SIF to Communication Mode I2C
   I2C.Start()
   I2C.WriteByte(I2C_DEVICE_ADDRESS)
   I2C.WriteByte(CFG_SIF_TO_I2C)
   I2C.Stop()
       
   // Start Normal Operation Mode (NOM). In Normal Operation Mode
   // the command set is restricted
   I2C.Start()
   I2C.WriteByte(I2C_DEVICE_ADDRESS)
   I2C.WriteByte(START_NOM)
   I2C.Stop() 
   
         
   // loop forever...
   while true           
   
      // read data - high byte, low byte
      // The pressure is transferred as 15 bit value (bit 0 – 14). From the 15
      // bit measured values, approx. 12 bit are used as resolution, the three
      // least significant bits can be ignored.
      dim result as ushort
      I2C.Start()                 
      I2C.WriteByte(I2C_DEVICE_ADDRESS + 1)                                     ' Address the device and tell it you want to do a read by setting the LSB to 1
      result.byte1 = I2C.ReadByte()                                             ' Read in the MSB
      I2C.Acknowledge(IsAcknowledge)                                            ' Send an ACK
      result.byte0 = I2C.ReadByte()                                             ' Read in the LSB
      I2C.Stop()                                                                ' Send the stop
      result = result >> 3                                                      ' Were interested in only 12 bits
                                                                               
      // display result via UART...
      Console.Write("value = ", cstr(result),13,10)                             ' Display the results
      delayms(500)
   end while

End Sub
Timbo
 
Posts: 93
Joined: Fri May 03, 2013 7:51 pm

Re: B & B Thermotechnik DRMOD-I2C-RxB Pressure Sensor Module

Postby David John Barker » Wed Mar 04, 2015 2:55 pm

Thanks for allowing us to share the code Tim! What kind of jitter, if any, do you get from the device?
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: B & B Thermotechnik DRMOD-I2C-RxB Pressure Sensor Module

Postby Timbo » Wed Mar 04, 2015 3:09 pm

The device has a resolution over 0-6bar of around 2mbar per bit at 12bits. So on the boundary of a change it will jitter between 2 values.

I'm polling it every 0.5 seconds and its not changing every read.

I'm going to up it to 100hz and also see what 15 bits looks like and then run it through a averaging algo.
Timbo
 
Posts: 93
Joined: Fri May 03, 2013 7:51 pm

Re: B & B Thermotechnik DRMOD-I2C-RxB Pressure Sensor Module

Postby Timbo » Wed Mar 04, 2015 7:43 pm

Just to add it seems you do not need all the setup code this seemed to work fine on its own


Code: Select all
// tested on Firewing for PIC24 board R2, compiler Firewing 16
// configure then import module...
#option I2C_SCL = _D2   ' 5v tolerent on PIC24, PIC32
#option I2C_SDA = _D3   ' 5v tolerent on PIC24, PIC32
#option I2C_DELAY_US = 3
imports I2c             

// device constants...
private const START_CYC_RAM as byte = &H02
private const CFG_SIF_TO_I2C as byte = &H52
private const START_NOM as byte = &H71
private const I2C_DEVICE_ADDRESS as byte = &H78 << 1

   
         
   // loop forever...
   while true           
   
      // read data - high byte, low byte
      // The pressure is transferred as 15 bit value (bit 0 – 14). From the 15
      // bit measured values, approx. 12 bit are used as resolution, the three
      // least significant bits can be ignored.
      dim result as ushort
      I2C.Start()                 
      I2C.WriteByte(I2C_DEVICE_ADDRESS + 1)                                     ' Address the device and tell it you want to do a read by setting the LSB to 1
      result.byte1 = I2C.ReadByte()                                             ' Read in the MSB
      I2C.Acknowledge(IsAcknowledge)                                            ' Send an ACK
      result.byte0 = I2C.ReadByte()                                             ' Read in the LSB
      I2C.Stop()                                                                ' Send the stop
      result = result >> 3                                                      ' Were interested in only 12 bits
                                                                               
      // display result via UART...
      Console.Write("value = ", cstr(result),13,10)                             ' Display the results
      delayms(500)
   end while

End Sub

Timbo
 
Posts: 93
Joined: Fri May 03, 2013 7:51 pm

Re: B & B Thermotechnik DRMOD-I2C-RxB Pressure Sensor Module

Postby Timbo » Fri Mar 06, 2015 10:23 am

I have added a conversion routine to BarA in case its of use. I have only been able to check it upto 3.5barA, I have to say its really very good. Within 1 or 2 mbar across the range.

Code: Select all
// device constants...
private const START_CYC_RAM as byte = &H02
private const CFG_SIF_TO_I2C as byte = &H52
private const START_NOM as byte = &H71
private const I2C_DEVICE_ADDRESS as byte = &H78 << 1

// program entry point...
Sub Main()

    Dim Tally as Ulong = 0
    DIm Index as byte = 0
    Dim TallyAverage as Ushort
    Dim Barg as Ushort   
         
   // loop forever...
   while true           
   
      // read data - high byte, low byte
      // The pressure is transferred as 15 bit value (bit 0 – 14). From the 15
      // bit measured values, approx. 12 bit are used as resolution, the three
      // least significant bits can be ignored.
      dim result as ushort
      I2C.Start()                 
      I2C.WriteByte(I2C_DEVICE_ADDRESS + 1)                                     ' Address the device and tell it you want to do a read by setting the LSB to 1
      result.byte1 = I2C.ReadByte()                                             ' Read in the MSB
      I2C.Acknowledge(IsAcknowledge)                                            ' Send an ACK
      result.byte0 = I2C.ReadByte()                                             ' Read in the LSB
      I2C.Stop()                                                                ' Send the stop
      result = result >> 1                                                      ' Were interested in only 14 bits
       

   
    if Index < 100 then
       Tally = Tally + result
       Index = Index + 1
    else
       TallyAverage = Tally / 100
       Tally = 0   
       Index = 0
       // display result via UART...   
       Barg = PRawToBarA(TallyAverage)     
       Console.Write("BarA = ", cstr(Barg),13,10)                             ' Display the results       
    end if

    delayms(5)
   end while
                       
 End Sub 
   
   Function PRawToBarA(value As Ushort) As Ushort
      Dim TempL as Ulong
      Dim TempS as UShort
      Const Span as Ulong = 367431
      Const Offset as Ushort = 1030
      Const Divider as Ulong = 1000000
      TempL = value * Span
      TempS = TempL / Divider
      TempS = TempS + Offset
      return TempS
   End Function
Timbo
 
Posts: 93
Joined: Fri May 03, 2013 7:51 pm

Re: B & B Thermotechnik DRMOD-I2C-RxB Pressure Sensor Module

Postby David John Barker » Fri Mar 06, 2015 11:23 am

Again, thanks for sharing your code ;-)

One thing I will mention is that you removed the initialisation code in a previous post. There is nothing wrong in doing this. After all, the device defaults to these settings anyway. However, I personally prefer to explicitly configure a device, especially if a product is likely to go into production. Explicit initialisation serves a number of purposes. For example:

  • It helps document your code.
  • If another device is plugged in the future and the manufacture spec has slightly changed, your firmware will still correctly initialise the device.
  • It guarantees a known start-up condition during power up. That is, how confident are you that your device will be in the default state at power up in any given environment?
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: B & B Thermotechnik DRMOD-I2C-RxB Pressure Sensor Module

Postby Timbo » Fri Mar 06, 2015 12:28 pm

Ok that's why it was there.

I will put it back in my code.
Timbo
 
Posts: 93
Joined: Fri May 03, 2013 7:51 pm


Return to Code Examples

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x