ArduCAM / RaspberryPi

This is Arducam camera demos used on Raspberry Pi paltform
BSD 3-Clause "New" or "Revised" License
162 stars 97 forks source link

Failed to set I2C address #50

Open ismyaki opened 3 years ago

ismyaki commented 3 years ago

Why i runing sample but has error Failed to set I2C address 😱

import cv2  # sudo apt-get install python-opencv
import numpy as py
import os
import time
from ctypes import *

# load arducam shared object file
arducam_vcm = CDLL('libs/libarducam_vcm.so')
try:
    import picamera
    from picamera.array import PiRGBArray
except:
    sys.exit(0)

def focusing(val):
    arducam_vcm.vcm_write(val)
    # print("focus value: {}".format(val))

def sobel(img):
    img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    img_sobel = cv2.Sobel(img_gray, cv2.CV_16U, 1, 1)
    return cv2.mean(img_sobel)[0]

def laplacian(img):
    img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    img_sobel = cv2.Laplacian(img_gray, cv2.CV_16U)
    return cv2.mean(img_sobel)[0]

def calculation(camera):
    rawCapture = PiRGBArray(camera)
    camera.capture(rawCapture, format="bgr", use_video_port=True)
    image = rawCapture.array
    rawCapture.truncate(0)
    return laplacian(image)

if __name__ == "__main__":
    # vcm init
    arducam_vcm.vcm_init()
    # open camera
    camera = picamera.PiCamera()

    # open camera preview
    camera.start_preview()
    # set camera resolution to 640x480(Small resolution for faster speeds.)
    camera.resolution = (640, 480)
    time.sleep(0.1)
    camera.shutter_speed = 30000
    print("Start focusing")

    max_index = 10
    max_value = 0.0
    last_value = 0.0
    dec_count = 0
    focal_distance = 10

    while True:
        # Adjust focus
        focusing(focal_distance)
        # Take image and calculate image clarity
        val = calculation(camera)
        # Find the maximum image clarity
        if val > max_value:
            max_index = focal_distance
            max_value = val

        # If the image clarity starts to decrease
        if val < last_value:
            dec_count += 1
        else:
            dec_count = 0
        # Image clarity is reduced by six consecutive frames
        if dec_count > 6:
            break
        last_value = val

        # Increase the focal distance
        focal_distance += 15
        if focal_distance > 1000:
            break

    # Adjust focus to the best
    focusing(max_index)
    time.sleep(1)
    # set camera resolution to 2592x1944
    camera.resolution = (1920, 1080)
    # save image to file.
    camera.capture("test.jpg")
    print("max index = %d,max value = %lf" % (max_index, max_value))
    # while True:
    #   time.sleep(1)

    camera.stop_preview()
    camera.close()

output

pi@raspberrypi:~/camera_test $ sudo python3 test.py
Start focusing
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
Failed to set I2C address
max index = 55,max value = 3.607292
pi@raspberrypi:~/camera_test $
asnewman commented 3 years ago

I'm experiencing the same thing. Any solutions?

asnewman commented 3 years ago

Looks like the most recent commit broke the code. I checked out 4d271ade72e1d9b0af889cd6351dafd460b10d00 and it worked.

ArduCAM commented 3 years ago

@asnewman For the latest system version, the i2c adapter is i2c10 instead of i2c0. We have updated our lib to compatible with the latest system. Please run uname -a command to check your kernel verson and run **ls /dev/i2c*** command to check if it exist i2c10 adapter.

asnewman commented 3 years ago

@ArduCAM Thanks for the tip. When I ran the commands I get:

Linux raspberrypi 4.19.118-v7+ #1311 SMP Mon Apr 27 14:21:24 BST 2020 armv7l GNU/Linux

and

/dev/i2c-0  /dev/i2c-1

Do I need to run some sort of update command?

npaibrooklyn commented 3 years ago

Any update on this? I am facing the same issue

bigdognj commented 2 years ago

Just received my pi autofocus camera, installed everything as directed and am getting the same error as above when running the first Python demo. There are no I2C drivers in my /dev/ directory. What to do?

