Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Unable to enable VEML7700 device #19

Open
IceRayer-OG opened this issue Feb 2, 2022 · 17 comments
Open

RuntimeError: Unable to enable VEML7700 device #19

IceRayer-OG opened this issue Feb 2, 2022 · 17 comments

Comments

@IceRayer-OG
Copy link

IceRayer-OG commented Feb 2, 2022

Running Micropython on Pi Pico and attempting to use the VEML7700 connected to a TCA9548a on Channel 0. Platform_Detector and Blinka src files are installed. Other adafruit libraries are working fine. As you can see in the output below my VEML6070 is communicating on channel 1 without issues.

import sys
import time
import board
import busio
import adafruit_tca9548a
import adafruit_veml7700
import adafruit_veml6070

# Setting Sampling Frequency
sample_half_sec = time.ticks_ms()
sample_sec = time.ticks_ms()

i2c = busio.I2C(board.GP5, board.GP4, frequency=400000)
tca = adafruit_tca9548a.TCA9548A(i2c)

for channel in range(8):
    if tca[channel].try_lock():
        print("Channel {}:".format(channel), end="")
        addresses = tca[channel].scan()
        print([hex(address) for address in addresses if address != 0x70])
        tca[channel].unlock()

# UV SENSOR
uv = adafruit_veml6070.VEML6070(tca[1])
# Alternative constructors with parameters
# uv = adafruit_veml6070.VEML6070(tca[1], 'VEML6070_1_T')
# uv = adafruit_veml6070.VEML6070(tca[1], 'VEML6070_HALF_T', True)

def UV_DATA():
    uv_raw = uv.uv_raw
    risk_level = uv.get_index(uv_raw)
    print("Reading: {0} | Risk Level: {1}".format(uv_raw, risk_level))

# LUX SENSOR
luxsensor = adafruit_veml7700.VEML7700(tca[0])
print("Light Integration Time:", luxsensor.light_integration_time)
print("Ambient Light:", luxsensor.lux)

def LUX_DATA():
    print("Ambient Light:", luxsensor.lux)

while True:
    if (time.ticks_ms() - sample_half_sec > 500):
        sample_half_sec = time.ticks_ms()


    if (time.ticks_ms() - sample_sec > 1000):
        UV_DATA()
        LUX_DATA()
        sample_sec = time.ticks_ms()

REPL OUTPUT:
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040
Type "help()" for more information.

%Run -c $EDITOR_CONTENT
Channel 0:['0x10']
Channel 1:['0x38', '0x39']
Channel 2:['0x77']
Channel 3:[]
Channel 4:['0x61']
Channel 5:[]
Channel 6:[]
Channel 7:[]
Reading: 0 | Risk Level: LOW
Traceback (most recent call last):
File "", line 35, in
File "/lib/adafruit_veml7700.py", line 197, in init
RuntimeError: Unable to enable VEML7700 device

I've flashed the same Pico with CircuitPython and the sensor works properly with the same library.

@ladyada
Copy link
Member

ladyada commented Feb 3, 2022

does it work without the TCA, on other channels, or with micropython without blinka
also please post pics of your setup

@IceRayer-OG
Copy link
Author

Thanks for the response. I made no HW config changes between loading the Pico with Circuitpython and Micropython. I'll wire up a new harness to test the sensor on a different channel and without the TCA. I'll run the test later this evening after removing the blinka folder from lib.

Below are the photos you requested. In the top photo you see I have the VEML6070 and VEML7700 on a separate PCB connected via a ribbon cable.

IMG_4323
IMG_4324

@IceRayer-OG
Copy link
Author

Results of attempting to remove blinka which ended with AttributeError no attribute 'try_lock'. You can see that the I2C scan shows a response from the TCA board, but the initiating TCA9548A doesn't seem to work without blinka. The requirements.txt for TCA9548A also shows Adafruit-Blinka as a requirement.

REPL output:
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040

Type "help()" for more information.

%Run -c $EDITOR_CONTENT
[112]
Traceback (most recent call last):
File "", line 22, in
File "/lib/adafruit_tca9548a.py", line 52, in try_lock
AttributeError: 'I2C' object has no attribute 'try_lock'

from machine import Pin, I2C, SoftI2C
import sys
import time
import adafruit_tca9548a
import adafruit_veml7700
import adafruit_veml6070

sample_sec = time.ticks_ms()

i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400000)

print(i2c.scan())

tca = adafruit_tca9548a.TCA9548A(i2c)

