Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

KeyError: 'BLINKA_MCP2221'
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

KeyError: 'BLINKA_MCP2221'

by darkmoon3d on Mon May 11, 2020 2:45 pm

Am trying to setup MCP2221 plugged into usb data port on Raspberry Pi Zero. Have everything setup as in https://learn.adafruit.com/circuitpytho ... 1?view=all until I try following:

import os
os.environ["BLINKA_MCP2221"]

getting following error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.7/os.py", line 678, in __getitem__
raise KeyError(key) from None
KeyError: 'BLINKA_MCP2221'

darkmoon3d
 
Posts: 44
Joined: Wed Jul 22, 2015 3:51 am

Re: KeyError: 'BLINKA_MCP2221'

by darkmoon3d on Mon May 11, 2020 5:38 pm

Managed to get no error by using 'export BLINKA_MCP2221=1' before the Python REPL but am still unable to read i2c sensor. Have MPU6050 plugged in via i2c to MCP2221 and 'sudo i2cdetect -y 1' is not showing 0x68 address or anything.

darkmoon3d
 
Posts: 44
Joined: Wed Jul 22, 2015 3:51 am

Re: KeyError: 'BLINKA_MCP2221'

by adafruit_support_carter on Mon May 11, 2020 7:54 pm

Yes, you need to set the environment variable first:
https://learn.adafruit.com/circuitpytho ... iable-5-21

If the sensor is not showing up with i2c-detect, then it may be connection related. Please post a photo of your setup showing how everything is wired together.

adafruit_support_carter
 
Posts: 17149
Joined: Tue Nov 29, 2016 2:45 pm

Re: KeyError: 'BLINKA_MCP2221'

by darkmoon3d on Mon May 11, 2020 9:30 pm

Testing with MPU6050 and NXP9DOF and not reading either on i2c

20200511_211708.jpg
20200511_211708.jpg (640.12 KiB) Viewed 64 times



20200511_211538.jpg
20200511_211538.jpg (607.24 KiB) Viewed 64 times

darkmoon3d
 
Posts: 44
Joined: Wed Jul 22, 2015 3:51 am

Re: KeyError: 'BLINKA_MCP2221'

by adafruit_support_carter on Tue May 12, 2020 11:36 am

Just curious - why are you using an MCP2221 for your setup? The Pi has I2C available on the 2x20 GPIO header. As well as numerous GPIO pins.

i2cdetect will not see the devices through the MCP2221, since it is scanning the I2C bus on the Pi's GPIO headers, to which you have nothing attached.

If you want to do the equivalent of i2cdetect with the MCP2221, then you'll want to launch Python and use the scan() method.
Code: Select all | TOGGLE FULL SIZE
import board
i2c = board.I2C()
i2c.try_lock()
i2c.scan()


The soldering on some of your pins looks a little cold and under soldered. You may need to try reflowing these:
solder.jpg
solder.jpg (67.24 KiB) Viewed 60 times

https://learn.adafruit.com/adafruit-gui ... n-problems

adafruit_support_carter
 
Posts: 17149
Joined: Tue Nov 29, 2016 2:45 pm

Re: KeyError: 'BLINKA_MCP2221'

by darkmoon3d on Tue May 12, 2020 2:20 pm

This project doesn't have available gpio pins so am trying to access via usb data port. Running code gave me '[104]' from i2c.scan() while address for mpu6050 should be 0x68. How to go about linking this to stream data from 6050?

Code: Select all | TOGGLE FULL SIZE
# https://learn.adafruit.com/mpu6050-6-dof-accelerometer-and-gyro?view=all
# https://github.com/adafruit/Adafruit_CircuitPython_MPU6050
# https://forums.adafruit.com/viewtopic.php?f=58&t=165320&p=811503#p811503

import time
import board
import busio
import adafruit_mpu6050

#import board
i2c = board.I2C()
#i2c.try_lock()
#i2c.scan()

#i2c = busio.I2C(board.SCL, board.SDA)
mpu = adafruit_mpu6050.MPU6050(i2c)

