rreignier
Members-
Posts
22 -
Joined
-
Last visited
-
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Hi @srinath Your Python script works for me. The numpy transformation seems useless but does not prevent to write the image on my side. But with your script, I only get black pictures. Adding the property settings and the loop (the first images are always black, I don't know why) I have managed to get good images: import cv2 capture = cv2.VideoCapture(1, cv2.CAP_V4L2) capture.set(cv2.CAP_PROP_FRAME_WIDTH, 1280.0) capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 720.0) capture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('Y', 'U', '1', '2')) for i in range(10): retur, frame = capture.read() isWritten = cv2.imwrite('image-2.jpg', frame) if isWritten: print('Image is successfully saved as file.') And don't forget to set the media command before starting the script: media-ctl --device /dev/media1 --set-v4l2 '"ov5640 1-003c":0[fmt:YUYV8_2X8/1280x720]' -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
I do not have the board with me right now, I will try later. But yesterday, after a system update to Linux 5.10, the camera switched to /dev/video1 and I had to use this fork of fswebcam with these commands: $ media-ctl --device /dev/media1 --set-v4l2 '"ov5640 1-003c":0[fmt:YUYV8_2X8/1280x720]' $ ./fswebcam --displayfps 1 -S 30 -d /dev/video0 -r 1280x720 -p YUV420P - > /tmp/cam_1280x720_yuv420p.jpg And for reference, to use it with OpenCV I had to specify the size and format: #include <iostream> #include <opencv2/opencv.hpp> int main(int, char**) { VideoCapture cap; cap.open(1, CAP_V4L2); if (!cap.isOpened()) { cerr << "ERROR! Unable to open camera\n"; return -1; } cap.set(cv::CAP_PROP_FRAME_WIDTH, 1280); cap.set(cv::CAP_PROP_FRAME_HEIGHT, 720); cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('Y','U','1','2')); Mat frame; // The first images might be black so take several before for(size_t i = 0; i < 10; ++i) { cap >> frame; } if (frame.empty()) { cerr << "ERROR! blank frame grabbed\n"; return -1; } imwrite("/tmp/opencv_frame.jpg", frame); return 0; } -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Hi @rdeyes On an Orange Pi One (which might be close to your Orange Pi PC), I have managed to get the OV5640 thanks to the amazing work of the contributors of this thread. Last time I have tried was on Armbian 20.08.17 with Linux 5.8.16. The device tree overlay I use is this one (you may have to change some pins) : /dts-v1/; /plugin/; / { compatible = "allwinner,sun8i-h3"; }; &ccu { assigned-clocks = <&ccu 107>; assigned-clock-parents = <&osc24M>; assigned-clock-rates = <24000000>; }; &pio { csi_mclk_pin: csi-mclk-pin { pins = "PE1"; function = "csi"; }; }; &i2c2_pins { bias-pull-up; }; &i2c2 { status = "okay"; ov5640: camera@3c { compatible = "ovti,ov5640"; reg = <0x3c>; pinctrl-names = "default"; pinctrl-0 = <&csi_mclk_pin>; clocks = <&ccu 107>; clock-names = "xclk"; AVDD-supply = <®_vcc_af_csi>; DOVDD-supply = <®_vdd_1v5_csi>; DVDD-supply = <®_vcc_csi>; reset-gpios = <&pio 4 14 1>; /* CSI-RST-R: PE14 */ powerdown-gpios = <&pio 4 15 0>; /* CSI-STBY-R: PE15 */ port { ov5640_ep: endpoint { remote-endpoint = <&csi_ep>; bus-width = <8>; data-shift = <2>; /* lines 9:2 are used */ hsync-active = <1>; /* Active high */ vsync-active = <0>; /* Active low */ data-active = <1>; /* Active high */ pclk-sample = <1>; /* Rising */ }; }; }; }; &csi { status = "okay"; port { #address-cells = <1>; #size-cells = <0>; csi_ep: endpoint { remote-endpoint = <&ov5640_ep>; bus-width = <8>; hsync-active = <1>; /* Active high */ vsync-active = <0>; /* Active low */ data-active = <1>; /* Active high */ pclk-sample = <1>; /* Rising */ }; }; }; To enable it, I use this command: sudo armbian-add-overlay csi-ov5640.dts And then, to take a picture: media-ctl --device /dev/media1 --set-v4l2 '"ov5640 1-003c":0[fmt:JPEG_1X8/1920x1080]' fswebcam -d /dev/video0 -r 1920x1080 -D 0 --jpeg 100 /tmp/test.jpg I hope this can help you and others. -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Hi @gsumner No, I did not have time to try it out on my board yet But I am very glad that you have managed to get this camera working on mainline and shared your progress. I am following with great attention! Thanks! Did you have a look at the blog post about PinePhone camera which happen to be an OV5640 too? https://blog.brixit.nl/camera-on-the-pinephone/ -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Wow! That's very nice! Thanks a lot for the help. I did not have the time to try it yet. But for sure, a dts overlay should be pushed to armbian! -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Yes, I have been trying on an Orange Pi One. I also have Orange Pi PC Plus and Orange Pi Lite2 (H6) on which I could also try. But since I have received the ov5640 board, I did not try the driver, only the i2cdetect. -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Interesting, indeed. But avafinger does not appear to be a contributor of the mainline driver : here. I think he has worked the old one, for kernel 3.4. Interestingly, the PineTab device tree uses an ov5640 here. On a A64 that uses the same sun6i_csi driver that the H3. So I am sure there is still hope. What device tree are you using? Are you using the device tree overlay I have posted above? -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Thnak you @jgauthier very interesting report. I did not take the time yet to test a 3.4 kernel to make sure my module is actually working or not. -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Before talking to /dev/video0, I would like to see some activity on the i2c side, so just with i2cdetect. But it did not work for me. If you have another camera module, maybe you could try. -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Actually. I cannot see the device on the i2c bus, so I don't think that the driver is to blame here. Or maybe i2c driver, but I don't think so. Which kernel are you using to make use of the OV5640 so I could check that my camera works? -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
@olivluca Sorry, but I don't feel like writing a full kernel driver After some discussions with the vendor and some delivery delays because of the COVID-19, I have now received the OV5640 camera sensor board! But with the overlay previously posted, there is not anything better I have then crafted this simple overlay to enable the `i2c2` with pull-up: /dts-v1/; /plugin/; / { compatible = "allwinner,sun8i-h3"; fragment@0 { target = <&pio>; __overlay__ { i2c2_pins: i2c2-pins { pins = "PE12", "PE13"; function = "i2c2"; bias-pull-up; }; }; }; fragment@1 { target = <&i2c2>; __overlay__ { pinctrl-0 = <&i2c2_pins>; status = "okay"; }; }; }; I applied it with: $ sudo armbian-add-overlay i2c2-with-pullup.dts $ sudo reboot Once rebooted, I have checked the i2c device number. I am looking for address `1c2b400` according to the dtsi: $ ls -l /sys/class/i2c-adapter/ total 0 lrwxrwxrwx 1 root root 0 Jan 1 1970 i2c-0 -> ../../devices/platform/soc/1ee0000.hdmi/i2c-0 lrwxrwxrwx 1 root root 0 Jan 1 1970 i2c-1 -> ../../devices/platform/soc/1c2b400.i2c/i2c-1 So let's check the detected devices on bus `1`: $ sudo i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- Nothing! While with the GC2035 connected, I have: $ sudo i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f 70: -- -- -- -- -- -- -- -- Does someone who owns an H3 based Orange Pi and the OV5640 camera module could try the above commands to see if the module is detected? Thank you. -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Actually, I have just discovered that the camera module I have received is a GC2035 and not a OV5640 as ordered. So I won't be able to continue my investigations. -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
By replacing `CLK_CSI_MCLK`, `GPIO_ACTIVE_LOW` and `GPIO_ACTIVE_HIGH` constants by respectively `107`, `1` and `0` the device-tree overlay can be compiled. But during the boot, I got: [ 10.837084] i2c i2c-1: mv64xxx: I2C bus locked, block: 1, time_left: 0 [ 10.843681] ov5640 1-003c: ov5640_read_reg: error: reg=300a [ 10.849315] ov5640 1-003c: ov5640_check_chip_id: failed to read chip identifier So I have disabled my overlay and load the sun8i-h3-i2c2 overlay instead. With the command: i2cdetect -y 1 I got a lot of these errors in the serial console: [ 40.470126] i2c i2c-2: mv64xxx: I2C bus locked, block: 1, time_left: 0 [ 42.518174] i2c i2c-2: mv64xxx: I2C bus locked, block: 1, time_left: 0 [ 44.566261] i2c i2c-2: mv64xxx: I2C bus locked, block: 1, time_left: 0 [ 46.614294] i2c i2c-2: mv64xxx: I2C bus locked, block: 1, time_left: 0 From this post I assumed that I could have a pull-up issue so I have created this overlay to enable the internal pull-up on the i2c-2 pins: /dts-v1/; /plugin/; / { compatible = "allwinner,sun8i-h3"; fragment@0 { target = <&pio>; __overlay__ { i2c2_pins: i2c2-pins { pins = "PE12", "PE13"; function = "i2c2"; bias-pull-up; }; }; }; fragment@1 { target = <&i2c2>; __overlay__ { pinctrl-0 = <&i2c2_pins>; status = "okay"; }; }; }; But now, I do not see the camera at the address 0x3c and if I let the i2cdetect continue, I get the "I2C bus locked" errors. With the GC235 camera module, I detect something at the address 0x4c. So, even if my OV5640 camera module is brand new, I am not sure if it is working. Does anyone have an idea on how to test if my module is still functional? -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Ok, thanks a lot, I will try it tonight. -
OV5640 device tree overlay for OrangePi One H3
rreignier replied to rreignier's topic in Orange Pi One
Ok, I see. Thank you @martinayotte From sun8i-h3-ccu.h I see: #define CLK_CSI_MCLK 107 So what syntax should I use to set it to 107? clocks = <&ccu 107>; or clocks = <107>; or clocks = "107"; Thank you