Electronic Basics #19: I2C and how to use it

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Cool video, but the guy writes his '1' really weird.

šŸ‘ļøŽ︎ 4 šŸ‘¤ļøŽ︎ u/few_boxes šŸ“…ļøŽ︎ Feb 29 2016 šŸ—«︎ replies
Captions
if you ever implemented a real complex ICU with many functions like telling you the exact date and time expanding your eye outputs with 16 12 bit pwm pins or receiving your favorite FM radio station in your project then you might be familiar with I squared C also known as two-wire interface it is a popular communication protocol that allows one or more master devices in this case not we know Nano to talk to up to one hundred and twelve slave devices to either tell them what to do or to receive data from them which they acquired so in this video I will tell you the basics of the synchronous serial bus and present you a practical example woman Arduino and the TA of five seven six seven FM radio I see let's get started before connecting the IC to the master device I first get to create a small breakout boards for that I simply scored in status reports solid 5 pin mail header on to its short sides interrupted the copper traces in the middle fix the IC on the board with hot glue and finally connected the mail header would the pins through silver copper wire then I connected ground 5 volts the antenna and the audio output to my headphones according to my small schematic the two I scratchy pins SDA aka serial data connects to pin a 4 of the Arduino and s CL aka serial clock connects to pin a 5 the last remaining components are two 10 kilo ohm resistors which act as a pull-up resistor for the tool I squared C lines this is necessary because the devices have an open collector configuration which means they can only connect the clock and signal line to ground but since we need to stay below touch States to define the two binary States over bits the resistors pull the lines up to 5 volts after powering up the circuits it was obvious that the audio outputs would deliver nothing useful because the correct code is still missing the most important resource of information when it comes to I square C devices or generally every I see is the datasheet there we can find what kind of bits or high-low States we have to send in order to tune in a certain frequency nute the audio or choose the correct region so it's definitely a good idea to print out those pages firstly we need to send a start condition which means the serial data folds while the clock stays high but don't worry the wire library of the arduino does this automatically when a transmission begins then we need to send the address which is usually a fixed 7 bit value which is always mentioned in the datasheet afterwards follows the RW bits which is 0 if you want to write to the slave or one if you want to read from the slave once again the library handles this on its own depending on whether you choose begin transmission or request from an acknowledge bits is the neck which is sent out by the slave to let the master know that it is ready for the next bite aka eight bits of data and here starts the fun part since we need to send our five data bytes which actually tell the slave what to do it is pretty easy to choose most of the bits correctly by studying the data sheet but the first and second bytes are a bit special then we need to define the PLL value which directly defines the frequency we want to tune in according to this given formula as an example I will use ninety five point six megahertz and get a decimal value of eleven thousand six hundred ninety seven after the calculation this can be converted to binary or wolf an online calculator or by hand but we could also compress it into a hexadecimal value which is more common than riding along binary codes again an online calculator or small hands-on calculation delivers us the necessary value we need for byte one and two and while I was at it I also converted the rest of the binary values into hexadecimal by simply following a charge which represents the relation to each other now that we got all our bits I typed them into my sketch and finalized this data transmission new bestop bits which pulls the data higher while the clock is high after uploading the sketch I was capable of listening to a radio station but since it was rather quiet I hooked up an amplifier with a speaker in order to hear it clearly and as you might already have noticed it works just as expected it is also a good exercise to use nozzle scope in order to decipher the different bit States one data bits is only valid when it's state is constant high or low over the complete period of the clock pulse which has a frequency of 100 kilo Hertz and is provided by the master after I was sure that I recorded the exact byte series I entered into the Arduino IDE I began to write an I squared C Reed function all the same theory applies as well except for the acknowledge bits which the master generates this time by storing the received data in the buffer and some evaluation of the first and second bites I can easily output the tuned FM station to the serial monitor and of course you can add more slave devices to your bus and control all of them with the same previous before as you can see using I squared C is not difficult as long as you study the data sheet carefully but don't think this is the only communication protocol there's also SPI one wire interface and plenty more but that is a subject for another video until then don't forget to Like share and subscribe stay creative and I will see you next time
Info
Channel: GreatScott!
Views: 336,480
Rating: 4.9128618 out of 5
Keywords: I2C, i2c, tutorial, how to, arduino, fm, ic, tea5767, radio, example, practical, nano, greatscott, electronics, basic, basics, electronic basics, bit, binary, hexadecimal, decimal, wire library, wire.h
Id: _fgWQ3TIhyE
Channel Id: undefined
Length: 6min 8sec (368 seconds)
Published: Sun Feb 28 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.