diff options
| author | Edvin <[email protected]> | 2025-05-02 11:57:35 +0200 |
|---|---|---|
| committer | Edvin <[email protected]> | 2025-05-02 11:57:35 +0200 |
| commit | 94203da32939e02476e2c747718e1d5d4eeb238a (patch) | |
| tree | 558a37d0f7236ea358bc2446c56ec6bb1a95aeb0 | |
| parent | 115b28f0cd219b98209839123c656771c252f6a9 (diff) | |
Added LED and photo transistor
| -rw-r--r-- | arduino/arduino.ino | 6 | ||||
| -rwxr-xr-x | main.py | 16 |
2 files changed, 16 insertions, 6 deletions
diff --git a/arduino/arduino.ino b/arduino/arduino.ino index 9e38b13..708fcec 100644 --- a/arduino/arduino.ino +++ b/arduino/arduino.ino @@ -16,6 +16,9 @@ LiquidCrystal_I2C lcd(0x27, 20, 4); int emptySpace = 0; void setup() { + pinMode(LED_PIN, OUTPUT); + digitalWrite(LED_PIN, HIGH); + pinMode(D1, OUTPUT); pinMode(D2, OUTPUT); pinMode(D3, OUTPUT); @@ -25,9 +28,6 @@ void setup() { digitalWrite(D3, LOW); digitalWrite(D4, LOW); - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, LOW); - Serial.begin(115200); lcd.init(); @@ -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: |
