I2C COMMUNICATIONS EXAMPLE - I2C TEMP SENSOR
What follows is a demonstration example of I2C transfer data from a digital sensor to a Picolog DA (DrDAQ in this case). The enclosed sketch is only valid for the LM75 Digital Temperature Sensor. With I2C communications the Micro acts as Master, while the sensor is the Slave, so there cannot be an “universal sketch” in I2C. For each sensor a special sketch must be prepared: luckily in most cases the vendors of the sensors make available on line simplified sketches that provide a starting point.
For details on I2C comms please consult the exhaustive literature available . The data sheet of the LM75 IC can be downloaded here:
Data sheet : http://esd.cs.ucr.edu/labs/temperature/LM75.pdf
The use of this module is straightforward, because of the Library that can be downloaded here.
Once you have downloaded and de-compressed the Library, you will have a “LM75-master” folder, which stores file cpp and file h. In the folder you will find two TEXT files named “LM75”. You must open: SYSTEM (C:) – PROGRAMS - ARDUINO – LIBRARIES. Here make a folder named “LM75” and place the two files inside. Later when you open the enclosed sketch you will note “#include <LM75.h>": this is the Library you have just inserted in the Libraries folder. Our demonstration sketch uses two libraries: Wire.h for I2C Communications and L75.h for reading the sensor digital outut.
With reference to Photos Micro Shield 4 (M) and LM75 Module(L) disconnect the two wires going from the Test Voltages Board (TSB) and terminals A4 (G) and A5 (H) of the Shield. Now wire the LM75 Module as shown in the photo.
Download the sketch: sketch_Analog_&_I2C_°C and paste it on an open blank Arduino IDE, as directed per previous Analogue sketch. Compile it. If compiles, load it and open the Serial Monitor. The SM will display: sensor equivalent voltage, ambient temperature and two Analogue channels. The correspondence between ambient temperature, as read by the L75.h Library and equivalent sensor voltage is 10 mV/°C: e.g., 0 @ 0 °C and 1V @100 °C.
Sketch_Analog_&_I2C_°C has been written by merging the Sensor Sketch contained in the “examples” – “Basic Usage” folders of the LT75-master directory with the previously discussed sketch_Analog_IN_PWM_OUT, while removing the Analogue functionality of Micro pins A4 & A5 and corresponding outputs.
With this sketch the PWM carrying the temperature data is connected to pin D10 of the Micro: to see temperture on Picolog, connect one of the DA input channels (example: EXT. 3 on the DrDAQ) to pin D10, then open a Math channel to convert voltage into temperature.
The enclosed PC screen shows the Picolog data display. Picolog receives the PWM and reads the corresponding temperature equivalent voltage. Then a Math channel is used to convert this voltage back to temperature. More data and the PLW file in the next post.
Operation is well illustrated in the enclosed Photos & PC screens.