LPS22HB click driver
mwroberts
Posts: 75
in Propeller 2
I wanted to do some testing with these LS22HB pressure sensors for potential altitude control for a drone. I saw there is a LS22HB click board, so I thought I would try and write a driver that someone else also might be able to use. I used Jon's click module template and his I2C driver. I used the same I2C pin outputs that the click board uses. I wanted to set the LS22HB to output data at 75 samples a second, and have a cog running that polls the fifo buffer and reads new pressure and temperature data as it becomes available, and in the background updates the pressure and temperature variables in the object.
First I got the basic functionality working, setting the registers, reading the fifo status bits, everything was working. Then I started a new cog to do the polling on the fifo status bits, but none of the I2C methods would work in the new cog. The only way I could get it to work was by doing all of the I2C stuff in the new cog... am I missing something on scope or instances of objects? or is it something about the I2C object?
I am amazed at the resolution of these pressure sensors, being able to sense just a couple of feet difference in altitude. And how the two different sensors tracked each other. (I added a offset to the second sensor to bring it closer to the first sensor in the graphic output.)
And I love the new graphical output modes... plot, trace... really nice!
First I got the basic functionality working, setting the registers, reading the fifo status bits, everything was working. Then I started a new cog to do the polling on the fifo status bits, but none of the I2C methods would work in the new cog. The only way I could get it to work was by doing all of the I2C stuff in the new cog... am I missing something on scope or instances of objects? or is it something about the I2C object?
I am amazed at the resolution of these pressure sensors, being able to sense just a couple of feet difference in altitude. And how the two different sensors tracked each other. (I added a offset to the second sensor to bring it closer to the first sensor in the graphic output.)
And I love the new graphical output modes... plot, trace... really nice!
spin2
993B
Comments
Jon,
If i2c.read(i2cACK) returns a long, then...
take this line for instance...
"reply1.byte[2] := i2c.read(i2c.ACK) "
do the 4 bytes that i2c.read() returns go into reply1.byte[2], reply1.byte[3], reply2.byte[0], reply2.byte[1]?
That looks cleaner than all the shifting right I was doing, and I neglected the sign extensions.
And the scaling...
I will clean it up and try to post it to git hub. (or email i tto parallax and have them do it like you said in as earlier post)
Mike
Here's a bit of test code that demonstrates: And here's the output: The value on the left is random, the value on the right is what we're building up one byte at a time. You can see at each step, only the target byte of the output value is affected, and it gets byte 0 of the return value. What this means is that the assignment operator behaves differently based on the size of the variable being assigned.