Skip to content

Latest commit

 

History

History
47 lines (29 loc) · 2.09 KB

010_i2c_helper_tutorials.md

File metadata and controls

47 lines (29 loc) · 2.09 KB

I2C helper

Table of Contents

Prolog

Many devices such as sensors and displays use the I2C (Inter-Integrated Circuit), but this presents a few hurdles for beginners. It starts with the fact that soldering has to be done very often here. Then the addresses must also be found (in the case of bad or missing documentation). Already 2 sources of error that deters so many people from using it.

It is therefore advantageous to create a script that confirms the basic functionality and outputs the necessary addresses.

I2C scanner

Build now an I2C scanner, which will save you time in the future!

# create new subdirectory
$ mkdir -p ~/Projects/ESP/examples/i2c_helper

# create script
$ touch ~/Projects/ESP/examples/i2c_helper/i2c_scanner.py

Source Code for i2c_scanner.py

Now connect the I2C device (pay attention to the correct polarity), copy the I2C scanner script to the ESP microcontroller and start the scan.

# copy file into pyboard as main.py
(venv) $ rshell -p [SERIAL-PORT] cp examples/i2c_helper/i2c_scanner.py /pyboard/i2c_scanner.py

# start repl
(venv) $ rshell -p [SERIAL-PORT] repl

Start with keys Control + d. Make a note of the important values of the output and leave the REPL, press keys Control + x. Don't forget to delete the scanner script on the microcontroller (waste of resources).

SoftI2C

Since MicroPython version 1.14.x a message is displayed, that the usage of I2C is deprecated and SoftI2C should be used. I won't go into the advantages of SoftI2C here, but I would like to mention that the switch is not that difficult and that it will probably be necessary at some point.

In the later tutorials, for example the OLED display (with ssd1306 driver) you will come into contact with SoftI2C.

Home | Previous | Next