Added so much stuff I forgot again

This commit is contained in:
Haldrup-tech 2025-04-15 13:10:57 -04:00
parent d1f8f7294b
commit d61fdb790a
161 changed files with 386 additions and 0 deletions

BIN
Spring 2025/.DS_Store vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Spring 2025/ENGR 490/.DS_Store vendored Normal file

Binary file not shown.

BIN
Spring 2025/ENGR 490/1/.DS_Store vendored Normal file

Binary file not shown.

BIN
Spring 2025/ENGR 490/10/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -0,0 +1,30 @@
from picamera2 import Picamera2, Preview
from gpiozero import DistanceSensor
import time
import os
user = os.getlogin()
user_home = os.path.expanduser(f'~{user}')
camera = Picamera2()
camera.start()
sensor = DistanceSensor(echo=24, trigger=23)
try:
i = 1
while (1):
dis = sensor.distance * 100
print('Distance: {:.2f} cm'.format(dis))
if dis < 100:
camera.capture_file(f'{user_home}/Assignments/10/rev_capture%s.jpg' % i)
print('The number is %s' % i)
time.sleep(3)
i += 1
else:
print('waiting')
time.sleep(0.5)
except KeyboardInterrupt:
camera.stop_preview
camera.stop
pass

Binary file not shown.

Binary file not shown.

