ESP8266 and MicroPython

Page 37

ESP8266 and Micropython - Coding cool stuff

APPENDIX B • THE I2C BUS B.1 Overview

The I2C (or I2C) bus is commonly used in microcontroller based projects. In this Appendix we shall be looking at the use of this bus with a simple example using MicroPython. The aim is to make the reader familiar with the MicroPython I2C bus library functions and to show how they can be used in a real project. B.2 THE I2C BUS

I2C bus is one of the most commonly used microcontroller communication protocols for communicating with external devices such as sensors and actuators. The I2C bus is a single master, multiple slave bus and it can operate at up 50 5MHz. The bus consists of two opendrain wires, pulled-up with resistors: SDA: data line SCL: clock line Figure B.1 shows the structure of an I2C bus with one master and three slaves.

Figure B.1 I2C bus with one master and three slaves Communication is initiated by the master which sends a START bit. This alerts all the slaves that some data is coming on the bus and all the slaves listen on the bus. After the start bit, 7 bits of unique slave address is sent. Each slave device on the bus has its own address and this ensures that only the addressed slave communicates on the bus at any time to avoid any collisions. The last sent bit is read/write bit such that if this bit is 0, it means that the master wishes to write to the bus (e.g. to a register of a slave), if this bit is a 1, it means that the master wishes to read from the bus (e.g. from the register of a slave). The data is sent on the bus with the MSB bit first. B.3 MicroPython I2C BUS COMMANDS

The I2C functions for the ESP8266 MicroPython language are implemented in software and the following functions are commonly used:

â—? 182

ESP8266 UK 170601.indd 182

09-06-17 12:05


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.