0% found this document useful (0 votes)
88 views

Arduino Basics

The document discusses I2C and SPI communication protocols. I2C uses two lines, SCL for clock and SDA for data transfer. One device acts as master to coordinate information transfer between slave devices. SPI uses separate lines for input, output and clock between a master and one or more slaves. An example is given of an I2C master communicating with multiple I2C slave devices.

Uploaded by

jeet kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views

Arduino Basics

The document discusses I2C and SPI communication protocols. I2C uses two lines, SCL for clock and SDA for data transfer. One device acts as master to coordinate information transfer between slave devices. SPI uses separate lines for input, output and clock between a master and one or more slaves. An example is given of an I2C master communicating with multiple I2C slave devices.

Uploaded by

jeet kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

I2C

• I2C The two connections for the I2C bus are called
SCL and SDA.
• These are available on a standard Arduino board using
analog pin 5 for SCL, which provides a clock signal,
and analog pin 4 for SDL, which is for transfer of data
(on the Mega, use digital pin 20 for SDA and pin 21 for
SCL).
• One device on the I2C bus is considered the master
device. Its job is to coordinate the transfer of
information between the other devices (slaves) that are
attached.
• There must be only one master, and in most cases the
Arduino is the master, controlling the other chips
attached to it. Figure 13-1 depicts an I2C master with
multiple I2C slaves.
An I2C master with one or more I2C slaves
SPI
• SPI Recent Arduino releases (from release
0019) include a library that allows
communication with SPI devices. SPI has
separate input (labelled “MOSI”) and output
(labelled “MISO”) lines and a clock line. These
three lines are connected to the respective
lines on one or more slaves. Slaves are
identified by signalling with the Slave Select
(SS) line. Figure shows the SPI connections.
BME280 I2C or SPI Temperature
Humidity Pressure Sensor
Responding to Changes in Voltage

Domain of Embedded Systems, SEEE, LPU.


Domain of Embedded Systems, SEEE, LPU.
Measuring Voltages More Than 5V
(Voltage Dividers)

Domain of Embedded Systems, SEEE, LPU.


Domain of Embedded Systems, SEEE, LPU.
Arduino Sketch

Domain of Embedded Systems, SEEE, LPU.


• Connecting and Using LEDs:

Domain of Embedded Systems, SEEE, LPU.


Domain of Embedded Systems, SEEE, LPU.
Adjusting LED brightness

Domain of Embedded Systems, SEEE, LPU.


Arduino Sketch

Domain of Embedded Systems, SEEE, LPU.


Fading of LED using PWM
/*
* LedBrightness sketch
* controls the brightness of LEDs on analog output ports
*/
const int firstLed = 3; // specify the pin for each of the LEDs
const int secondLed = 5;
const int thirdLed = 6;
int brightness = 0;
int increment = 1;
void setup()
{
// pins driven by analogWrite do not need to be declared as outputs
}

Domain of Embedded Systems, SEEE, LPU.


void loop()
{
if(brightness > 255)
{
increment = -1; // count down after reaching 255
}
else if(brightness < 1)
{
increment = 1; // count up after dropping back down to 0
}
brightness = brightness - increment; // increment (or
decrement sign is minus)
// write the brightness value to the LEDs
analogWrite(firstLed, brightness);
analogWrite(secondLed, brightness);
analogWrite(thirdLed, brightness );
delay(10); // 10ms for each step change means 2.55 secs to
fade up or down
}

You might also like