Hadeel Elayyan Report Interface For Exp#2
Hadeel Elayyan Report Interface For Exp#2
Hadeel Elayyan Report Interface For Exp#2
INTERFACING LABORATORY
ENCS412
Report #2
Prepared by:
Hadeel Elayyan 1150192
Partners:
Aseel Hamadna 1150031
Section: 1
Date: 27-2-2019
Table of Contents
Abstract.........................................................................................................................................II
Theory..............................................................................................................................................1
I2C...............................................................................................................................................1
LM75B temperature sensor.........................................................................................................2
Seven Segment.............................................................................................................................3
Procedure & Discussion..................................................................................................................4
Part 1: LM75B temperature sensor..............................................................................................4
Discussion for the code :..........................................................................................................4
Part 2: SEVEN-SEGMENTS......................................................................................................5
Discussion for the code :..........................................................................................................6
Conclusion.......................................................................................................................................9
References......................................................................................................................................10
I
Abstract
The aims of this experiment are understand the concept of I2C in order to read temperature
from LM75B temperature sensor and measure it in Celsius and Fahrenheit , also how to connect
two seven segments together with arduino and display two digits number.
II
Theory
I2C
The term IIC stands for “Inter Integrated Circuits” and denoted as I2C or I squared C . I2C is a
synchronous communication protocol , the devices that are sharing the information both must
share a common clock signal. also there are only two wires in I2C to share information out of
which one is used for the cock signal and the other is used for sending and receiving data[1].
I²C uses 2 signals for transferring data between devices, this halves the SPI’s 4 wire
communication protocol see Figure 1. The signals we will use are called:
Data signal (SDA) – This is where all of our control information and data is
sent/received. Everything is sent on this signal and can be sent anywhere on the bus.
A clock signal (SCL) – This is purely for regulating the speed the data is sent. The
slave devices will sample a bit from the data stream in synchronization with this signal.
We use I2C because it is Far easier to use than SPI, uses fewer connections than SPI
,supports a multi-master system, rather than SPI’s one master, infinite-slaves system, and
100% compatible with our Arduino Uno.
1
LM75B temperature sensor
The LM75B _see figure 2_ is a temperature-to-digital converter using an on-chip band gap
temperature sensor and Sigma-Delta A-to-D conversion technique with an over temperature
detection output. The LM75B powers up in the normal operation mode with the OS in
comparator mode, temperature threshold of 80 °C and hysteresis of 75 °C, so that it can be used
as a stand-alone thermostat with those pre-defined temperature set points. The LM75B contains a
number of data registers, that can be communicated by a controller via the 2-wire serial I²C-bus
interface. The device also includes an open-drain output (OS) which becomes active when the
temperature exceeds the programmed limits. The LM75B have many features like I²C-bus
interface with up to 8 devices on the same bus ,power supply range from 2.8 V to 5.5 V
,temperatures range from -55 °C to +125 °C ,frequency range 20 Hz to 400 kHz with bus fault
time-out to prevent hanging up the bus ,11-bit ADC that offers a temperature resolution of 0.125
°C ,and temperature accuracy of:±2 °C from -25 °C to +100 °C , ±3 °C from -55 °C to +125
°C_see pins description for the sensor in Table 1_.[2]
Figure 2 : LM75BD
2
Seven Segment
3
Procedure & Discussion
Firstly ,we connected the LM75B temperature sensor_ shown in Figure 6 _ to arduino , also we
know the location of the SCL and SCL pins in arduino from the other side of the arduino as
shown in Figure 7 , then we wrote a code to read the temperature from the sensor using I2C
protocol.
Figure 6: Connection LM75B with the arduino Figure 7: SDA and SCL pins
First segment :
#include <Wire.h>
int LM75BAddress = 0x48;
void setup(){
Wire.begin();
}
4
In this segment we used wire library which allows you to communicate with I2C / TWI devices
, then we declared the address for the LM75B sensor which is equal to 0x48 ,finally ,we Initiate
the Wire library and join the I2C bus as a master or slave by using wire.begin().
Second segment :
float getTemperature(){
Wire.requestFrom(LM75BAddress,2);
Figure 7: Result
Part 2: SEVEN-SEGMENTS
Firstly ,we connected two seven segments in order to display the average of the last digit from
the ID number for the members of the group . The two seven segments are common anode which
5
means if we want to light the led's we connect them to ground , and connect one of the enable
pins (3,8) to the VCC , the connection shown in the figure 8.
First segment :
void loop() {
digitalWrite(enable1,HIGH);
digitalWrite(enable2,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
6
digitalWrite(a,HIGH);
digitalWrite(d,HIGH);
digitalWrite(f,HIGH);
digitalWrite(e,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dot,LOW);
delay(5);
digitalWrite(enable2,HIGH);
digitalWrite(enable1,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(a,LOW);
digitalWrite(d,LOW);
digitalWrite(f,LOW);
digitalWrite(e,HIGH);
digitalWrite(g,LOW);
digitalWrite(dot,HIGH);
delay(5);
In this segment we want to display number one in the first segment with dot symbol ,so we
write logic 0 to the pins b, c and dot to light them, also we write logic 1 to enable1 and 0 to
enable 2 to enable the first seven segment and disable the second one for 5ms, then for the
7
second seven segments we want to display the number 5, so we write logic 0 the pins a, f, d, c
and g, to light them , also we write logic 1 to enable2 and 0 to enable 1 to enable the second
seven segment and disable the first one for 5ms. The result is shown in Figure 9.
Figure 9: result
8
Conclusion
In this experiment we knew what's I2C means , and how this protocol works , also we knew
what are the main two wires in I2C , in addition we learned some information about the LM75B
temperature sensor ,and how it reads the temperature using I2C by using the address of the
sensor ,finally we knew how to connect two seven segment together, and how to display number
with two digits .
9
References
[1] https://circuitdigest.com/microcontroller-projects/arduino-i2c-tutorial-communication-
between-two-arduino.
[2] https://www.nxp.com/docs/en/data-sheet/LM75B.pdf
[3] https://www.electronics-tutorials.ws/blog/7-segment-display-tutorial.html
10