TypeError: object with buffer protocol required - trying to write to SMBus - micropython

I'm using a raspberry pi pico to read data from a SHT3x sensor using the I2C protocol. I'm quite new to (micro)python so I used this example. This example is for a regular Raspberry Pi since I didn't find any for the Pico. However, the SMBus library is not found. I assume it is just not available for micropython (I have version 1.17).
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'smbus'
There seems to be only one micropython wrapper for SMBus (as far as I found), this one. When I use this wrapper, the problem I have and don't understand is the following error:
Traceback (most recent call last):
File "<stdin>", line 8, in <module>
File "usmbus.py", line 50, in write_i2c_block_data
TypeError: object with buffer protocol required
Refering to this line function: writeto_mem(addr, register, data) (documentation).
The data that I pass in is as follows
addr = 0x44
register = 0x2C
data = [0x06]
I understood that it has something to do with framebuffer in micropython not being supported, but I don't understand how to fix it. Can someone help me out? Or suggest me other solutions?

If the sensor supports I2C, you should be able to use the builtin MicroPython I2C support.
I also found a library for the SHT3x, by searching on the MicroPython forum.

Related

nrf24l01 Module not Working with Raspberry Pi Pico W

I can use the nrf24l01 wireless module just fine with a Raspberry Pi Pico, but when I try to compile the same code on the Raspberry Pi Pico W, it fails to recognize the device. I am using this library, and I get this error:
Traceback (most recent call last):
File "<stdin>", line 31, in <module>
File "nrf24l01.py", line 78, in __init__
OSError: nRF24L01+ Hardware not responding
The boards are supposed to have the same footprint, so what is the difference here? How can I use these modules with the Pico W?

How to get Metadata in python ONVIF?

Currently, I'm looking for metadata access functions using the in Python-onvif.
I want to get the coordinates of "BoundingBox" inside the red box.
How to i access data?
https://www.onvif.org/ver20/analytics/wsdl/analytics.wsdl#op.GetSupportedMetadata
This function was used, but an AttributeError occurred.
from onvif import ONVIFCamera
cam = ONVIFCamera('192.168.100.133', 80, 'ID', 'P/W')
cam.create_analytics_service()
meta = cam.analytics.GetSupportedMetadata()
print(meta)
result:
Traceback (most recent call last):
File "C:\Users\User\anaconda3\envs\py310\lib\site-packages\zeep\proxy.py", line 97, in __getitem__
return self._operations[key]
KeyError: 'GetSupportedMetadata'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\User\AppData\Roaming\JetBrains\PyCharmCE2021.2\scratches\meta_data.py", line 24, in <module>
meta = cam.analytics.GetSupportedMetadata()
File "C:\Users\User\anaconda3\envs\py310\lib\site-packages\onvif\client.py", line 167, in __getattr__
return self.service_wrapper(getattr(self.ws_client, name))
File "C:\Users\User\anaconda3\envs\py310\lib\site-packages\zeep\proxy.py", line 88, in __getattr__
return self[key]
File "C:\Users\User\anaconda3\envs\py310\lib\site-packages\zeep\proxy.py", line 99, in __getitem__
raise AttributeError("Service has no operation %r" % key)
AttributeError: Service has no operation 'GetSupportedMetadata'
I need your help.
I'm not exactly using the same onvif package you are, and I'm not so sure myself how to achieve this, but this is what I've got so far:
Both the package python-onvif, that you are using, and the Valkka inspired implementation I'm using, rely on a folder WSDL which contains pretty old versions of Onvif operations. It seems we both were using version 2.2 while the current version is 20.12.
So what I did was to download the newer versions at their repository and replace the contents of the WSDL folder with the content of the new WSDL folder.
I also had to replace how the paths were built since now there is some folder hierarchy inplace to reach the WSDL files, but after that I was able to call GetSupportedMetadata successfully.

Micropython: [Errno 19] ENODEV but i2c.scan() returns proper address

I am currently using an SRF-10 sensor connected to an esp32. It's being powered by 5V and I am using a level converter to bring down the voltage to 3.3V to be able to use it on the esp32. Both the SCL and SDA have a 1.8K pull up resistor as recommended on the datasheet.
I have written the following script to try to get a read from the sensor. I am not entirely sure if it is correct but soon as it reaches line 16 I get an error saying [Errno 19] ENODEV. Eveything I could find suggests that the i2c connection isn't working properly but when I run i2c.scan() it returns the sensor address so I am guessing connections arenĀ“t the problem.
My script is as follows:
from machine import I2C, Pin
import time
byte = bytearray(4)
#Distance units
unit_in = 0x50
unit_cm = 0x51
unit_us = 0x52
i2c = I2C(scl=Pin(21), sda=Pin(22))
address = i2c.scan()[0]
print(address)
#Sensor range
range_mm = 11008 // 43 - 1
i2c.writeto_mem(range_mm, address, bytearray(2)) #line 16
#Begin reading
i2c.writeto_mem(unit_cm, address, bytearray(0))
#Reading after measurement
data = i2c.readfrom_mem(4, address, 0)
print(data)
This is the output:
112
Traceback (most recent call last):
File "main.py", line 22, in <module>
OSError: [Errno 19] ENODEV
MicroPython v1.12 on 2019-12-20; ESP32 module with ESP32
Type "help()" for more information.
What could I be doing wrong?
The proper use of i2c.writeto_mem requires the following order of arguments:
writeto_mem(addr, memaddr, buf, *, addrsize=8)
Therefore, try to use in line 16:
i2c.writeto_mem(address, range_mm, bytearray(2)) #line 16
Reference: class I2C

