Hadeel Elayyan Report Interface For Exp#2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Faculty of Engineering & Technology

Electrical & Computer Engineering Department

INTERFACING LABORATORY
ENCS412
Report #2

Two Wire Interface I2C Bus Multiplexed displays on Arduino

Prepared by:
Hadeel Elayyan 1150192

Partners:
Aseel Hamadna 1150031

Instructor: Dr. Hanna Bullata

Assistant: Eng. Ahmad Dar Khalil

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.

Figure 1: I2C Communication

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

Table 1:LM75B pins description

2
Seven Segment

A seven-segment display _shown in figure 3_  (SSD), or seven-segment indicator, is a form of


electronic display device for displaying decimal numerals that is an alternative to the more
complex dot matrix displays. The seven-segment display  consists of seven LEDs also an
additional 8th LED is sometimes used within the same package thus allowing the indication of a
decimal point. there are two types of LED 7-segment display , Common Cathode _shown in
figure 4_   the LED segments are joined together to logic “0” or ground, and Common Anode
_shown in figure 5_   (CA) the LED segments are joined together to logic “1” or HIGH[3].

Figure 3 : Seven segment Display

Figure 4: Common cathode

Figure 5 : Common Anode

3
Procedure & Discussion

Part 1: LM75B temperature sensor

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

Discussion for the code :

Note : the following segments of the code are not completed.

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);

byte MSB = Wire.read();

byte LSB = Wire.read();

int TemperatureSum = ((MSB << 8) | LSB) >> 4;

In this segment we used wire.requestFrom(address, quantity) which used by the master to


request bytes from a slave device. The bytes may then be retrieved with
the available() and read() functions , we put the address of the LM75B and the quantity equals 2 ,
which means two bytes to request , after that we used the function read to get the most
significant byte and the least significant byte , so because we have 16 bits , and the sensor read
12 bits only , we shift left the MSB by 8 bits then make a logical OR with LSB finally get rid of
the least four bits by shift right the result by 4 bits , the result shown in figure 7 .

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.

Figure 8: Connection for 2 7SEG

Discussion for the code :

Note : the following segment of the code is not completed.

First segment :

void loop() {

// put your main code here, to run repeatedly:

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.

Accessed on 27-2-2019 at 10:20 PM .

[2] https://www.nxp.com/docs/en/data-sheet/LM75B.pdf

Accessed on 28-2-2019 at 8:23 PM .

[3] https://www.electronics-tutorials.ws/blog/7-segment-display-tutorial.html

Accessed on 28-2-2019 at 9:00 PM .

10

You might also like