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

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

Related

Raspberry Pico W network test fails

I just put my hands on RP Pico W to try it out but I hit the issue with the very first wifi test.
Tutorials say to do this:
import network
import socket
from time import sleep
from picozero import pico_temp_sensor, pico_led
import machine
so my pico lib folder looks like this when I imported all required packages:
However when try to run wifi test like this:
def connect():
#Connect to WLAN
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while wlan.isconnected() == False:
print('Waiting for connection...')
sleep(1)
ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')
try:
connect()
except KeyboardInterrupt:
machine.reset()
it fails with following error:
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/network.py", line 8, in <module>
File "/lib/socket.py", line 42, in <module>
AttributeError: 'module' object has no attribute 'socket'
>>>
This is whole code, I skipped only ssid and password.
I cannot figure out what exactly is wrong here. I do not have any other files named the same as socket or so.
I took the example from RP foundation pages:
https://projects.raspberrypi.org/en/projects/get-started-pico-w/2

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?

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

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.

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.

ncclient.operations.rpc.RPCError: 'YANG framework' detected the 'fatal' condition 'Operation not supported on this datastore'

I am configuring the hostname of my cisco XR using ncclient. But I am receiving bellow an RPCError-
Traceback (most recent call last):
File "obj4.py", line 13, in <module>
edit_result = device.edit_config(target='running',config=host_name, default_operation='merge').data_xml
File "/usr/local/lib/python3.5/dist-packages/ncclient/manager.py", line 162, in wrapper
return self.execute(op_cls, *args, **kwds)
File "/usr/local/lib/python3.5/dist-packages/ncclient/manager.py", line 232, in execute
raise_mode=self._raise_mode).request(*args, **kwds)
File "/usr/local/lib/python3.5/dist-packages/ncclient/operations/edit.py", line 67, in request
return self._request(node)
File "/usr/local/lib/python3.5/dist-packages/ncclient/operations/rpc.py", line 337, in _request
raise self._reply.error
ncclient.operations.rpc.RPCError: 'YANG framework' detected the 'fatal' condition 'Operation not supported on this datastore'
My code is-
#!/usr/bin/env python3
from ncclient import manager
with manager.connect(host='198.51.100.1',port=830,username='netman',password='netman',hostkey_verify=False,device_params={'name':'iosxr'},allow_agent=True,look_for_keys=False) as device:
host_name = '''<config>
<cli-config-data>
<cmd>hostname Lab9XR</cmd>
</cli-config-data>
</config>'''
edit_result = device.edit_config(target='running',config=host_name, default_operation='merge').data_xml
print (edit_result)
Configuration on my cisco XR device is-
RP/0/0/CPU0:ios#sh run
Mon Apr 8 02:53:28.496 UTC
Building configuration...
!! IOS XR Configuration 6.1.3
!! Last configuration change at Mon Apr 8 02:08:58 2019 by netman
!
hostname ios
interface MgmtEth0/0/CPU0/0
shutdown
!
interface GigabitEthernet0/0/0/0
ipv4 address 198.51.100.1 255.255.255.0
!
interface GigabitEthernet0/0/0/1
shutdown
!
xml agent
iteration off
!
netconf agent tty
!
netconf-yang agent
ssh
!
ssh server v2
ssh server netconf vrf default
ssh server logging
ssh timeout 120
end
Please help resolve the issue. How to enable cli module on this device's datastore?
It could be due to Cisco XR does not support "urn:ietf:params:netconf:capability:writable-running:1.0". You need to use candidate datastore in that case
Please try candidate store like:
====current code--------
edit_result = device.edit_config(target='running',config=host_name, default_operation='merge').data_xml
print (edit_result)
----newcode------
edit_result = device.edit_config(target='candidate',config=host_name, default_operation='merge').data_xml
print (edit_result)