Notifications
Clear all

ArduCam and libcamera

132 Posts
6 Users
4 Likes
5,748 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7026
 

@byron Or just use the --datetime option.

Screenshot 2023 02 20 at 06.18.15

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 

@zander  - yes I saw that (all all those other nice settings to adjust the camera parameters), but I'm not yet familiar with the picamera2 api to grab the necessary.  And can one adjust the format or is it just MMDD etc.

I've only skimmed over docs. If you do get into python for your camera then do let us know how to incorporate this --datetime into the demo program.   You may well be in advance of my efforts as I will have to wait a bit before I devote any real time to this.  

Its enjoyable playing about with this camera stuff in tea breaks though 😀   So many ways to get the time for a date formatted filename, well I never, its what makes it all such fun. 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7026
 

@byron This is a back-burner exercise for me, my game cameras will use MotionEyeOS the PIR is far too flaky. I do have a PIR on my workbench, but although my VOM says it is working, I can't get the Pi to respond to it. I might spend a few more hours today, but soon I will shelve it as it does not appear to be useful in the wild.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@emeyeraway)
Member
Joined: 3 years ago
Posts: 21
Topic starter  

@byron 

Your latest version of the code works just fine.  In the meantime I have discovered that running Raspi headless requires going through VNC; if I use ssh the code doesn't run.  Also since getting "libcamera-hello" back on Raspi 4B, some code I had downloaded ("Burglar_Detector.py" from https://randomnerdtutorials.com) and couldn't get to run - now runs just fine.  I now believe that all the trouble I was having with picamera2 was the result of Raspi somehow losing "libcamera-hello" without my realizing it.  I now run "libcamera-hello" before trying new code to avoid this in future.

So now I have code that accomplishes my goals and I will probably never know what caused the "60-seconds" phenomenon in my old code.  Better for me to try to understand this new code than to pursue that problem.

This forum has been a terrific experience for me.  Thank you all who responded!


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7026
 

@emeyeraway As I pointed out to Byron, just add the --datetime option to create a file with a name of date and time.

I am a little confused as to what you are doing, are you planning on an unattended operation relying on the PIR sensor to take some pictures, or are you sitting in front of a monitor watching? If it will be unattended, there is no need for a preview and if you are watching, you might want/need a button to take a picture manually as the PIR may be in the TI window or otherwise not able to trigger a picture at the right time. How remote will the Pi be and what will power it? If you are planning on using VNC the WiFi chip on the Pi is a power hog. If it isn't too far away, an extension cord and wall wart can do the job, just keep the DC leads short as DC does NOT like long runs.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 

@zander

for some years I've had one of these 'nature' cameras

https://thepihut.com/products/naturebytes-wildlife-camera-case

It worked well enough until the plastic lens of the PIR cracked.  I've been meaning to repair it for several years but I've not got round to it.  If I remember right mine contains an old rpi2 A (wifi only) and it runs a python script.  But it all worked quite well with the PIR sensor.  Its only one of those cheap sensors one can get anywhere.  It uses an rpi camera and the python script is basic, nothing cleaver, but it will not work with the latest rpi os.

If your set up is not working then it would be quite cheap to get a new rpi camera and a sensor and you would soon get a new game camera up and running using your own had rolled libcamera based program I'm sure.  Why do you need all that motioneye complication, get a RonEye package working


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7026
 

@byron Nothing complicated about it, I installed it on a Pi Zero and had it working in a couple minutes. The problem now of course is that I can't buy a Pi Zero at a reasonable price. I am slowly investigating alternatives using esp series 3 perhaps, clone Pi Zero boards, possibly PICO.

At the moment and since last fall I am not well enough to work on this for very long but hopefully, I will be well by the summer. Of course, if all goes according to plan, I will be moving so realistically if I get medical service in time, it will be tied up until the fall of this year. If I can't get medical service in time then the fall of next year.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@emeyeraway)
Member
Joined: 3 years ago
Posts: 21
Topic starter  

@zander 

Well, I’m ready to throw in the towel; I’m clearly in over my head. Here’s the latest:

I copied some code from https://randomnerdtutorials : Burglar_Detector.py It was written for picamera, so I had to modify it for picamera2. I also modified it to use the date-time as the name of the file. The code is given below. (I left in some hashed-out lines for code that didn’t do what I had expected.)

When I run this code, a picture is taken every 60 seconds – just like the earlier code I had written myself.

There is an error that doesn’t keep the code from running: “qt.qpa.xcb: QxcbConnection: XCB error: 148 (Unknown), sequence: 192, resource id: 0, major code: 140 (Unknown), minor code: 20”

This surprises me, since it seems related to Qt, and exactly the same error occurs when I run the code that byron sent me, written in pyQt5. However, the error occurs only before a picture is taken; once pictures are being taken the error doesn’t appear and the code seems to run OK.

