I2C device found at 0x27 Traceback (most recent call last): File "<stdin>", line 16, in <module> OSError: [Errno 5] EIO - i2c

import machine, utime
from machine import I2C
i2c = machine.I2C(0, scl=machine.Pin(1), sda=machine.Pin(0), freq=400000)
devices = i2c.scan()
if len(devices) == 0:
print("No I2C device found")
elif len(devices) > 1:
print("Multiple I2C devices found -")
for d in devices:
print(" 0x{:02X}".format(d))
else:
print("I2C device found at 0x{:02X}".format(devices[0]))
device = devices[0]
i2c.writeto(device, b'x3')
i2c.writeto(device, 2, b'x80')
>>> %Run -c $EDITOR_CONTENT
I2C device found at 0x27
Traceback (most recent call last):
File "<stdin>", line 16, in <module>
OSError: [Errno 5] EIO

Related

Error code in a SPI camera connected to raspberry pi - micropython code

I've got the following code:
import machine
import time as utime
from OV5642_reg import *
OV5642=1
BMP =0
JPEG=1
RAW =2
OV5642_CHIPID_HIGH=0x300a
OV5642_CHIPID_LOW=0x300b
class ArducamClass(object):
def __init__(self,Type):
self.CameraMode=JPEG
self.CameraType=Type
self.SPI_CS = machine.Pin(5, mode=machine.Pin.OUT, value=1)
self.I2cAddress=0x3c
self.spi = machine.SPI(0, baudrate=4000000,polarity=0,phase=0,bits=8, sck=machine.Pin(2), mosi=machine.Pin(3), miso=machine.Pin(4))
self.i2c = machine.I2C(0, scl=machine.Pin(9), sda=machine.Pin(8), freq=1000000)
print(self.i2c.scan())
self.Spi_write(0x07,0x80)
utime.sleep(0.1)
self.Spi_write(0x07,0x00)
utime.sleep(0.1)
def Camera_Detection(self):
while True:
if self.CameraType==OV5642:
self.I2cAddress=0x3c
self.wrSensorReg16_8(0xff,0x01)
id_h=self.rdSensorReg16_8(OV5642_CHIPID_HIGH)
id_l=self.rdSensorReg16_8(OV5642_CHIPID_LOW)
if((id_h==0x56)and(id_l==0x42)):
print('CameraType is OV5642')
break
else:
print('Can\'t find OV5642 module')
utime.sleep(1)
def Set_Camera_mode(self,mode):
self.CameraMode=mode
def wrSensorReg16_8(self,addr,val):
buffer=bytearray(3)
buffer[0]=(addr>>8)&0xff
buffer[1]=addr&0xff
buffer[2]=val
self.iic_write(buffer)
def rdSensorReg16_8(self,addr):
buffer=bytearray(2)
rt=bytearray(1)
buffer[0]=(addr>>8)&0xff
buffer[1]=addr&0xff
self.iic_write(buffer)
self.iic_readinto(rt)
return rt[0]
def iic_write(self, buf, *, start=0, end=None):
if end is None:
end = len(buf)
self.i2c.writeto(self.I2cAddress, buf[start:end])
def iic_readinto(self, buf, *, start=0, end=None):
if end is None:
end = len(buf)
print(buf[start:end])
print(self.I2cAddress)
self.i2c.readfrom_into(self.I2cAddress, buf[start:end])
def Spi_write(self,address,value):
maskbits = 0x80
buffer=bytearray(2)
buffer[0]=address | maskbits
buffer[1]=value
self.SPI_CS.value(0)
self.spi_write(buffer)
self.SPI_CS.value(1)
def spi_write(self, buf, *, start=0, end=None):
if end is None:
end = len(buf)
self.spi.write(buf[start:end])
mycam = ArducamClass(OV5642)
mycam.Camera_Detection()
Which gives me the following error:
Traceback (most recent call last):
File "<stdin>", line 89, in <module>
File "<stdin>", line 33, in Camera_Detection
File "<stdin>", line 58, in rdSensorReg16_8
File "<stdin>", line 71, in iic_readinto
OSError: [Errno 5] EIO
I'm sure that the camera is connected correctly (I've tested it using the standard CircuitPython code provided with it and it works) so I think that I'm misinterpreting how the readfrom_into call works... any hint?
I tried to understand what get's written in the readfrom_into part but can't get anything.. The starting code (based on circuitpython) is here: https://github.com/ArduCAM/PICO_SPI_CAM/blob/master/Python/Arducam.py

pycairo error: “no current point defined” when trying to use TeeSurface