pi@octopi:~ $ cd dev -bash: cd: dev: No such file or directory pi@octopi:~ $ cd /dev pi@octopi:/dev $ ls i2c ls: cannot access 'i2c': No such file or directory pi@octopi:/dev $ ls autofs mapper raw tty24 tty52 vcs5 block media0 rfkill tty25 tty53 vcs6 btrfs-control media1 rpivid-h264mem tty26 tty54 vcsa bus mem rpivid-hevcmem tty27 tty55 vcsa1 cachefiles mmcblk0 rpivid-intcmem tty28 tty56 vcsa2 char mmcblk0p1 rpivid-vp9mem tty29 tty57 vcsa3 console mmcblk0p2 serial tty3 tty58 vcsa4 cuse mqueue serial1 tty30 tty59 vcsa5 disk net shm tty31 tty6 vcsa6 dma_heap null snd tty32 tty60 vcsm-cma dri port stderr tty33 tty61 vcsu fd ppp stdin tty34 tty62 vcsu1 full ptmx stdout tty35 tty63 vcsu2 fuse pts tty tty36 tty7 vcsu3 gpiochip0 ram0 tty0 tty37 tty8 vcsu4 gpiochip1 ram1 tty1 tty38 tty9 vcsu5 gpiomem ram10 tty10 tty39 ttyAMA0 vcsu6 hwrng ram11 tty11 tty4 ttyprintk vga_arbiter initctl ram12 tty12 tty40 ttyUSB0 vhci input ram13 tty13 tty41 uhid video0 kmsg ram14 tty14 tty42 uinput video10 log ram15 tty15 tty43 urandom video11 loop0 ram2 tty16 tty44 v4l video12 loop1 ram3 tty17 tty45 vchiq video13 loop2 ram4 tty18 tty46 vcio video14 loop3 ram5 tty19 tty47 vc-mem video15 loop4 ram6 tty2 tty48 vcs video16 loop5 ram7 tty20 tty49 vcs1 video18 loop6 ram8 tty21 tty5 vcs2 watchdog loop7 ram9 tty22 tty50 vcs3 watchdog0 loop-control random tty23 tty51 vcs4 zero pi@octopi:/dev $ cd / pi@octopi:/ $ cd RaspberryPi -bash: cd: RaspberryPi: No such file or directory pi@octopi:/ $ cd /RaspberryPi -bash: cd: /RaspberryPi: No such file or directory pi@octopi:/ $ ls bin common.sh etc lib media opt root sbin sys usr boot dev home lost+found mnt proc run srv tmp var pi@octopi:/ $ sudo reboot [sudo] password for pi: login as: pi pi@192.168.1.180's password: Linux octopi 5.10.63-v7l+ #1459 SMP Wed Oct 6 16:41:57 BST 2021 armv7l

The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Sun Nov 14 17:50:20 2021 from 192.168.1.188


Access OctoPrint from a web browser on your network by navigating to any of:

http://octopi.local
http://192.168.1.180

https is also available, with a self-signed certificate.

OctoPrint version : 1.7.2 OctoPi version : 0.18.0

pi@octopi:~ $ cd /RaspberryPi -bash: cd: /RaspberryPi: No such file or directory pi@octopi:~ $ cd RaspberryPi pi@octopi:~/RaspberryPi $ cd Motorized_Focus_Camera pi@octopi:~/RaspberryPi/Motorized_Focus_Camera $ git clone https://github.com/ArduCAM/RaspberryPi.git Cloning into 'RaspberryPi'... remote: Enumerating objects: 1142, done. remote: Counting objects: 100% (28/28), done. remote: Compressing objects: 100% (18/18), done. remote: Total 1142 (delta 12), reused 21 (delta 10), pack-reused 1114 Receiving objects: 100% (1142/1142), 23.55 MiB | 5.11 MiB/s, done. Resolving deltas: 100% (638/638), done. pi@octopi:~/RaspberryPi/Motorized_Focus_Camera $ sudo reboot [sudo] password for pi: login as: pi pi@192.168.1.180's password: Linux octopi 5.10.63-v7l+ #1459 SMP Wed Oct 6 16:41:57 BST 2021 armv7l

The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Sun Nov 14 17:53:57 2021 from 192.168.1.188


Access OctoPrint from a web browser on your network by navigating to any of:

http://octopi.local
http://192.168.1.180

https is also available, with a self-signed certificate.

OctoPrint version : 1.7.2 OctoPi version : 0.18.0

pi@octopi:~ $ cd RaspberryPi pi@octopi:~/RaspberryPi $ cd Motorized_Focus_Camera pi@octopi:~/RaspberryPi/Motorized_Focus_Camera $ cd python pi@octopi:~/RaspberryPi/Motorized_Focus_Camera/python $ sudo python Motorized_Focus_Camera_Preview.py [sudo] password for pi: Please press up and down to adjust focus. mmal: mmal_vc_component_enable: failed to enable component: ENOSPC mmal: camera component couldn't be enabled mmal: main: Failed to create camera component mmal: Failed to run camera app. Please check for firmware updates

vidya0398 commented 2 years ago

I am also facing the same issue. Im getting error failed to set i2c address when I try to run Motorized_Focus_Camera_Preview.py and try to adjust the focus.

import os import time import sys import _thread from ctypes import * keyboard = CDLL('./lib/libarducam_keyboard.so') arducam_vcm =CDLL('./lib/libarducam_vcm.so') UP = 1 DOWN = 2 SAVE = 115 focus_val = 512; step = 10 def run_camera(name): os.system("raspistill -t 0") if name == "main": _thread.start_new_thread(run_camera, ("run_camera",)) arducam_vcm.vcm_init() print("Please press up and down to adjust focus.") while True: keyVal = keyboard.processKeyEvent() time.sleep(0.01) if keyVal == UP: print("UP") focus_val = focus_val+step if focus_val > 1023: focus_val = 1023 print(focus_val) arducam_vcm.vcm_write(focus_val) if keyVal == DOWN: print("DOWN") focus_val = focus_val-step if focus_val < 0: focus_val = 0 print(focus_val) arducam_vcm.vcm_write(focus_val)

vidya0398 commented 2 years ago

WhatsApp Image 2022-04-25 at 5 02 06 PM (1)