from picamera2 import Picamera2, Preview
#Project 13 - Burglar Detector With Photo Capture
#latest code updates available at:  https://github.com/RuiSantosdotme/RaspberryPiProject 
#project updates at:  https://nostarch.com/RaspberryPiProject 

#import the necessary packages
from gpiozero import Button, MotionSensor
from picamera2 import Picamera2
from time import sleep
from signal import pause
from libcamera import Transform
import datetime





#create objects that refer to a button,
#a motion sensor and the PiCamera
button = Button(2)
pir = MotionSensor(17)
picam2 = Picamera2()

#start the camera
#picam2.rotation = 180
picam2.start_preview(Preview.QTGL, transform=Transform(hflip=True, vflip=True))
#still_config = picam2.create_still_configuration(transform=Transform(hflip=True, vflip=True))
#picam2.configure(still_config)
picam2.start()
sleep(2)

#image image names
i = 0

#stop the camera when the pushbutton is pressed
def stop_camera():
    picam2.stop_preview()
    #exit the program
    exit()

#take photo when motion is detected
def take_photo():
    timestamp = str((datetime.datetime.now()))
    timestamp = timestamp[5:19]
    global i
    i = i + 1
    picam2.capture_file('/home/pi/aPyProg/%s.jpg' % timestamp)
    print('A photo has been taken')
    sleep(10)

#assign a function that runs when the button is pressed
button.when_pressed = stop_camera
#assign a function that runs when motion is detected
pir.when_motion = take_photo

pause()

   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7026
 

@emeyeraway It's every 60 seconds because the TX potentiometer on the side of your camera module is set for 60 seconds. If you are close enough to see the sketch output, then the sensor will fire. Try it again, but close the door to the room and wait outside for at least 5 minutes. Now go back and see how many pictures were taken. If still too many (one or two is likey) then move the jumper to the other position and try again. I will try this code on my Pi4 later today to see what hapens.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@emeyeraway)
Member
Joined: 3 years ago
Posts: 21
Topic starter  

@zander 

There is no potentiometer on my sensor HC-SR312 AM312.  I have a good idea of what kind of motion sets off the sensor.


   
ReplyQuote
(@emeyeraway)
Member
Joined: 3 years ago
Posts: 21
Topic starter  

@byron

I inadvertently sent my last reply to Ron; is there some way that you can read t?


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7026
 

@emeyeraway Then it is hard coded to go off every 60 seconds as long as motion is detected. In order to prove the setup, after it reports taking one picture, put a towel over the sensor, you may think there is no motion, but it could be something as simple as a fan in the Pi, a hot spot from the sun shining in (remember they are actually heat sensors)

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7026
 

@emeyeraway He can see it, ALL posts are visible to ALL members.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1697
 

Hi @emeyeraway,

   I don't have any of the components under discussion in this thread, so I can't reproduce the problems.

However, I fear you have fallen into a trap that I have seen many times before in both amateur and professional scenarios ... starting with a complex system with lots of parts that are all 'new' to you. This situation can easily result in several problems to solve at the same time, and that is vastly more difficult than solving one problem at a time.

Please don't take this as a personal attack or criticism ... it is a situation we have all fallen into from time to time, and sometimes it is difficult to avoid. The trick is to recognise it has happened and find a way out.

So in a sense, I agree that 'throwing the towel in' might be a good idea, if you mean not carrying on trying to fix the whole system as it stands, but that doesn't mean you need to give up entirely. Instead, 'take a step back' and see if you can start with a simpler aim that is an essential part of your final system, and demonstrate that it works as expected. You will then have a more positive foundation to build on.

----------

In your case, I would start with just the PIR sensor, your chosen processor board, and an LED (with current limiting resistor). Build a system, with as little use of libraries as possible, to demonstrate that the LED is switched on when the sensor is triggered for the correct reason, and at no other time.

If you would like some help with this, then start a new thread, beginning  by explaining in detail exactly which components you are using.

For example, from your recent post, I note you mention "HC-SR312 AM312", but unfortunately not provided a reference. I might guess you mean one like:

https://thepihut.com/products/breadboard-friendly-mini-pir-motion-sensor-with-3-pin-header

... but I could be completely wrong ... you may be using another different device, even though this thread is on the 7th page,  .... 

----------

So by all means, look for a way of making a 'fresh start', review what has happened so far, but use it all in a positive way, as part of the learning exercise.

I very much hope you will continue with your overall project, and succeed in the end. Don't be put off when you find one road is blocked off ... do a short back track, find another one and keep going.

Best wishes, Dave


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7026
 

@davee Excellent advice Dave. I would go a step further, and use C rather than Python as 1 line of Python is who knows how many lines of C and as such much is hidden and therefore you can't really learn the basic foundations.

I am not sure how exactly to do this on a Pi, but in the Arduino IDE there is an example sketch for the Pi PICO called Button. Maybe copy that and get it working, then simply change the button for a PIR sensor and observe. I will do the same with a PICO and my PIR sensor and post the results.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 7 / 9