I'm trying to use a cairo.TeeSurface (pycairo version '1.21.0') to redirect input to multiple surfaces, but I cannot make it work, here is my code:
>>> import cairo
>>> s1 = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500,500)
>>> s2 = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500,500)
>>> s3 = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500,500)
>>> s = cairo.TeeSurface(s1)
>>> s.add(s2)
>>> s.add(s3)
>>> c = cairo.Context(s)
After above iniziatilation if I try to draw a line I get an error:
>>> c.rel_line_to(100,100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cairo.Error: no current point defined
I tried to set explicitly a point but I get the same error:
>>> c.move_to(10,10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cairo.Error: no current point defined
For sure I must have misunderstood something, any clue would be appreciated.

ModuleNotFoundError: No module named '_posixsubprocess' when creating virtual enviroment

i'm trying to set a virtual enviroment with:
$ python3 -m venv cv2
But when trying it, i'm getting this exception:
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/usr/lib/python3.6/venv/__init__.py", line 10, in <module>
import subprocess
File "/usr/lib/python3.6/subprocess.py", line 136, in <module>
import _posixsubprocess
ModuleNotFoundError: No module named '_posixsubprocess'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 12, in <module>
import subprocess, tempfile, os.path, re, pwd, grp, os, time
File "/usr/lib/python3.6/subprocess.py", line 136, in <module>
import _posixsubprocess
ModuleNotFoundError: No module named '_posixsubprocess'
Original exception was:
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/usr/lib/python3.6/venv/__init__.py", line 10, in <module>
import subprocess
File "/usr/lib/python3.6/subprocess.py", line 136, in <module>
import _posixsubprocess
ModuleNotFoundError: No module named '_posixsubprocess'
I've trying reinstalling subprocess32, but i haven't solved anything. I'm using Python 3.6.3 Anaconda on Ubuntu 18.04.1 LTS.
Any suggestions?

Micropython: Non-Blocking SSLSocket

I was just trying SSL-Sockets in Micropython and discovered that I can not set the connection to non-blocking as the setblocking() function is not implemented, yet.
>>> import ussl
>>> import usocket
>>> s = usocket.socket()
>>> adr = usocket.getaddrinfo('myserverwithssl.com', 443)[0][-1]
>>> s.connect(adr)
>>> s_ssl = ussl.wrap_socket(adr)
>>> s_ssl.setblocking(False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NotImplementedError:
Looking forward to the implementation. However, is there another way to achieve nonblocking SSL-Sockets in Micropython?

Run Theano on Python 3.5

Previously I have working installation of bleeding edge Theano version on Anaconda Python 2.7 x 64 on Windows 7 x64.
I tried to upgrade to bleeding edge Theano version on Python 3.5 x64 on Windows x64 and encountered error during test example compilation:
Problem occurred during compilation with the command line below:
C:\TDM-GCC-64\bin\g++.exe -shared -g -march=ivybridge -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mno-movbe -maes -mno-sha -mpclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mavx -mno-avx2 -msse4.2 -msse4.1 -mno-lzcnt -mno-rtm -mno-hle -mrdrnd -mf16c -mfsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mxsave -mxsaveopt -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 -mno-clflushopt -mno-xsavec -mno-xsaves -mno-avx512dq -mno-avx512bw -mno-avx512vl -mno-avx512ifma -mno-avx512vbmi -mno-clwb -mno-pcommit --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -mtune=ivybridge -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -DMS_WIN64 -IC:\Anaconda3\lib\site-packages\numpy\core\include -IC:\Anaconda3\include -IC:\Anaconda3\lib\site-packages\theano\gof -o C:\Users\s.nechuiviter\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.1-64\lazylinker_ext\lazylinker_ext.pyd C:\Users\s.nechuiviter\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-3.5.1-64\lazylinker_ext\mod.cpp -LC:\Anaconda3\libs -LC:\Anaconda3 -lpython35
===============================
C:\Anaconda3\libs/python35.lib: error adding symbols: File in wrong format
collect2.exe: error: ld returned 1 exit status
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py", line 75, in <module>
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py", line 92, in <module>
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/GIT_MIRROR/SRP_DLA/Python_DLA/tests/theano_test.py", line 4, in <module>
import theano.tensor as T
File "C:\Anaconda3\lib\site-packages\theano\__init__.py", line 64, in <module>
from theano.compile import (
File "C:\Anaconda3\lib\site-packages\theano\compile\__init__.py", line 10, in <module>
from theano.compile.function_module import *
File "C:\Anaconda3\lib\site-packages\theano\compile\function_module.py", line 22, in <module>
import theano.compile.mode
File "C:\Anaconda3\lib\site-packages\theano\compile\mode.py", line 12, in <module>
import theano.gof.vm
File "C:\Anaconda3\lib\site-packages\theano\gof\vm.py", line 646, in <module>
from . import lazylinker_c
File "C:\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py", line 127, in <module>
preargs=args)
File "C:\Anaconda3\lib\site-packages\theano\gof\cmodule.py", line 2204, in compile_str
(status, compile_stderr.replace('\n', '. ')))
.
How to fix this?
It seems libpython conflicts with Python 3.5?