Do all of comment line on virtual environment...
- picamera2 default install with piOS bookworm B1: create virtual environment with comment line in the first folder default:
python -m venv --system-site-packages env source env/bin/activate
B2: test camera with comment line:
python3 "name_of_file_python" /or sudo python3 "name_of_file_python"
Note: follow link documentation "https://datasheets.raspberrypi.com/camera/picamera2-manual.pdf" or code:
To install opencv, follow this link: https://pypi.org/project/opencv-python/#manual-builds
pip install opencv-contrib-python
import cv2 from picamera2 import Picamera2
picam2 = Picamera2() picam2.preview_configuration.main.size=(640,480) #max of Camera PiV2 is (3280, 2464) picam2.preview_configuration.main.format = "RGB888" picam2.start()
while True: im = picam2.capture_array() cv2.imshow("preview", im) if cv2.waitKey(1) == ord('q'): break
picam2.stop() cv2.destroyAllWindows()
Note: Must run the code on Terminal of VNC-viewer or similar, because some IDE like VScode doesn't, it show "Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.
Aborted"
B1: install paho-mqtt library. Follow this link: https://console.hivemq.cloud/clients/python-paho
Note: install paho-mqtt<2.0 like "pip3 install paho-mqtt==1.5.1" Or Follow this link: https://github.com/hivemq-cloud/paho-mqtt-client-example/blob/master/requirements.txt
B2: code example in here: https://github.com/hivemq-cloud/paho-mqtt-client-example/blob/master/simple_example.py
There are 4 things we need to see: client.username_pw_set("<your_username>", "<your_password>") client.connect("<your_host>", 8883)
B3: create account MQTT broker (example HiveMQ) like:
- Go to "https://www.hivemq.com/
- next "Login"
- Create a free Cluster
- ULR is hostname
- Port 8883
- Click "Manage Cluster" -> "Client"
- Autocreate account... then we need to remember this!
- Next subcribe all the topic "#"
...waiting to write...
- Follow this link: https://sparklers-the-makers.github.io/blog/robotics/use-neo-6m-module-with-raspberry-pi/
Note: Fix problem "ERROR V4L2 v4l2_videodevice.cpp:1906 /dev/video0[18:cap]: Failed to start streaming: Invalid argument"
follow this link: raspberrypi/libcamera#104
Code file GPS_PUB_SUB.py
Code file DETECT_RYB_PUBSUB.py