require "i2c" ADRS = 0x5c # LPS25H NODE = "/dev/i2c-1" # I2C device node def to_int16( b1, b2 ) return (b1 << 8 | b2) - ((b1 & 0x80) << 9) end def to_uint24( b1, b2, b3 ) return (b1 << 16) | (b2 << 8) | b3 end i2c = I2C.create(NODE) res = i2c.read(ADRS, 1, 0x0f) printf "RESULT: 0x%02x\n", res.getbyte(0) i2c.write(ADRS, 0x20, 0x90) sleep 1 buf = i2c.read(ADRS, 5, 0xa8) # Read 5 bytes from 0x28 register with cont mode. p_cnt = to_uint24(buf.getbyte(2), buf.getbyte(1), buf.getbyte(0)) p p_cnt.to_f / 4096 t_cnt = to_int16(buf.getbyte(4), buf.getbyte(3)) p 42.5 + t_cnt.to_f / 480