{"id":61866,"date":"2025-06-10T15:25:33","date_gmt":"2025-06-10T19:25:33","guid":{"rendered":"https:\/\/www.engineersgarage.com\/?p=61866"},"modified":"2025-06-11T12:18:48","modified_gmt":"2025-06-11T16:18:48","slug":"articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python","status":"publish","type":"post","link":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/","title":{"rendered":"RPi Python Programming 25 &#8211; Synchronous serial communication in Raspberry Pi using I2C protocol"},"content":{"rendered":"<p class=\"ai-optimize-6 ai-optimize-introduction\">In the <a href=\"https:\/\/www.engineersgarage.com\/microcontroller-projects\/articles-raspberry-pi-i2c-protocol\/\" target=\"_blank\" rel=\"noopener noreferrer\">previous tutorial<\/a>, we discussed the basics of the I2C protocol. In most of the embedded devices, either UART otherwise I2C is used for console messages. In this tutorial, we will discuss serial communication in Raspberry Pi using the I2C protocol.<\/p>\n<p class=\"ai-optimize-7\"><strong>I2C in Raspberry Pi<br \/>\n<\/strong>For serial communication over the I2C protocol, the Broadcom processor of Raspberry Pi has Broadcom Serial Controller (BSC). This standard-mode master BSC controller is NXP Semiconductor&#8217;s I2C compliant and supports a data transfer rate of 400 kbps. The BSC controller supports both 7-bit as well as 10-bit addressing. This I2C interface is accessible at pins GPIO2 (Board Pin No. 3) and GPIO3 (Board Pin No. 5). GPIO2 is Serial Data (SDA) line, and GPIO3 is a Serial Clock (SCL) line of the I2C1. These I2C pins are internally pulled up to 3.3V via 1.8 kohms resistors. That is why these pins cannot be used for general-purpose I\/O where pull-up is not required.<\/p>\n<p class=\"ai-optimize-8\"><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-61871\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-01.png\" alt=\"\" width=\"582\" height=\"339\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-01.png 1024w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-01-300x175.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-01-768x447.png 768w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-01-368x214.png 368w\" sizes=\"auto, (max-width: 582px) 100vw, 582px\" \/><\/a><\/p>\n<p class=\"ai-optimize-9\">There is one more I2C peripheral BSC2 in Raspberry Pi identified as I2C0. The BSC2 master is dedicated to the HDMI interface and cannot be accessed by users. This I2C interface is present at board pins 27 (ID_SD) and 28 (ID_SC). I2C0 remains reserved for reading EEPROM of Raspberry Pi&#8217;s add-on boards called Hardware on The Top (HAT) boards. I2C0 can only talk to HAT EEPROM at address 0x50 during boot time.<\/p>\n<p class=\"ai-optimize-10\">It is possible to access I2C0 only if both the camera interface and HDMI port are unused. To use I2C0, add the following lines to boot\/config.txt.<br \/>\n<strong><span style=\"color: #993300;\">dtparam=i2c_vc=on<\/span><\/strong><\/p>\n<p class=\"ai-optimize-11\">The I2C0 pins are not internally pulled up, so if they are used by modifying the Raspberry Pi configuration file, external pull-ups (to 3.3V) must be used on both SDA and SCL lines. While using I2C0, pins avoid using the HAT EEPROM address.<\/p>\n<p class=\"ai-optimize-12\">Even the I2C1 is disabled on Raspberry Pi by default. It needs to be enabled from the Raspberry Pi configuration. The Raspberry Pi&#8217;s BSC controllers support multi-master, multi-slave I2C. Therefore, I2C1 is sufficient to connect several I2C slaves (maximum 112 slaves) and any number of master devices.<\/p>\n<p class=\"ai-optimize-13\"><strong>Enabling I2C1 from Raspberry Pi GUI<\/strong><br \/>\nOn Raspbian, navigate to Pi Start Menu -&gt; Preferences -&gt; Raspberry Pi Configuration.<\/p>\n<p class=\"ai-optimize-14\"><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-02.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-61872\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-02-1024x576.png\" alt=\"\" width=\"566\" height=\"318\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-02-1024x576.png 1024w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-02-300x169.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-02-768x432.png 768w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-02-1536x864.png 1536w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-02-368x207.png 368w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-02.png 1920w\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" \/><\/a><\/p>\n<p class=\"ai-optimize-15\">In the pop-up window, click on the &#8216;Interfaces&#8217; tab and select the &#8216;Enable&#8217; radio button for I2C. You can also enable or disable other interfaces as required.<\/p>\n<p class=\"ai-optimize-16\"><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-03.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-61873\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-03-1024x576.png\" alt=\"\" width=\"553\" height=\"311\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-03-1024x576.png 1024w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-03-300x169.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-03-768x432.png 768w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-03-1536x864.png 1536w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-03-368x207.png 368w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-03.png 1920w\" sizes=\"auto, (max-width: 553px) 100vw, 553px\" \/><\/a><\/p>\n<p class=\"ai-optimize-17\">To take changes effect, restart Raspberry Pi. After rebooting, GPIO3 and GPIO5 can be used to connect Raspberry Pi as I2C master with an I2C bus or to any I2C slave.<\/p>\n<p class=\"ai-optimize-18\"><strong>Enabling I2C1 from Terminal<br \/>\n<\/strong>The I2C support for Raspberry Pi&#8217;s ARM core and Linux Kernel can also be enabled from the Terminal (Bash Shell on Raspberry Pi). Open Terminal and run the following command:<br \/>\n<strong><span style=\"color: #993300;\">sudo raspi-config<\/span><\/strong><\/p>\n<p class=\"ai-optimize-19\">In the Raspberry Pi Software Configuration Tool, navigate to &#8216;Interfacing Options&#8217;.<\/p>\n<p class=\"ai-optimize-20\"><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-04.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61874\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-04.png\" alt=\"\" width=\"644\" height=\"272\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-04.png 644w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-04-300x127.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-04-368x155.png 368w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/a><\/p>\n<p class=\"ai-optimize-21\">In older Raspberry Pi models, navigate to &#8216;Advanced Options&#8217; and then &#8216;I2C&#8217;.<\/p>\n<p class=\"ai-optimize-22\"><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-05.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-61875\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-05.png\" alt=\"\" width=\"916\" height=\"272\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-05.png 915w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-05-300x89.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-05-768x228.png 768w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-05-368x109.png 368w\" sizes=\"auto, (max-width: 916px) 100vw, 916px\" \/><\/a><\/p>\n<p class=\"ai-optimize-23\"><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-06.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-61876 size-full\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-06.png\" alt=\"\" width=\"916\" height=\"274\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-06.png 916w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-06-300x90.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-06-768x230.png 768w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-06-368x110.png 368w\" sizes=\"auto, (max-width: 916px) 100vw, 916px\" \/><\/a>In the pop-up window, enable the Arm I2C interface and select &#8216;Yes&#8217; to load the I2C Kernel Module.<\/p>\n<p class=\"ai-optimize-24\"><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-07.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61877\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-07.png\" alt=\"\" width=\"482\" height=\"322\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-07.png 482w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-07-300x200.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-07-356x238.png 356w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/a><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-08.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61878\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-08.png\" alt=\"\" width=\"479\" height=\"319\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-08.png 479w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-08-300x200.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-08-357x238.png 357w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/a>Now reboot Raspberry Pi by entering the following command:<br \/>\n<strong><span style=\"color: #993300;\">sudo reboot<\/span><\/strong><\/p>\n<p class=\"ai-optimize-25\">After rebooting, GPIO3 and GPIO5 can be used to connect Raspberry Pi as I2C master with an I2C bus or to any I2C slave.<\/p>\n<p class=\"ai-optimize-26\"><strong>Testing I2C port<br \/>\n<\/strong>After enabling I2C user-port and rebooting Raspberry Pi, we can test if the port is available as a Linux device or not. In the Terminal window, run the following command:<br \/>\n<strong><span style=\"color: #993300;\">ls \/dev\/<br \/>\n<\/span><\/strong>Or<br \/>\n<strong><span style=\"color: #993300;\">ls \/dev\/*i2c*<br \/>\n<\/span><\/strong>I2C1 must appear as one of the Linux devices available as shown in the image below.<\/p>\n<p class=\"ai-optimize-27\"><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-09.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61879\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-09.png\" alt=\"\" width=\"659\" height=\"422\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-09.png 659w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-09-300x192.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-09-368x236.png 368w\" sizes=\"auto, (max-width: 659px) 100vw, 659px\" \/><\/a><\/p>\n<p class=\"ai-optimize-28\">Note that in the older versions of Raspberry Pi, the I2C user port is identified as I2C0 instead of I2C1. In all 256M Raspberry Pi models, the I2C user port is 0, and in rest, all it is 1.<\/p>\n<p class=\"ai-optimize-29\"><strong>Scanning I2C slaves on Raspberry Pi<br \/>\n<\/strong>After enabling the I2C user port, the connected I2C slaves can be detected using i2c-tools. First of all, install the i2c-tools by running the following command in the Raspberry Pi Terminal:<br \/>\n<span style=\"color: #993300;\"><strong>sudo apt-get install -y i2c-tools<\/strong><\/span><\/p>\n<p class=\"ai-optimize-30\">Now run the following command to scan connected I2C slaves:<br \/>\n<strong><span style=\"color: #993300;\">sudo i2cdetect -y 1<\/span><\/strong><\/p>\n<p class=\"ai-optimize-31\">As already mentioned that in older versions of Raspberry Pi, I2C user port is 0, in older versions change the port number to 0 as follows:<br \/>\n<strong><span style=\"color: #993300;\">sudo i2cdetect -y 0<\/span><\/strong><\/p>\n<p class=\"ai-optimize-32\">The i2c-detect is a tool that scans the I2C user port and returns the I2C addresses of the connected slave devices. The tool returns a table of addresses of connected I2C slave devices as shown in the image below:<\/p>\n<p class=\"ai-optimize-33\"><strong><a href=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-61880\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-10.png\" alt=\"\" width=\"660\" height=\"397\" srcset=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-10.png 726w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-10-300x181.png 300w, https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/25R-10-368x222.png 368w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/a>Accessing I2C devices using SMBus library<br \/>\n<\/strong>On Raspberry Pi, the I2C bus can be accessed in a Python script using the SMBus library. SMBus is a subset of the I2C interface. The Python library for SMBus can be used to communicate with I2C based devices. The SMBus library can be installed on Raspberry Pi by running the following command:<br \/>\n<span style=\"color: #993300;\"><strong>sudo apt-get install python-smbus<\/strong><\/span><\/p>\n<p class=\"ai-optimize-34\">In a Python script, the SMBus library can be imported using the following statement:<br \/>\n<strong><span style=\"color: #993300;\">import smbus<\/span><\/strong><\/p>\n<p class=\"ai-optimize-35\">After importing SMBus library, an object of SMBus class must be created using the SMBus() method. The SMBus() method takes the I2C port number as a parameter and must be used in an assignment statement to create an SMBus object. It has the following syntax:<br \/>\n<span style=\"color: #993300;\"><strong>&lt;Object_name&gt; = smbus.SMBus(I2C_Port_Number)<\/strong><\/span><\/p>\n<p class=\"ai-optimize-36\">The following is a valid example of creating an SMBus object:<br \/>\n<strong><span style=\"color: #993300;\">i2c-bus = smbus.SMBus(1)<\/span><\/strong><\/p>\n<p class=\"ai-optimize-37\">Note that in older Raspberry Pi versions, I2C user port is 0, and in all Raspberry Pi versions above 256M RPi versions, it is 1. To use the latest SMBus2 library, it can be installed using pip by running the following command:<br \/>\n<strong><span style=\"color: #993300;\">pip install smbus2<\/span><\/strong><\/p>\n<p class=\"ai-optimize-38\">In a Python script, the SMBus2 library can be imported using the following statement:<br \/>\n<strong><span style=\"color: #993300;\">from smbus2 import SMBus, i2c_msg<\/span><\/strong><\/p>\n<p class=\"ai-optimize-39\">An object of SMBus class can be created using smbus2.SMBus() method as follows:<br \/>\n<strong><span style=\"color: #993300;\">i2c-bus = smbus2.SMBus(1)<\/span><\/strong><\/p>\n<p class=\"ai-optimize-40\">The smBus2 library has two classes &#8211; SMBus and i2c_msg. The SMBus class supports the following methods:<br \/>\n<strong><span style=\"color: #993300;\"><em>smbus.SMBus()\/smbus2.SMBus()<\/em><\/span><\/strong> &#8211; To create an SMBus object in Python script.<br \/>\n<strong><span style=\"color: #993300;\"><em>open(bus)<\/em><\/span><\/strong> &#8211; To open a given i2c bus.<br \/>\n<strong><span style=\"color: #993300;\"><em>close()<\/em><\/span><\/strong> &#8211; To close I2C connection.<\/p>\n<p class=\"ai-optimize-41\">The serial data from an I2C slave can be read in bytes, words or block of bytes. In some I2C slave devices, master need to access serial data from specific registers. The following methods are available in SMBus2 library for reading serial I2C data from slave devices:<br \/>\n<em>read_byte(i2c_addr,force=None)<\/em> &#8211; To read a single byte from a device.<br \/>\n<strong><span style=\"color: #993300;\"><em>read_byte_data(i2c_addr,register,force=None)<\/em><\/span><\/strong> &#8211; To read a single byte from a designated register.<br \/>\n<span style=\"color: #993300;\"><strong><em>read_block_data(i2c_addr,register,force=None)<\/em> <\/strong><\/span>&#8211; To read a block of up to 32-bytes from a given register.<br \/>\n<strong><span style=\"color: #993300;\"><em>read_i2c_block_data(i2c_addr,register,length,force=None)<\/em> <\/span><\/strong>&#8211; To read a block of byte data from a given register.<br \/>\n<strong><span style=\"color: #993300;\"><em>read_word_data(i2c_addr,register,force=None)<\/em><\/span><\/strong> &#8211; To read a single word (2 bytes) from a given register.<\/p>\n<p class=\"ai-optimize-42\">Similarly, data can be written to I2C slaves in bytes, words or block of bytes. In some I2C slave devices, data must be written to specific registers. The following methods are available in SMBus2 library for writing serial I2C data from slave devices:<br \/>\n<strong><span style=\"color: #993300;\"><em>write_byte(i2c_addr,value,force=None)<\/em><\/span><\/strong> &#8211; To write a single byte to a device.<br \/>\n<strong><span style=\"color: #993300;\"><em>write_byte_data(i2c_addr,register,value,force=None)<\/em> <\/span><\/strong>&#8211; To write a byte to a given register.<br \/>\n<strong><span style=\"color: #993300;\"><em>write_block_data(i2c_addr,register,data,force=None)<\/em><\/span><\/strong> &#8211; To write a block of byte data to a given register.<br \/>\n<strong><span style=\"color: #993300;\"><em>write_i2c_block_data(i2c_addr,register,data,force=None)<\/em><\/span><\/strong> &#8211; To write a block of byte data to a given register.<br \/>\n<strong><span style=\"color: #993300;\"><em>write_word_data(i2c_addr,register,value,force=None)<\/em><\/span><\/strong> &#8211; To write a byte to a given register.<br \/>\n<strong><span style=\"color: #993300;\"><em>write_quick(i2c_addr,force=None)<\/em> <\/span><\/strong>&#8211; To perform quick transaction. Throws IOError if unsuccessful.<\/p>\n<p class=\"ai-optimize-43\">The following methods are available for managing SMBus processes and to combine I2C bus read\/write operations:<br \/>\n<strong><span style=\"color: #993300;\"><em>process_call(i2c_addr,register,value,force=None)<\/em><\/span><\/strong> &#8211; To execute a SMBus Process Call, sending a 16-bit value and receiving a 16-bit response<br \/>\n<strong><span style=\"color: #993300;\"><em>block_process_call(i2c_addr,register,data,force=None)<\/em><\/span><\/strong> &#8211; To send a variable-size data block and receiving another variable-size response.<br \/>\n<strong><span style=\"color: #993300;\"><em>i2c_rdwr(*i2c_msgs)<\/em><\/span><\/strong> &#8211; To combine a series of i2c read and write operations in a single transaction.<\/p>\n<p class=\"ai-optimize-44\">In the next tutorial, we will discuss interfacing the ADXL345 accelerometer sensor with Raspberry Pi via I2C port.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous tutorial, we discussed the basics of the I2C protocol. In most of the embedded devices, either UART otherwise I2C is used for console messages. In this tutorial, we will discuss serial communication in Raspberry Pi using the I2C protocol. I2C in Raspberry Pi For serial communication over the I2C protocol, the Broadcom&hellip;<\/p>\n","protected":false},"author":387,"featured_media":61881,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[1853,3993],"tags":[1724],"class_list":{"2":"type-post","10":"entry","11":"has-post-thumbnail"},"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.2 (Yoast SEO v25.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>RPi Python Programming 25: I2C Bus\/Interface in Raspberry Pi<\/title>\n<meta name=\"description\" content=\"In this tutorial, we will discuss serial communication in Raspberry Pi using the I2C protocol for console messages.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"RPi Python Programming 25 - Synchronous serial communication in Raspberry Pi using I2C protocol\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we will discuss serial communication in Raspberry Pi using the I2C protocol for console messages.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Engineers Garage\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/engineersgarage\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"740\" \/>\n\t<meta property=\"og:image:height\" content=\"416\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nikhil Agnihotri\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EngineersGarage\" \/>\n<meta name=\"twitter:site\" content=\"@EngineersGarage\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nikhil Agnihotri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/\"},\"author\":{\"name\":\"Nikhil Agnihotri\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6\"},\"headline\":\"RPi Python Programming 25 &#8211; Synchronous serial communication in Raspberry Pi using I2C protocol\",\"datePublished\":\"2025-06-10T19:25:33+00:00\",\"dateModified\":\"2025-06-11T16:18:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/\"},\"wordCount\":1534,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg\",\"keywords\":[\"raspberrypi\"],\"articleSection\":[\"Featured Contributions\",\"Raspberry pi\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/\",\"url\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/\",\"name\":\"RPi Python Programming 25: I2C Bus\/Interface in Raspberry Pi\",\"isPartOf\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg\",\"datePublished\":\"2025-06-10T19:25:33+00:00\",\"dateModified\":\"2025-06-11T16:18:48+00:00\",\"description\":\"In this tutorial, we will discuss serial communication in Raspberry Pi using the I2C protocol for console messages.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#primaryimage\",\"url\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg\",\"contentUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg\",\"width\":740,\"height\":416},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.engineersgarage.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"RPi Python Programming 25 &#8211; Synchronous serial communication in Raspberry Pi using I2C protocol\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.engineersgarage.com\/#website\",\"url\":\"https:\/\/www.engineersgarage.com\/\",\"name\":\"Engineers Garage\",\"description\":\"Electronic Projects, Electrical Engineering Resources, Makers Articles and Product News\",\"publisher\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.engineersgarage.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\",\"name\":\"Engineer's Garage - WTWH Media\",\"url\":\"https:\/\/www.engineersgarage.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png\",\"contentUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png\",\"width\":372,\"height\":52,\"caption\":\"Engineer's Garage - WTWH Media\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/engineersgarage\",\"https:\/\/x.com\/EngineersGarage\",\"https:\/\/www.youtube.com\/channel\/UC0VITh11JSYk-UW7toLebUw\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6\",\"name\":\"Nikhil Agnihotri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g\",\"caption\":\"Nikhil Agnihotri\"},\"url\":\"https:\/\/www.engineersgarage.com\/author\/nikhil-agnihotri\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"RPi Python Programming 25: I2C Bus\/Interface in Raspberry Pi","description":"In this tutorial, we will discuss serial communication in Raspberry Pi using the I2C protocol for console messages.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/","og_locale":"en_US","og_type":"article","og_title":"RPi Python Programming 25 - Synchronous serial communication in Raspberry Pi using I2C protocol","og_description":"In this tutorial, we will discuss serial communication in Raspberry Pi using the I2C protocol for console messages.","og_url":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/","og_site_name":"Engineers Garage","article_publisher":"https:\/\/www.facebook.com\/engineersgarage","og_image":[{"width":740,"height":416,"url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg","type":"image\/jpeg"}],"author":"Nikhil Agnihotri","twitter_card":"summary_large_image","twitter_creator":"@EngineersGarage","twitter_site":"@EngineersGarage","twitter_misc":{"Written by":"Nikhil Agnihotri","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#article","isPartOf":{"@id":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/"},"author":{"name":"Nikhil Agnihotri","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6"},"headline":"RPi Python Programming 25 &#8211; Synchronous serial communication in Raspberry Pi using I2C protocol","datePublished":"2025-06-10T19:25:33+00:00","dateModified":"2025-06-11T16:18:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/"},"wordCount":1534,"commentCount":0,"publisher":{"@id":"https:\/\/www.engineersgarage.com\/#organization"},"image":{"@id":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg","keywords":["raspberrypi"],"articleSection":["Featured Contributions","Raspberry pi"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/","url":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/","name":"RPi Python Programming 25: I2C Bus\/Interface in Raspberry Pi","isPartOf":{"@id":"https:\/\/www.engineersgarage.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#primaryimage"},"image":{"@id":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg","datePublished":"2025-06-10T19:25:33+00:00","dateModified":"2025-06-11T16:18:48+00:00","description":"In this tutorial, we will discuss serial communication in Raspberry Pi using the I2C protocol for console messages.","breadcrumb":{"@id":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#primaryimage","url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg","contentUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg","width":740,"height":416},{"@type":"BreadcrumbList","@id":"https:\/\/www.engineersgarage.com\/articles-raspberry-pi-i2c-bus-pins-smbus-smbus2-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.engineersgarage.com\/"},{"@type":"ListItem","position":2,"name":"RPi Python Programming 25 &#8211; Synchronous serial communication in Raspberry Pi using I2C protocol"}]},{"@type":"WebSite","@id":"https:\/\/www.engineersgarage.com\/#website","url":"https:\/\/www.engineersgarage.com\/","name":"Engineers Garage","description":"Electronic Projects, Electrical Engineering Resources, Makers Articles and Product News","publisher":{"@id":"https:\/\/www.engineersgarage.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.engineersgarage.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.engineersgarage.com\/#organization","name":"Engineer's Garage - WTWH Media","url":"https:\/\/www.engineersgarage.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png","contentUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png","width":372,"height":52,"caption":"Engineer's Garage - WTWH Media"},"image":{"@id":"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/engineersgarage","https:\/\/x.com\/EngineersGarage","https:\/\/www.youtube.com\/channel\/UC0VITh11JSYk-UW7toLebUw"]},{"@type":"Person","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/3c71105e3b40a1fd12c79c15602914b6","name":"Nikhil Agnihotri","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d26b31563fa36169891c8c7d312e9b33de8a0e3da1340ec14ef2de84d5c43497?s=96&r=g","caption":"Nikhil Agnihotri"},"url":"https:\/\/www.engineersgarage.com\/author\/nikhil-agnihotri\/"}]}},"featured_image_src":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg","featured_image_src_square":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2020\/08\/Raspberry-Pi-4-25-featured.jpg","author_info":{"display_name":"Nikhil Agnihotri","author_link":"https:\/\/www.engineersgarage.com\/author\/nikhil-agnihotri\/"},"_links":{"self":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts\/61866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/users\/387"}],"replies":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/comments?post=61866"}],"version-history":[{"count":0,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts\/61866\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/media\/61881"}],"wp:attachment":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/media?parent=61866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/categories?post=61866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/tags?post=61866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}