for channel in range(8):
    if tca[channel].try_lock():
        print("Channel {}:".format(channel), end="")
        addresses = tca[channel].scan()
        print([hex(address) for address in addresses if address != 0x70])
        tca[channel].unlock()

# UV SENSOR
uv = adafruit_veml6070.VEML6070(tca[1])
# Alternative constructors with parameters
# uv = adafruit_veml6070.VEML6070(tca[1], 'VEML6070_1_T')
# uv = adafruit_veml6070.VEML6070(tca[1], 'VEML6070_HALF_T', True)


def UV_DATA():
    uv_raw = uv.uv_raw
    risk_level = uv.get_index(uv_raw)
    print("Reading: {0} | Risk Level: {1}".format(uv_raw, risk_level))

# LUX SENSOR
luxsensor = adafruit_veml7700.VEML7700(tca[0])
print("Light Integration Time:", luxsensor.light_integration_time)
print("Ambient Light:", luxsensor.lux)


def LUX_DATA():
    print("Ambient Light:", luxsensor.lux)


# MEASURE SOME DATA!
while True:

    if (time.ticks_ms() - sample_sec > 10000):
        UV_DATA()
        LUX_DATA()
        sample_sec = time.ticks_ms()

I'll test the a direct connect to the VEML7700 tomorrow afternoon after I can build a wiring harness.

@IceRayer-OG
Copy link
Author

Trying to isolate and run the sensor directly connected to the I2C pins results in the following

REPL Output:

MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040
Type "help()" for more information.

%Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "", line 7, in
File "/lib/adafruit_veml7700.py", line 189, in init
File "/lib/adafruit_bus_device/i2c_device.py", line 50, in init
File "/lib/adafruit_bus_device/i2c_device.py", line 152, in __probe_for_device
AttributeError: 'I2C' object has no attribute 'try_lock'

from machine import Pin, I2C
import time
import adafruit_veml7700

i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400000)
veml = adafruit_veml7700.VEML7700(i2c)

while True:
    print("Ambient light:", veml7700.light)
    time.sleep(1)

@IceRayer-OG
Copy link
Author

IceRayer-OG commented Feb 3, 2022

One more test run with the sensor directly connected to the Pico running Micropython and blinka installed

import busio
import time
import board
import adafruit_veml7700

i2c = busio.I2C(board.GP5, board.GP4, frequency=400000) 
veml7700 = adafruit_veml7700.VEML7700(i2c)

while True:
    print("Ambient light:", veml7700.light)
    time.sleep(0.1)

REPL:

%Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "", line 7, in
File "/lib/adafruit_veml7700.py", line 197, in init
RuntimeError: Unable to enable VEML7700 device

@IceRayer-OG
Copy link
Author

IceRayer-OG commented Feb 3, 2022

Last test complete. Moved the VEML7700 to channel one of the TCA9548A. Pico running Micropython with platformdetect and blinka folders installed.

import sys
import time
import board
import busio
import digitalio
import adafruit_tca9548a
import adafruit_veml7700
import adafruit_veml6070

sample_sec = time.ticks_ms()

i2c = busio.I2C(board.GP5, board.GP4, frequency=400000)
tca = adafruit_tca9548a.TCA9548A(i2c)

for channel in range(8):
    if tca[channel].try_lock():
        print("Channel {}:".format(channel), end="")
        addresses = tca[channel].scan()
        print([hex(address) for address in addresses if address != 0x70])
        tca[channel].unlock()

# UV SENSOR
uv = adafruit_veml6070.VEML6070(tca[0])
# Alternative constructors with parameters
# uv = adafruit_veml6070.VEML6070(tca[1], 'VEML6070_1_T')
# uv = adafruit_veml6070.VEML6070(tca[1], 'VEML6070_HALF_T', True)

def UV_DATA():
    uv_raw = uv.uv_raw
    risk_level = uv.get_index(uv_raw)
    print("Reading: {0} | Risk Level: {1}".format(uv_raw, risk_level))

UV_DATA()

# LUX SENSOR
luxsensor = adafruit_veml7700.VEML7700(tca[1])
print("Light Integration Time:", luxsensor.light_integration_time)
print("Ambient Light:", luxsensor.lux)

def LUX_DATA():
    print("Ambient Light:", luxsensor.lux)

while True:

    if (time.ticks_ms() - sample_sec > 10000):
        UV_DATA()
        LUX_DATA()
        sample_sec = time.ticks_ms()

