Skip to content

Instantly share code, notes, and snippets.

@BjoernSchilberg
Last active October 18, 2021 15:35
Show Gist options
  • Save BjoernSchilberg/470406378c05fd0376feb44b87fe1a0d to your computer and use it in GitHub Desktop.
Save BjoernSchilberg/470406378c05fd0376feb44b87fe1a0d to your computer and use it in GitHub Desktop.
MCP2221

MCP2221

Infos

I2C Setup

Source:

wget http://ww1.microchip.com/downloads/en/DeviceDoc/mcp2221_0_1.tar.gz
tar zxvf mcp2221_0_1.tar.gz
cd mcp2221_0_1
sudo make modules
sudo make install
sudo ./driver_load.sh

Test

apt install i2c-tools
sudo i2cdetect -l
i2c-3   i2c             i2c-mcp2221 at bus 001 device 006       I2C adapter
sudo i2cdetect -y 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

CircuitPython Libraries on any Computer with MCP2221

Setup

python3 -m venv venv
source venv/bin/activate
pip3 install bpython

Source: https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221/linux

pip3 install hidapi
pip3 install adafruit-blinka
export BLINKA_MCP2221=1

Test setup

import board
dir(board)

SparkFun CCS811/BME280 Combo Board

Source:

sudo i2cdetect -l
i2c-3 i2c        AMDGPU DM i2c hw bus 0           I2C adapter
i2c-10 i2c        i2c-mcp2221 at bus 001 device 014 I2C adapter
i2c-1 i2c        Synopsys DesignWare I2C adapter  I2C adapter
i2c-8 i2c        AMDGPU DM aux hw bus 2           I2C adapter
i2c-6 i2c        AMDGPU DM i2c hw bus 3           I2C adapter
i2c-4 i2c        AMDGPU DM i2c hw bus 1           I2C adapter
i2c-2 i2c        Synopsys DesignWare I2C adapter  I2C adapter
i2c-0 i2c        Synopsys DesignWare I2C adapter  I2C adapter
i2c-9 i2c        AMDGPU DM aux hw bus 3           I2C adapter
i2c-7 i2c        AMDGPU DM aux hw bus 0           I2C adapter
i2c-5 i2c        AMDGPU DM i2c hw bus 2           I2C adapter
sudo i2cdetect -y 10

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- 5b -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- 77 

BME280

pip3 install adafruit-circuitpython-bme280
export BLINKA_MCP2221=1
import board
from adafruit_bme280 import basic as adafruit_bme280
i2c = board.I2C()  # uses board.SCL and board.SDA
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
print("\nTemperature: %0.1f C" % bme280.temperature)
print("Humidity: %0.1f %%" % bme280.humidity)
print("Pressure: %0.1f hPa" % bme280.pressure)

CCS811

pip3 install adafruit-circuitpython-ccs811
export BLINKA_MCP2221=1
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
import adafruit_ccs811

i2c = board.I2C()  # uses board.SCL and board.SDA
ccs811 = adafruit_ccs811.CCS811(i2c, address=0x5B)

# Wait for the sensor to be ready
while not ccs811.data_ready:
    pass

while True:
    print("CO2: {} PPM, TVOC: {} PPB".format(ccs811.eco2, ccs811.tvoc))
    time.sleep(0.5)

Grove - I2C ADC

Grove - I2C ADC is a 12-bit precision ADC module based on ADC121C021.

Links

I2C adress is 0x50.

i2cdetect -y 10
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --    
# set mode 
i2cset -y 10 0x50 0x02 0x20
watch -n1 i2cget -y 10 0x50 0

Tips & Tricks

Use bpython as lightweight Python interpreter:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment