It travels along the bus, and “notifies” the matching device that it has some data coming… Wire.write(0) // sends 0 down the bus This sends the device address down the SDA (data) line of the bus. So to set the wiper to zero, we would use the following three functions: Wire.beginTransmission(0x2F) // part address is 0x2F or 0101111 Then we want to set the wiper value, which is a value between 0 and 127, or 0x00 and 0x7F in hexadecimal. For example, the address of the part in example 20.1 (below) is 00101111 (binary) which is 0X2F in hexadecimal. Sendingdata from our Arduino to the I2C devices requires two things: the unique device address (we need this in hexadecimal) and at least one byte of data to send. Then use the function Wire.begin() inside of void setup() and we’re ready to go. It is possible to use two devices with identical addresses on an I2C bus, but that will be discussed in a later article.Īs like most devices, we make use of an Arduino library, in this case. We use that address in the functions described later on to direct our read or write requests to the correct device. By now you should be thinking “how do we differentiate each device on the bus?”… Each device has a unique address. We can write data to a device, or read data from a device. In our Arduino situation, the board is the master and the devices on the I2C bus are the slaves. This distance can be extended with the use of a special IC, which we will examine during the next I2C chapter.Įach device can be connected to the bus in any order, and devices can be masters or slaves. The maximum length of an I2C bus is around one metre, and is a function of the capacitance of the bus. Sometimes you may see in a particular device’s data sheet the use of different value pull-up resistors – for example 4.7k ohm. Like anything, some testing on a breadboard or prototype circuit will determine their necessity. However if you are running a string of devices, use two 10 kilo ohm resistors. If you are only using one I2C device, the pull-up resistors are (normally) not required, as the ATmega328 microcontroller in our Arduino has them built-in. If you have another type of board, check your data sheet or try the Arduino team’s hardware website.Īnd finally, if you are using a bare DIP ATmega328-PU microcontroller, you will use pins 27 for SDA and 28 for SCL. The bus wiring is simple: If you are using an Arduino Mega, SDA is pin 20 and SCL is 21, so note that shields with I2C need to be specifically for the Mega. Those of you with an Arduino Uno or 100% compatible board, you will be using pins A4 for SDA (data) and A5 for SCL (clock): There are many applications, such a real-time clocks, digital potentiometers, temperature sensors, digital compasses, memory chips, FM radio circuits, I/O expanders, LCD controllers, amplifiers, and so on.Īnd you can have more than one on the bus at any time, in fact the maximum number of I2C devices used at any one time is 112.įrom a hardware perspective, the wiring is very easy. And our Arduino boards can control them all. Here is a nice introductory video from NXP:Īs there are literally thousands of components that use the I2C interface. This reduced the number of wires to two (SDA – data, and SCL – clock). In the late 1970s, Philips’ semiconductor division (now NXP) saw the need for simplifying and standardising the data lines that travel between various integrated circuits in their products. I2C is an acronym for “Inter-Integrated Circuit”. Furthermore it would be in your interest to have an understanding of the binary, binary-coded decimal and hexadecimal number systems. In this article we will learn the necessary theory, and then apply it by controlling a variety of devices. The I2C bus can be a complex interface to master, so we will do my best to simplify it for you. In this first of several tutorials we are going to investigate the I2C data bus, and how we can control devices using it with our Arduino systems.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |