Pi 4

Pi 4 - script in Python with the date and time marked

Many of the novice programmers such as would like to start their fun with Raspberry. Most of them search the Web for scripts and programs written in Python to take full advantage of Pi. Today, a short program that encloses a camera for a specified time dividing files into time-defined files.

Recently, I became the owner of Raspberry 4. I also decided to learn Python programming. I would like to be able to take full advantage of Pi, I have some nice ideas for servicing the entire home along with mining cryptocurrencies. I want to buy Raspberry to have one device in each room. Each of them is to measure the temperature, record movement, measure the air level, warn of poor air quality, high dustiness, open windows when necessary, warn of smoke and smoke from the furnace. For this, the central unit is to serve as an alarm and fire control panel. I have a few other ideas but more on that later.

Returning to the subject, as if it were if I had Raspberry and I did not buy the periphery. On AliExpress I bought an infrared camera. Waiting time only 2 weeks. After connecting to Pi you would have to run the webcam to start the fun. The course on comes with help here. Two days later I wanted to launch the webcam, but this time from Python. Quickly on the network I found a short program that allowed me to run and record a webcam video.

import picamera

camera = picamera.PiCamera()
camera.resolution = (640, 480)

The applet allowed to launch the webcam and record the movie in 640 × 480 resolution and 60 seconds length. Unfortunately, the movie lacked a time stamp. After all, what if I had to record a film lasting 12 hours? I started searching for a program that will allow me to record a movie for 12 hours by dividing it into hourly parts. Finally succeeded. The program recorded a movie with a time stamp, it was enough to modify it to meet my criteria.

Thanks to the beginner course, I looped the program that now allows me to record as many hours as I want, saving hourly parts.

import picamera
import datetime as dt

camera = picamera.PiCamera(resolution=(640, 480), framerate=24)
#Podgląd bieżący z kamery, wystarczy usunąć #
camera.annotate_background = picamera.Color('black')
camera.annotate_text ='%Y-%m-%d %H:%M:%S')
for i in range(2, 6):# 6 - to ilość godzin w nagrywaniu -1
    start =
    # 3600 - czas trwania jednego filmu
    while ( - start).seconds < 3600:
        camera.annotate_text ='%Y-%m- %d %H:%M:%S')
    camera.split_recording('%d.h264' % i)

This is not the best solution, but it works. Over time, as I continue to deepen my knowledge, I will probably make better improvements or write my program, but it must be enough for today.

The program fulfills its role. Making an entry in crontab, the camera records infrared films every day from 23 to 7 am, so I know what's happening at night on the terrace at the back of the house. Maybe beginners will need this knowledge. Greetings.

How do you rate this article?


Python - moje pierwsze kroki / Python - my first s
Python - moje pierwsze kroki / Python - my first s

Python programming - I've heard so much about it that I decided to be tempted to learn. The more I try, the harder it pulls me. Who knows maybe in my old age I will become a programmer :)

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.