REPL:
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040
Type "help()" for more information.

%Run -c $EDITOR_CONTENT
Channel 0:['0x38', '0x39']
Channel 1:['0x10']
Channel 2:['0x77']
Channel 3:[]
Channel 4:['0x61']
Channel 5:[]
Channel 6:[]
Channel 7:[]
Reading: 0 | Risk Level: LOW
Traceback (most recent call last):
File "", line 36, in
File "/lib/adafruit_veml7700.py", line 197, in init
RuntimeError: Unable to enable VEML7700 device

@caternuson
Copy link

caternuson commented Feb 3, 2022

Seems odd that this is showing up in REPL output:

Reading: 0 | Risk Level: LOW

The UV_DATA() function is not called before the attempt to init the sensor on line 34.

Does the issue repeat is your try this simpler program?

import board
import adafruit_tca9548a
import adafruit_veml7700

print("VEML770 Test.")

tca = adafruit_tca9548a.TCA9548A(board.I2C())

luxsensor = adafruit_veml7700.VEML7700(tca[1])

print("Light Integration Time:", luxsensor.light_integration_time)
print("Ambient Light:", luxsensor.lux)

@IceRayer-OG
Copy link
Author

Seems odd that this is showing up in REPL output:

Reading: 0 | Risk Level: LOW

The UV_DATA() function is not called before the attempt to init the sensor on line 34.

Does the issue repeat is your try this simpler program?

Definitely understand the confusion. As a test of the VEML6070 I had a call to the function one line before the VEML7700 init line. I've edited the comment to showcase the full code and REPL. Sorry about that.

I'll give this shorter code a run within the hour.

@ladyada
Copy link
Member

ladyada commented Feb 3, 2022

when we say 'micropython without blinka' we mean using a micropython driver for the veml7700. also, remove the veml6070, its totally different.
https://github.com/palouf34/veml7700

@IceRayer-OG
Copy link
Author

Does the issue repeat is your try this simpler program?

That code snippet gave some errors with board not having attribute I2C. Running this code

import board
import busio
import adafruit_tca9548a
import adafruit_veml7700

print("VEML770 Test.")

tca = adafruit_tca9548a.TCA9548A(busio.I2C(board.GP5, board.GP4, frequency=400000))

luxsensor = adafruit_veml7700.VEML7700(tca[1])

print("Light Integration Time:", luxsensor.light_integration_time)
print("Ambient Light:", luxsensor.lux)

Gave this REPL:

%Run -c $EDITOR_CONTENT
VEML770 Test.
Traceback (most recent call last):
File "", line 10, in
File "/lib/adafruit_veml7700.py", line 197, in init
RuntimeError: Unable to enable VEML7700 device

@ladyada
Copy link
Member

ladyada commented Feb 3, 2022

remove the frequency arg

@IceRayer-OG
Copy link
Author

remove the frequency arg

tca = adafruit_tca9548a.TCA9548A(busio.I2C(board.GP5, board.GP4))

REPL:

%Run -c $EDITOR_CONTENT
VEML770 Test.
Traceback (most recent call last):
File "", line 10, in
File "/lib/adafruit_veml7700.py", line 197, in init
RuntimeError: Unable to enable VEML7700 device

@ladyada
Copy link
Member

ladyada commented Feb 3, 2022

ok this is not a high priority and its a very complex setup, so we dont have a recommendation at this time for a fix. you may have to use it without the expander

@caternuson
Copy link

Adding this here FWIW, wanted to sanity check hardware combo. Tested with CircuitPython and works fine.

test code:

import board
import busio
import adafruit_tca9548a
import adafruit_veml7700

print("VEML770 Test.")

i2c = busio.I2C(board.GP5, board.GP4)

tca = adafruit_tca9548a.TCA9548A(i2c)

luxsensor = adafruit_veml7700.VEML7700(tca[1])

print("Light Integration Time:", luxsensor.light_integration_time)
print("Ambient Light:", luxsensor.lux)

result:

Adafruit CircuitPython 7.1.1 on 2022-01-14; Raspberry Pi Pico with rp2040
>>> import veml_test
VEML770 Test.
Light Integration Time: 0
Ambient Light: 266.227
>>> 

@IceRayer-OG
Copy link
Author

Yes. I get the same result when running CircuitPython directly on the Pico. The problem occurs when I move the Pico to MicroPython and use blinka to run adafruit libraries. The only library that has given this error is VEML7700. These libraries are all connected to the same setup and TCA without issue.

