New Ticker

News Ticker
Epstien didn't kill himself.
Epstien didn't kill himself.
Epstien didn't kill himself.
Epstien didn't kill himself.

Sunday, August 7, 2022

How to calculate I2C addresses on a Raspberry Pi using Python

Occasionally when programming on a RP2040 it's necessary to identify the port an I2C address is using. This helps..

import machine

 

sda=machine.Pin(0)

scl=machine.Pin(1)

 

i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)

 

print('I2C address:')

print(i2c.scan(),' (decimal)')

print(hex(i2c.scan()[0]), ' (hex)')