Tags: Raspberry Pi, Electronics
Raspberry Pi For Beginners - 2021 Complete Course | Udemy
- The current limit for the Raspberry Pi is near 15 mA.
- When using an infinite loop, use
time.sleepto consume less CPU usage. hostname -Ifor the IP address on the network.df -hfor the available space on the SD card.sudo raspi-configfor more Rasp configs.- Use
yagmailto send and receive emails (SMTP). - You can use
systemdto start your app when the Raspberry Pi boots up.[Unit] Description = Program that detects movements, takes a photo and sends an email with it After=multi-user.target [Service] ExecStart=/user/bin/python3 /home/pi/Documents/python_programs/project_step4.py User=pi [Install] WantedBy=multi-user.target
- Then
sudo systemctl enable project.service
- Then
- Taking photos:
raspistill -o camera/img.jpg- You can also use rotation, width and height arguments.
- And you can also record videos with
raspivid - In Python:
import picamera camera = PiCamera() camera.resolution = (1280, 720) camera.rotation = 180 time.sleep(2) file_name = "path/to/file" camera.capture(file_name) print("Done.") # Or: camera.start_recording(file_name) camera.wait_recording(10) camera.stop_recording()
pip3 listto list all of the installed packages.except KeyboardInterrupt:captures the Ctrl + C exception.
# Use `"w"` to write
with open("/home/pi/text_file", "r") as f:
# print(f.read())
for line in f:
print(line)if os.path.exists("/home/pi/text_file"):
print("File exists")
os.remove("/home/pi/text_file")from flask import Flask
import RPi.GPIO as GPIO
BUTTON_PIN = 26
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_PIN, GPIO.IN)
app = Flask(__name__)
@app.route("/")
def index():
return "Hello from Flask"
@app.route("/push-button")
def push_button_state():
if GPIO.input(BUTTON_PIN) == GPIO.HIGH:
return ""
else:
return "Button is not pressed"
app.run(host="0.0.0.0", port=8500)