Close

howto i2c with Zipit

A project log for repurposed luminiferous aether detector

over the last few years, i've build up a functional laser interferometer. now i want to use it to accurately measure distance.

beaglebreathBeaglebreath 07/09/2014 at 07:490 Comments

The following code controls a Microchip Technology Inc.'s MCP9804 digital temperature sensor.

The following was developed on a Zipit Z2 running openWRT.  The distribution includes the nano text editor and picoc c language compiler.  Some of the following code was blatantly cut and paste from other peoples web sites and from many many internet searches.  

The first half of the code executes a user command and pipes the output of the command into an array of chars.  The user command that gets executed is:

i2cget -y 0 0xlf 0x05 w

The second half of the code rearranges the order of the chars since they are received from the i2c sensor in a funny order.  After rearrangement, the array of chars is converted to an integer.  The most significant three bits are masked off.  The remaining integer can take a value from 0 to 8192 representing temperatures from -40 °C to 125 °C.

Discussions