Google Coral USB Accelerator on Raspbian Lite Buster and Raspberry PI 4

I am following the getting started guide for the Google Coral USB Accelerator and even though I was able to trick the install.sh file to install for RPI4
https://twitter.com/hansamann/status/1154021771554766849
I cannot run the example with the image classification. When I run the sample, I get this:
python3 classify_image.py --model ~/Downloads/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite --label ~/Downloads/inat_bird_labels.txt --image ~/Downloads/parrot.jpg
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/edgetpu/swig/edgetpu_cpp_wrapper.py", line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_edgetpu_cpp_wrapper', [dirname(__file__)])
File "/usr/lib/python3.7/imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_edgetpu_cpp_wrapper'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "classify_image.py", line 19, in <module>
from edgetpu.classification.engine import ClassificationEngine
File "/usr/local/lib/python3.7/dist-packages/edgetpu/classification/engine.py", line 17, in <module>
from edgetpu.basic.basic_engine import BasicEngine
File "/usr/local/lib/python3.7/dist-packages/edgetpu/basic/basic_engine.py", line 15, in <module>
from edgetpu.swig.edgetpu_cpp_wrapper import BasicEngine
File "/usr/local/lib/python3.7/dist-packages/edgetpu/swig/edgetpu_cpp_wrapper.py", line 28, in <module>
_edgetpu_cpp_wrapper = swig_import_helper()
File "/usr/local/lib/python3.7/dist-packages/edgetpu/swig/edgetpu_cpp_wrapper.py", line 20, in swig_import_helper
import _edgetpu_cpp_wrapper
ModuleNotFoundError: No module named '_edgetpu_cpp_wrapper'
Any idea whay I could try?
I had the same problem but with an older Rpi 3. This is the solution I used. I don't think it's a make or break to complete the project:
$ sudo cp _edgetpu_cpp_wrapper.cpython-35m-arm-linux-gnueabihf.so _edgetpu_cpp_wrapper.cpython-37m-arm-linux-gnueabihf.so
Can you go through : https://github.com/google-coral/edgetpu-platforms ?
This repository holds auxiliary platform-related material related to Google Coral Edge TPU. Here you can find precompiled images, shared libraries and patches for using the USB Edge TPU accelerator on additional platforms to the main supported ones.
For convenience Google has uploaded prebuilt images for Raspberry Pi Zero, Pi 3 and Pi 4. Simply write the image to an sd card and boot up your Pi. The images contain several examples that should work out of the box.

builtins.ImportError: cannot import name 'Empty'

While working the examples in a book on Parallel Programming in Python, I encountered the following error in code that uses the multiprocessing queue:
File "C:\pyDev\multiproc\queue-test.py", line 4, in <module>
queue = multiprocessing.Queue()
File "C:\Anaconda3\Lib\multiprocessing\context.py", line 100, in Queue
from .queues import Queue
File "C:\Anaconda3\Lib\multiprocessing\queues.py", line 20, in <module>
from queue import Empty, Full
builtins.ImportError: cannot import name 'Empty'
After some experimentation, I determined that all it takes to generate this error is the following code (which is the entirety of the queue-test.py file mentioned in the error message above).
import multiprocessing
if __name__ == "__main__":
queue = multiprocessing.Queue()
I'm running Python 3.5.1 with Anaconda 4.1.0 on a machine with Windows 7. I have ported the code above and the example from the book to another machine with Python 2.7.11 with Anaconda 2.5.0, with Windows 10 and it works fine on that machine.
Thinking that perhaps there was a corrupt file or other issue with my Python installation, I tried reinstalling Anaconda and it did not help. I performed a Google search and did not find this particular error. Other stackoverflow postings such as the one found here: ImportError: Cannot import name X don't appear to be relevent because this involves part of the Python standard library and not code and classes I wrote myself.
I encountered almost the same error in my code and finally figure out where went wrong. Hope it will help you somehow.
I named my python script as "queue.py", and then I run it, I got error info. below just like yours:
Traceback (most recent call last):
File "F:/02_Coding/01_Projects/PyHomeWork/Day23_Process/queue.py", line 19, in <module>
queue = multiprocessing.Queue()
File "E:\02_CodingSoftware\02_Installed\Anaconda3\lib\multiprocessing\context.py", line 101, in Queue
from .queues import Queue
File "E:\02_CodingSoftware\02_Installed\Anaconda3\lib\multiprocessing\queues.py", line 20, in <module>
from queue import Empty, Full
ImportError: cannot import name 'Empty'
I use the below method to create a Queue:
if __name__ =="__main__":
queue = multiprocessing.Queue()
Finally, I notice that I should not named the file in a name of "queue.py", it seems it will cause a misleading to python when it interpreter the script. And after I rename the script, the error is gone. What a stupid mistake, LoL.
So my suggestion is maybe you can check whether under your folder is there a script named as "queue.py" or any custom module would conflict with that in libraries.
Hope you can solve the issue. Best