while True:
    print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (mpu.acceleration))
    print("Gyro X:%.2f, Y: %.2f, Z: %.2f degrees/s" % (mpu.gyro))
    print("Temperature: %.2f C" % mpu.temperature)
    print("")
    time.sleep(1

)

darkmoon3d
 
Posts: 44
Joined: Wed Jul 22, 2015 3:51 am

Re: KeyError: 'BLINKA_MCP2221'

by adafruit_support_carter on Tue May 12, 2020 2:26 pm

'[104]' from i2c.scan() while address for mpu6050 should be 0x68.

That looks fine. 0x68 hex is 104.

If you set the environment variable, then that program should work. Without the environment variable set, it will try and use the I2C bus on the GPIO headers.

adafruit_support_carter
 
Posts: 17149
Joined: Tue Nov 29, 2016 2:45 pm

Re: KeyError: 'BLINKA_MCP2221'

by darkmoon3d on Tue May 12, 2020 5:17 pm

Thanks! Working now.

Is there a way to smooth out the data or calibrate IMU before use using Rasp Pi? Seems like an adafruit port exist but nothing for Rasp Pi. Am looking for best IMU for stable gyro values exploring either mpu6050 or fxos8700/fxas21002c . Was originally considering using bno055 but wanted one at lower price.




Code: Select all | TOGGLE FULL SIZE
Acceleration (m/s^2): (0.239, 0.510, -9.138)
Acceleration (Gforce): (0.024, 0.052, -0.932)
Magnetometer (uTesla): (-4.300, -58.400, 1.800)
Gyroscope (radians/s): (0.562,  -0.312,  0.109)
Gyroscope (DEGREES): (32.229,  -17.905,  6.267)


Acceleration (m/s^2): (0.239, 0.531, -9.141)
Acceleration (Gforce): (0.024, 0.054, -0.932)
Magnetometer (uTesla): (-5.100, -58.200, 1.900)
Gyroscope (radians/s): (0.680,  0.047,  0.547)
Gyroscope (DEGREES): (38.943,  2.686,  31.334)


Acceleration (m/s^2): (0.261, 0.517, -9.141)
Acceleration (Gforce): (0.027, 0.053, -0.932)
Magnetometer (uTesla): (-5.100, -59.200, 2.000)
Gyroscope (radians/s): (0.578,  -0.094,  0.102)
Gyroscope (DEGREES): (33.124,  -5.371,  5.819)


Acceleration (m/s^2): (0.246, 0.510, -9.145)
Acceleration (Gforce): (0.025, 0.052, -0.933)
Magnetometer (uTesla): (-5.200, -58.200, 2.000)
Gyroscope (radians/s): (0.633,  -0.133,  0.367)
Gyroscope (DEGREES): (36.257,  -7.610,  21.038)

darkmoon3d
 
Posts: 44
Joined: Wed Jul 22, 2015 3:51 am

Re: KeyError: 'BLINKA_MCP2221'

by adafruit_support_carter on Tue May 12, 2020 5:19 pm

I think what was said in that thread you linked applies here as well.

adafruit_support_carter
 
Posts: 17149
Joined: Tue Nov 29, 2016 2:45 pm

Re: KeyError: 'BLINKA_MCP2221'

by darkmoon3d on Tue May 12, 2020 6:21 pm

Wanting to set a gpio pin on mcp2221 to blink with cpu activity. Should adding following to config.txt file work?

Code: Select all | TOGGLE FULL SIZE
dtoverlay=pi3-act-led,activelow="on",gpio=digitalio.DigitalInOut(board.G0)

darkmoon3d
 
Posts: 44
Joined: Wed Jul 22, 2015 3:51 am

Re: KeyError: 'BLINKA_MCP2221'

by adafruit_support_carter on Tue May 12, 2020 6:30 pm

Very unlikely. You can really only use the MCP2221 from within Python. The device tree overlay most likely only works with GPIO pins on the main SOC.

adafruit_support_carter
 
Posts: 17149
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.