BIN
Spring 2025/ENGR 490/11/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,55 @@
from picamera2 import Picamera2
import cv2
import os
camera = Picamera2()
preview_config = camera.create_preview_configuration(main={'size': (640, 480)})
camera.configure(preview_config)
camera.start()
if not os.path.exists("haarcascade_frontalface_default.xml"):
import urllib.request
url = "https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml"
urllib.request.urlretrieve(url, "haarcascade_frontalface_default.xml")
if not os.path.exists("haarcascade_eye.xml"):
import urllib.request
url = "https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_eye.xml"
urllib.request.urlretrieve(url, "haarcascade_eye.xml")
if not os.path.exists("haarcascade_smile.xml"):
import urllib.request
url = "https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_smile.xml"
urllib.request.urlretrieve(url, "haarcascade_smile.xml")
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
smile_cascade = cv2.CascadeClassifier('haarcascade_smile.xml')
while(1):
frame = camera.capture_array()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
eyes = eye_cascade.detectMultiScale(gray, 1.3, 5)
smiles = smile_cascade.detectMultiScale(gray, 1.8, 20)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
for (x, y, w, h) in eyes:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
for (x, y, w, h) in smiles:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 0, 255), 2)
cv2.imshow("Real-Time Face Detection", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()

View File

@ -0,0 +1,54 @@
from picamera2 import Picamera2
import cv2
import numpy as np
import os
import urllib.request
if not os.path.exists("MobileNetSSD_deploy.prototxt"):
urllib.request.urlretrieve(
"https://raw.githubusercontent.com/chuanqi305/MobileNet-SSD/master/deploy.prototxt",
"MobileNetSSD_deploy.prototxt"
)
if not os.path.exists("MobileNetSSD_deploy.caffemodel"):
urllib.request.urlretrieve(
"https://github.com/chuanqi305/MobileNet-SSD/raw/master/mobilenet_iter_73000.caffemodel",
"MobileNetSSD_deploy.caffemodel"
)
net = cv2.dnn.readNetFromCaffe('MobileNetSSD_deploy.prototxt', 'MobileNetSSD_deploy.caffemodel')
CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat", "bottle",
"bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse",
"motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
camera = Picamera2()
camera.configure(camera.create_preview_configuration(main={'size': (640, 480)}))
camera.start()
while (1):
frame = camera.capture_array()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
(h, w) = frame.shape[:2]
blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300,300)), 0.007843, (300, 300), 127.5)
net.setInput(blob)
detections = net.forward()
for i in range(detections.shape[2]):
confidence = detections[0, 0, 1, 2]
if confidence > 0.5:
idx = int(detections[0, 0, 1, 1])
box = detections[0, 0, 1, 3:7] * np.array([w, h, w, h])
(startX, startY, endX, endY) = box.astype("int")
label = f"{CLASSES[idx]}: {confidence*100:.2f}%"
cv2.rectangle(frame, (startX, startY), (endX, endY), (0,255,0), 2)
cv2.putText(frame, label, (startX, startY - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,255,0), 2)
cv2.imshow("Object Detection", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destoryAllWindows()

Binary file not shown.

View File

@ -0,0 +1,55 @@
from picamera2 import Picamera2
from gpiozero import LED
import cv2
import os
camera = Picamera2()
led = LED(17)
off = True
on_time = 100
time_left = 0
preview_config = camera.create_preview_configuration(main={'size': (640, 480)})
camera.configure(preview_config)
camera.start()
if not os.path.exists("haarcascade_frontalface_default.xml"):
import urllib.request
url = "https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml"
urllib.request.urlretrieve(url, "haarcascade_frontalface_default.xml")
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
while(1):
frame = camera.capture_array()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
try:
if faces[0][0] > 0 :
off = False
time_left = on_time
except:
off = True
if not off or time_left > 0:
led.on()
time_left = time_left - 1
else:
led.off()
time_left = 0
print(time_left)
cv2.imshow("Real-Time Face Detection", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Spring 2025/ENGR 490/12/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,27 @@
import socket
import time
import math as np
SERVER_IP = "pistudent7"
SERVER_PORT = 8080
def send_distance():
x = 0
while True:
try:
distance_cm = abs(np.sin(x)) * 100
message = f"DISTANCE:{distance_cm:.2f}cm"
with socket.socket() as sock:
sock.connect((SERVER_IP, SERVER_PORT))
sock.sendall(message.encode())
print(f"Sent: {message}")
time.sleep(1)
x = x + .1
except Exception as e:
print(f"Error: {e}")
time.sleep(5)
if __name__ == "__main__":
send_distance()

Binary file not shown.

View File

@ -0,0 +1,25 @@
import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(('0.0.0.0', 8080))
server_socket.listen(1)
print("Server ready, Waiting for data...")
while True:
conn, addr = server_socket.accept()
print(f"Connected to {addr}")
try:
while True:
data = conn.recv(1024)
if not data:
break
print(f"Recieved: {data.decode()}")
except Exception as e:
print(f"Error: {e}")
finally:
conn.close()
print(f"Connection to {addr} closed.")

Binary file not shown.

View File

@ -0,0 +1,11 @@
import smtplib
from email.mime.text import MIMEText
msg = MIMEText("Hello from your Rasberry Pi!")
msg['Subject'] = 'RPi Alert'
msg['From'] = 'ghaldrup00@gmail.com'
msg['To'] = 'garrett@haldrup.tech'
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server:
server.login('ghaldrup00@gmail.com', 'xxxxxxxxxxxxxxxxxxx')
server.send_message(msg)

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

View File

@ -0,0 +1,22 @@
from gpiozero import DistanceSensor
import smtplib
from email.mime.text import MIMEText
import time
ultra = DistanceSensor(echo=24, trigger=23)
while (1):
time.sleep(1)
print(round(ultra.distance * 100, 2))
if (ultra.distance * 100) > 50:
print("Sending email")
msg = MIMEText(f"Distance is over 50cm it is {round(ultra.distance * 100, 2)}cm!")
msg['Subject'] = 'Distance Alert'
msg['From'] = 'ghaldrup00@gmail.com'
msg['To'] = 'garrett@haldrup.tech'
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server:
server.login('ghaldrup00@gmail.com', 'irfm gopy mcsi suge')
server.send_message(msg)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Spring 2025/ENGR 490/2/.DS_Store vendored Normal file

Binary file not shown.

BIN
Spring 2025/ENGR 490/3/.DS_Store vendored Normal file

Binary file not shown.

BIN
Spring 2025/ENGR 490/4/.DS_Store vendored Normal file

Binary file not shown.

BIN
Spring 2025/ENGR 490/4/A4/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
Spring 2025/ENGR 490/4/P4/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,12 @@
# Get user input
number = int(input("Enter a number: "))
# Check if the number is positive, negative, or zero
if number > 0:
print(f"{number} is positive.")
elif number < 0:
print(f"{number} is negative.")
else:
print("The number is zero.")

View File

@ -0,0 +1,16 @@
# Print numbers from 1 to 10 using a for loop
print("For Loop:")
for i in range(1,11):
print(i)
# Print numbers from 1 to 5 using a while loop
print("While Loop:")
count = 1
while count <= 5:
print(count)
count += 1

View File

@ -0,0 +1,12 @@
# Get two numbers from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Perform basic operations
print(f"Addition: {num1 + num2}")
print(f"Subtraction: {num1 - num2}")
print(f"Multiplication: {num1 * num2}")
print(f"Division: {num1 / num2}")

View File

@ -0,0 +1,17 @@
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
operation = input("CHoose an operation (+, -, *, /): ")
if operation == "+":
result = num1 + num2
elif operation == "-":
result = num1 - num2
elif operation == "*":
result = num1 * num2
elif operation == "/":
result = num1 / num2
else:
result = "Invalid operation"
print(f"Result: {num1} {operation} {num2} = {result}")

View File

@ -0,0 +1,6 @@
def greet_user(name):
print(f"Hello, {name}! Welcome to the Python function activity.")
greet_user("Alice")
greet_user("Bob")

BIN
Spring 2025/ENGR 490/5/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,12 @@
from gpiozero import LED, Button
from time import sleep
led = LED(18)
button = Button(17)
try:
while(1):
button.when_pressed = led.on
button.when_released = led.off
except KeyboardInterrupt:
print("Exiting..")

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,15 @@
from gpiozero import LED
import time as time
led = LED(17)
try:
while(1):
led.on()
time.sleep(0.5)
led.off()
time.sleep(0.5)
except KeyboardInterrupt:
print("Exiting...")
finally:
pass

Binary file not shown.

Binary file not shown.

BIN
Spring 2025/ENGR 490/6/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Spring 2025/ENGR 490/6/P6/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More