Skip to content

an integer is required #7

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

Closed
watakandai opened this issue Jan 8, 2020 · 14 comments
Closed

an integer is required #7

watakandai opened this issue Jan 8, 2020 · 14 comments

Comments

@watakandai
Copy link

Although I followed the tutorial and ran the example script
I got an error.
I also activated I2C, but don't know why it is not working.

import time
import board
import busio
import adafruit_vcnl4040

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_vcnl4040.VCNL4040(i2c)

while True:
    print("Proximity:", sensor.proximity)
    print("Light: %d lux"% sensor.lux)
    time.sleep(1.0)
Traceback (most recent call last):
  File "07_read_vcnl4040.py", line 8, in <module>
    sensor = adafruit_vcnl4040.VCNL4040(i2c)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_vcnl4040.py", line 308, in __init__
    if self._device_id != 0x186:
  File "/usr/local/lib/python3.7/dist-packages/adafruit_register/i2c_struct.py", line 87, in __get__
    out_end=1, in_start=1, stop=False)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 136, in write_then_readinto
    in_start=in_start, in_end=in_end)
  File "/usr/local/lib/python3.7/dist-packages/busio.py", line 91, in writeto_then_readfrom
    in_start=in_start, in_end=in_end, stop=stop)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 61, in writeto_then_readfrom
    readin = self._i2c_bus.read_i2c_block_data(address, buffer_out[out_start:out_end], in_end-in_start)
  File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_PureIO/smbus.py", line 207, in read_i2c_block_data
    reg = c_uint8(cmd)
TypeError: an integer is required (got type bytearray)

@ladyada
Copy link
Member

ladyada commented Jan 9, 2020

what board are you using?

@watakandai
Copy link
Author

A Raspberry Pi 3

@caternuson
Copy link

@caternuson
Copy link

@watakandai Can you recreate the issue if you start with a fresh OS install? Or a venv if you're familiar with that. See thread linked above. This seems like something potentially related to some kind of software conflict.

@watakandai
Copy link
Author

I think the issue is related to the one you posted.
Similar to the thread, the OS is the latest Raspbian and I also added few libraries.
I could try to indtsll a fresh OS today and see what would happen.

Or maybe it is due to the updates on smbus or busio, but not sure.

@watakandai
Copy link
Author

With a freshly installed OS (Raspbian 4.19.75-v7), it worked perfectly.
Even if I installed pyqt5 sudo apt-get install python3-pyqt5, it worked.

@caternuson
Copy link

OK, let's close this for now. The person in the other issue was also able to get around this with a fresh OS install. If you run into this again and can narrow it down to a specific package install or something, please let us know and we can reopen the issue.

Thanks for testing with a fresh OS image.

@ladyada
Copy link
Member

ladyada commented Jan 10, 2020

@caternuson i think this is from old libraries, maybe we should tell em to do a full pip update:

https://stackoverflow.com/questions/2720014/how-to-upgrade-all-python-packages-with-pip

@caternuson
Copy link

@watakandai Do you still have your non-working setup? If so, can you try the above and see if that gets it back to working?

@watakandai
Copy link
Author

Hi @caternuson, I still do. I will try the above method and let you know what will happen.

@ladyada
Copy link
Member

ladyada commented Jan 10, 2020

please do it as a user and also after sudo bash as root

@watakandai
Copy link
Author

watakandai commented Jan 10, 2020

It worked using

pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U

Thank you so much @caternuson and @ladyada

@Grandpa-G
Copy link

I did this also on my Raspberry and will post the results in the other issue. It worked.

@lemonkey
Copy link

A similar error happened with my si7021 temperature/humidity board (on a fresh Raspbian Buster install, after running sudo pip3 install adafruit-circuitpython-si7021).

It turned out that somehow I had an older version of Adafruit-PureIO installed (0.2.3) instead of the latest as of this comment (1.0.4).

After a pip install -U Adafruit-PureIO, I was able to run the sample code without errors:

import time
import board
import busio
import adafruit_si7021

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_si7021.SI7021(i2c)

while True:
    print("\nTemperature: %0.1f C" % sensor.temperature)
    print("Humidity: %0.1f %%" % sensor.relative_humidity)
    time.sleep(2)

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

5 participants