← Back to ratslair.com
aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorEdvin <[email protected]>2025-05-02 11:57:35 +0200
committerEdvin <[email protected]>2025-05-02 11:57:35 +0200
commit94203da32939e02476e2c747718e1d5d4eeb238a (patch)
tree558a37d0f7236ea358bc2446c56ec6bb1a95aeb0 /main.py
parent115b28f0cd219b98209839123c656771c252f6a9 (diff)
Added LED and photo transistor
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/main.py b/main.py
index 53f5679..68c4139 100755
--- a/main.py
+++ b/main.py
@@ -5,12 +5,20 @@ import serial
import select
from time import sleep
import math
+import RPi.GPIO as GPIO
+
+LED = 17 # Light emitting diode
+PT = 27 # Phototransistor
+
+GPIO.setmode(GPIO.BCM)
+GPIO.setup(PT, GPIO.IN)
+GPIO.setup(LED, GPIO.OUT)
# Open serial port to Arduino Nano
-NANO = serial.Serial('/dev/ttyUSB1', 9600, timeout=1)
+NANO = serial.Serial('/dev/ttyUSB1', 115200, timeout=1)
sleep(2)
-BluetoothProcess = subprocess.Popen(["python", "-u", "/home/pi/TNE107-RPI/bt.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, text=True)
+BluetoothProcess = subprocess.Popen(["python", "-u", "/home/pi/TNE107-RPI/bt.py"], stdout=subprocess.PIPE, text=True)
# Waiting on connection
NANO.write(b"Bluetooth up\n")
@@ -47,6 +55,7 @@ curDir = 0.0
desDir = 0.0
if bto.find("Connected") != -1:
+ GPIO.output(LED, True)
nanoBtMessage = "Bluetooth connected " + bto[13:].translate({ord(c): None for c in ':'}) # Address to send to nano
NANO.write(nanoBtMessage.encode())
print(nanoBtMessage)
@@ -56,12 +65,13 @@ if bto.find("Connected") != -1:
print(f"LIDAR PID: {LIDARProcess.pid}")
# DWM Process Code
- DWMProcess = subprocess.Popen(["python", "-u", "/home/pi/TNE107-RPI/DWM.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, text=True)
+ DWMProcess = subprocess.Popen(["python", "-u", "/home/pi/TNE107-RPI/DWM.py"], stdout=subprocess.PIPE, text=True)
print(f"DWM PID: {DWMProcess.pid}")
sleep(5)
while bto != "1000":
+ print(GPIO.input(PD))
btReady, _, _ = select.select([BluetoothProcess.stdout], [], [], 0.0005)
if btReady: