Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"configuration": "cpu=atmega2560",
"board": "arduino:avr:mega",
"board": "arduino:avr:uno",
"programmer": "avrisp",
"port": "COM9",
"port": "COM7",
"sketch": "transmitter\\transmitter.ino"
}
4 changes: 2 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"intelliSenseMode": "gcc-x64",
"includePath": [
"C:\\Users\\sabzi\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\cores\\arduino",
"C:\\Users\\sabzi\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\mega",
"C:\\Users\\sabzi\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\standard",
"C:\\Users\\sabzi\\OneDrive - Baku Higher Oil School\\Documents\\Arduino\\libraries\\MFRC522\\src",
"C:\\Users\\sabzi\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\libraries\\SPI\\src",
"C:\\Users\\sabzi\\OneDrive - Baku Higher Oil School\\Documents\\Arduino\\libraries\\Servo\\src",
Expand All @@ -33,7 +33,7 @@
"defines": [
"F_CPU=16000000L",
"ARDUINO=10607",
"ARDUINO_AVR_MEGA2560",
"ARDUINO_AVR_UNO",
"ARDUINO_ARCH_AVR",
"__DBL_MIN_EXP__=(-125)",
"__HQ_FBIT__=15",
Expand Down
41 changes: 33 additions & 8 deletions itemlist_retriever.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json # used to convert string obtained from database to a dictionary
import time # used to sleep the program for a certain amount of time
from serial import Serial # used to connect to the serial port
from serial.tools import list_ports # used to list all the serial ports
import mysql.connector # used to connect to the database
from credentials import CREDENTIALS # used to store the credentials for the database
from os import name as os_name # used to check the operating system

PORT = "COM9" # change this to the port that the arduino is connected to
BAUDRATE = 9600 # change this to the baudrate that the serial port is using

BAUDRATE = (
9600 # baudrate of the serial connection to the arduino, change this if needed
)

# used to store the previous items that were retrieved from the database
# this is used to check if the items have changed during the next iteration of the loop
Expand Down Expand Up @@ -34,20 +36,43 @@ def fetch_all_items(self):


class SerialConnection:
def __init__(self, port, baudrate):
self.port = port
def __init__(self, baudrate):
self.port = self.find_ARDUINO_serial_port()
self.baudrate = baudrate
self.ser = Serial(port, baudrate)
self.ser = Serial(self.port, self.baudrate)
print("Connected to serial -- success")

def write(self, data):
self.ser.write(data.encode())

@staticmethod
def find_ARDUINO_serial_port():
if os_name == "nt":
for i in range(0, 256):
try:
port = "COM" + str(i)
ser = Serial(port)
ser.close()
return port
except:
pass
elif os_name == "posix":
for port in range(0, 256):
try:
port = "/dev/ttyUSB" + str(port)
ser = Serial(port)
ser.close()
return port
except:
pass
else:
raise Exception("Unknown OS")

def read(self):
try:
return self.ser.readline().decode().strip()
except:
return ">>>>> ERROR <<<<<"
return ">>>>> ERROR - Serial read failed - possible cause: serial port not connected"

def close(self):
self.ser.close()
Expand All @@ -61,7 +86,7 @@ def __init__(self, db, ser):

def main():
db = DatabaseConnection(CREDENTIALS)
ser = SerialConnection(PORT, BAUDRATE)
ser = SerialConnection(BAUDRATE)
items_dict = db.fetch_all_items()
prev_items = items_dict
iter_cnt = 0
Expand Down
28 changes: 14 additions & 14 deletions transmitter/transmitter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
// RST D9 D8
// 3.3V 3.3V 3.3V

#define servoPin 10 // Set servo pin
String previousUID = "0"; // Do not change //
#define servoPin 8 // Set servo pin
String previousUID = "0"; // Do not change //
String previousRFIDUID = "0"; // Do not change //
String fromSerialUID = "0"; // Do not change //
String fromRFIDUID = "0"; // Do not change //
String readSerialFlag = "0"; // Do not change //
int printCounter = 0; // Do not change //
int pickUpTimeout = 1500; // Set timeout for picking up item
int serialBaudRate = 9600; // Set serial baud rate
int optimizationDelay = 50; // Fine tune this value to optimize performance
Servo myServo; // Do not change //
MFRC522 card(9, 8); // SDA, RST set up for MEGA
String fromSerialUID = "0"; // Do not change //
String fromRFIDUID = "0"; // Do not change //
String readSerialFlag = "0"; // Do not change //
int printCounter = 0; // Do not change //
int pickUpTimeout = 1500; // Set timeout for picking up item
int serialBaudRate = 9600; // Set serial baud rate
int optimizationDelay = 50; // Fine tune this value to optimize performance
Servo myServo; // Do not change //
MFRC522 card(10, 9); // SDA, RST set up for MEGA

void setup()
{
Expand All @@ -39,7 +39,7 @@ void setup()

void loop()
{
// Check if there is a new RFID from DB
// Check if there is a new RFID from DB
if (readSerialFlag == "0")
{
// if there is a new RFID from DB, set flag to 1
Expand Down Expand Up @@ -87,8 +87,8 @@ void loop()
// printCounter is used to print message every 10 iterations
printCounter++;
}
// function to read RFID from DB via serial

// function to read RFID from DB via serial
String readSerial()
{
String fromSerialRFID = "";
Expand Down