TCA uses I2C0 scl=pin5, sda=pin4
0 - VEML6070
1 - VEML7700
2 - SCD30
4 - BMP280

direct on I2C1 scl=Pin15, sda=Pin14
PM25

The reason I've been trying to switch to micropython is to open up threading. I'd like to run my ESP01 communication code on core 2 and use core 1 to collect sensor data.

@IceRayer-OG
Copy link
Author

IceRayer-OG commented Feb 3, 2022

@ladyada - Understand it is a low priority. I also agree that it is a complex setup. I rebuilt the circuit on breadboard to remove and issues with the setup on the board. Using a different Pico, TCA board, and VEML7700.

Micropython Direct Connect

Setup:
IMG_4325

Code:

from machine import Pin, I2C
import veml7700

i2c = I2C(0, scl=Pin(5), sda=Pin(4))

print("VEML TEST.")

veml = veml7700.VEML7700(address=0x10, i2c=i2c, it=100, gain=1/8)

print(veml.read_lux())

REPL:
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040
Type "help()" for more information.

%Run -c $EDITOR_CONTENT
VEML TEST.
261

Micropython, TCA, VEML standard library
Setup:
IMG_4326

Code:

import board
import busio
import adafruit_tca9548a
import veml7700

i2c = busio.I2C(board.GP5, board.GP4)

tca = adafruit_tca9548a.TCA9548A(i2c)

print("VEML TEST.")

veml = veml7700.VEML7700(address=0x10, i2c=tca[0], it=100, gain=1/8)

print(veml.read_lux())

REPL:
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040

Type "help()" for more information.

%Run -c $EDITOR_CONTENT
VEML TEST.
Traceback (most recent call last):
File "", line 12, in
File "/lib/veml7700.py", line 142, in init
File "/lib/veml7700.py", line 148, in init
AttributeError: 'TCA9548A_Channel' object has no attribute 'writeto_mem'

This would make sense as the python library reference the writeto_mem while the TCA uses the writeto() and readfrom_into() functions

Micropython TCA, VEML adafruit libraries
Code:

import board
import busio
import adafruit_tca9548a
import adafruit_veml7700

i2c = busio.I2C(board.GP5, board.GP4)

tca = adafruit_tca9548a.TCA9548A(i2c)

print("VEML TEST.")

veml = adafruit_veml7700.VEML7700(tca[0])

print(veml.light)

REPL:
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040
Type "help()" for more information.

%Run -c $EDITOR_CONTENT
VEML TEST.
Traceback (most recent call last):
File "", line 12, in
File "/lib/adafruit_veml7700.py", line 197, in init
RuntimeError: Unable to enable VEML7700 device

Cpy on Pico TCA and VEML adafruit libraries
Setup:
Same as last picture above

Code:

import board
import busio
import adafruit_tca9548a
import adafruit_veml7700

i2c = busio.I2C(board.GP5, board.GP4)

tca = adafruit_tca9548a.TCA9548A(i2c)

print("VEML TEST.")

veml = adafruit_veml7700.VEML7700(tca[0])

print(veml.light)

REPL:
Adafruit CircuitPython 7.1.1 on 2022-01-14; Raspberry Pi Pico with rp2040

%Run -c $EDITOR_CONTENT
VEML TEST.
3088

@IceRayer-OG
Copy link
Author

IceRayer-OG commented Feb 5, 2022

@ladyada not sure if this is helpful, but I attempted to force the VEMLL7700 to set the light_shutdown = False in the init function and got the following.

Code:

    def __init__(self, i2c_bus, address=0x10):
        self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)
        self.light_shutdown = False   # Line 190
        print(self.light_shutdown)
        for _ in range(3):
            try:
                self.light_shutdown = False  # Enable the ambient light sensor
                break
            except OSError:
                pass
        else:
            raise RuntimeError("Unable to enable VEML7700 device")

REPL:
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040
Type "help()" for more information.

%Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "", line 48, in
File "/lib/adafruit_veml7700.py", line 190, in init
File "/lib/adafruit_register/i2c_bit.py", line 53, in set
File "/lib/adafruit_bus_device/i2c_device.py", line 84, in write
File "/lib/adafruit_tca9548a.py", line 71, in writeto
File "/lib/busio.py", line 157, in writeto
File "/lib/adafruit_blinka/microcontroller/rp2040/i2c.py", line 33, in writeto
OSError: [Errno 5] EIO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants