From f587dafb154eb9836626cc16ee6120233a29fc89 Mon Sep 17 00:00:00 2001 From: SWETRAK Date: Fri, 3 Jul 2026 14:33:54 +0200 Subject: [PATCH 1/7] feat: updated main README.md file --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index da4fe1d..2cc8bdc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ # Architektoniczne perełki Lublina +## Master device + +Insert for this device is in directory `API_Master`. This device communicates with PC. + +## Slave + +### Slave 1 + +### Slave 2 + +### Slave 3 + +### Slave 4 + +### Slave 5 \ No newline at end of file -- 2.54.0 From 3eb119f6a2b6adbbb1bc7a5b423ebbfb8b470b77 Mon Sep 17 00:00:00 2001 From: SWETRAK Date: Fri, 3 Jul 2026 23:02:53 +0200 Subject: [PATCH 2/7] feat: added configurations for i2c communication between devices --- APL_Master/README.md | 14 ++++++++++++- APL_Master/platformio.ini | 3 ++- APL_Master/src/main.cpp | 42 +++++++++++++++++++++++++++++++++++++++ APL_Slave_1/README.md | 7 +++++++ APL_Slave_1/src/main.cpp | 19 ++++++++++++++++++ APL_Slave_2/README.md | 9 ++++++++- APL_Slave_2/src/main.cpp | 20 ++++++++++++++++++- APL_Slave_3/README.md | 9 ++++++++- APL_Slave_3/src/main.cpp | 20 ++++++++++++++++++- APL_Slave_4/README.md | 9 ++++++++- APL_Slave_4/src/main.cpp | 19 ++++++++++++++++++ APL_Slave_5/README.md | 9 ++++++++- APL_Slave_5/src/main.cpp | 19 ++++++++++++++++++ 13 files changed, 191 insertions(+), 8 deletions(-) diff --git a/APL_Master/README.md b/APL_Master/README.md index f7a9d96..66ab445 100644 --- a/APL_Master/README.md +++ b/APL_Master/README.md @@ -1 +1,13 @@ -# Architektoniczne perełki Lublina - Master \ No newline at end of file +# Architektoniczne perełki Lublina - Master + +## I2C +Pins: + - SDA -> 21 + - SCL -> 22 + +Addresses: + - Slave 1 -> `0x08` + - Slave 2 -> `0x09` + - Slave 3 -> `0x0A` + - Slave 4 -> `0x0B` + - Slave 5 -> `0x0C` \ No newline at end of file diff --git a/APL_Master/platformio.ini b/APL_Master/platformio.ini index 86818e0..e45e6ea 100644 --- a/APL_Master/platformio.ini +++ b/APL_Master/platformio.ini @@ -12,5 +12,6 @@ platform = espressif32 board = esp32dev framework = arduino - monitor_speed = 115200 + +lib_deps = fastled/FastLED@^3.10.3 diff --git a/APL_Master/src/main.cpp b/APL_Master/src/main.cpp index 37a1561..9feee3d 100644 --- a/APL_Master/src/main.cpp +++ b/APL_Master/src/main.cpp @@ -1,11 +1,53 @@ #include +#include +#include + +#define SDA_PIN 21 +#define SCL_PIN 22 + +#define SLAVE_ONE_ADDRESS 0x08 +#define SLAVE_TWO_ADDRESS 0x09 +#define SLAVE_THREE_ADDRESS 0x0A +#define SLAVE_FOUR_ADDRESS 0x0B +#define SLAVE_FIVE_ADDRESS 0x0C + +#define LED_DATA_PIN 5 +#define LED_COUNT 29 +#define BRIGHTNESS 64 +#define LED_TYPE WS2812B +#define COLOR_ORDER GRB + +CRGB leds[LED_COUNT]; + +const CRGB SUCCESS_COLOR = CRGB::Green; +const CRGB ERROR_COLOR = CRGB::Red; + +void testLedStrip(); void setup() { + Wire.begin(SDA_PIN, SCL_PIN); Serial.begin(115200); + + // Initialize FastLED with the specified LED type, data pin, and LED count + FastLED.addLeds(leds, LED_COUNT).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + testLedStrip(); } void loop() { // put your main code here, to run repeatedly: } + +void testLedStrip() +{ + // Test the LED strip by turning on each LED one by one + for (int i = 0; i < LED_COUNT; i++) + { + leds[i] = SUCCESS_COLOR; // Set the LED to green + FastLED.show(); + delay(100); // Wait for a short duration + leds[i] = CRGB::Black; // Turn off the LED + } +} \ No newline at end of file diff --git a/APL_Slave_1/README.md b/APL_Slave_1/README.md index 0a16a38..a59945c 100644 --- a/APL_Slave_1/README.md +++ b/APL_Slave_1/README.md @@ -1 +1,8 @@ # Architektoniczne perełki Lublina - Slave 1 + +## I2C +Pins: + - SDA -> 21 + - SCL -> 22 + +Address: 0x08 \ No newline at end of file diff --git a/APL_Slave_1/src/main.cpp b/APL_Slave_1/src/main.cpp index b1cef02..895c624 100644 --- a/APL_Slave_1/src/main.cpp +++ b/APL_Slave_1/src/main.cpp @@ -1,10 +1,29 @@ #include +#include + +#define SDA_PIN 21 +#define SCL_PIN 22 + +#define SLAVE_ADDRESS 0x08 + +void requestEvent(); void setup() { Serial.begin(115200); + + Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins + + Wire.onRequest(requestEvent); } void loop() { } + +void requestEvent() +{ + // TODO: Send data to the master when requested + Serial.println("Master requested data from Slave."); + Wire.write("Hello from Slave!"); +} \ No newline at end of file diff --git a/APL_Slave_2/README.md b/APL_Slave_2/README.md index 20462a5..cdb1853 100644 --- a/APL_Slave_2/README.md +++ b/APL_Slave_2/README.md @@ -1 +1,8 @@ -# Architektoniczne perełki Lublina - Slave 2 \ No newline at end of file +# Architektoniczne perełki Lublina - Slave 2 + +## I2C +Pins: + - SDA -> 21 + - SCL -> 22 + +Address: 0x09 \ No newline at end of file diff --git a/APL_Slave_2/src/main.cpp b/APL_Slave_2/src/main.cpp index 37a1561..9c79bed 100644 --- a/APL_Slave_2/src/main.cpp +++ b/APL_Slave_2/src/main.cpp @@ -1,11 +1,29 @@ #include +#include + +#define SDA_PIN 21 +#define SCL_PIN 22 + +#define SLAVE_ADDRESS 0x09 + +void requestEvent(); void setup() { Serial.begin(115200); + + Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins + + Wire.onRequest(requestEvent); } void loop() { - // put your main code here, to run repeatedly: } + +void requestEvent() +{ + // TODO: Send data to the master when requested + Serial.println("Master requested data from Slave."); + Wire.write("Hello from Slave!"); +} \ No newline at end of file diff --git a/APL_Slave_3/README.md b/APL_Slave_3/README.md index b88f3af..ca39350 100644 --- a/APL_Slave_3/README.md +++ b/APL_Slave_3/README.md @@ -1 +1,8 @@ -# Architektoniczne perełki Lublina - Slave 3 \ No newline at end of file +# Architektoniczne perełki Lublina - Slave 3 + +## I2C +Pins: + - SDA -> 21 + - SCL -> 22 + +Address: 0x0A \ No newline at end of file diff --git a/APL_Slave_3/src/main.cpp b/APL_Slave_3/src/main.cpp index f76fc99..510f019 100644 --- a/APL_Slave_3/src/main.cpp +++ b/APL_Slave_3/src/main.cpp @@ -1,11 +1,29 @@ #include +#include + +#define SDA_PIN 21 +#define SCL_PIN 22 + +#define SLAVE_ADDRESS 0x0A + +void requestEvent(); void setup() { Serial.begin(115200); + + Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins + + Wire.onRequest(requestEvent); } void loop() { - // put your main code here, to run repeatedly: +} + +void requestEvent() +{ + // TODO: Send data to the master when requested + Serial.println("Master requested data from Slave."); + Wire.write("Hello from Slave!"); } \ No newline at end of file diff --git a/APL_Slave_4/README.md b/APL_Slave_4/README.md index a90f8e7..8fd5c9b 100644 --- a/APL_Slave_4/README.md +++ b/APL_Slave_4/README.md @@ -1 +1,8 @@ -# Architektoniczne perełki Lublina - Slave 4 \ No newline at end of file +# Architektoniczne perełki Lublina - Slave 4 + +## I2C +Pins: + - SDA -> 21 + - SCL -> 22 + +Address: 0x0B \ No newline at end of file diff --git a/APL_Slave_4/src/main.cpp b/APL_Slave_4/src/main.cpp index b1cef02..b2b60bf 100644 --- a/APL_Slave_4/src/main.cpp +++ b/APL_Slave_4/src/main.cpp @@ -1,10 +1,29 @@ #include +#include + +#define SDA_PIN 21 +#define SCL_PIN 22 + +#define SLAVE_ADDRESS 0x0B + +void requestEvent(); void setup() { Serial.begin(115200); + + Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins + + Wire.onRequest(requestEvent); } void loop() { } + +void requestEvent() +{ + // TODO: Send data to the master when requested + Serial.println("Master requested data from Slave."); + Wire.write("Hello from Slave!"); +} \ No newline at end of file diff --git a/APL_Slave_5/README.md b/APL_Slave_5/README.md index 44d036d..2299fc1 100644 --- a/APL_Slave_5/README.md +++ b/APL_Slave_5/README.md @@ -1 +1,8 @@ -# Architektoniczne perełki Lublina - Slave 5 \ No newline at end of file +# Architektoniczne perełki Lublina - Slave 5 + +## I2C +Pins: + - SDA -> 21 + - SCL -> 22 + +Address: 0x0C \ No newline at end of file diff --git a/APL_Slave_5/src/main.cpp b/APL_Slave_5/src/main.cpp index b1cef02..ef13d54 100644 --- a/APL_Slave_5/src/main.cpp +++ b/APL_Slave_5/src/main.cpp @@ -1,10 +1,29 @@ #include +#include + +#define SDA_PIN 21 +#define SCL_PIN 22 + +#define SLAVE_ADDRESS 0x0C + +void requestEvent(); void setup() { Serial.begin(115200); + + Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins + + Wire.onRequest(requestEvent); } void loop() { } + +void requestEvent() +{ + // TODO: Send data to the master when requested + Serial.println("Master requested data from Slave."); + Wire.write("Hello from Slave!"); +} \ No newline at end of file -- 2.54.0 From a3cfa44d82b6132c61223da0a8b908e789fa9a29 Mon Sep 17 00:00:00 2001 From: SWETRAK Date: Fri, 3 Jul 2026 23:50:58 +0200 Subject: [PATCH 3/7] feat: implemented simple logic to detect cards and send information to master via I2C --- APL_Master/README.md | 9 ++- APL_Master/src/main.cpp | 3 + APL_Slave_1/platformio.ini | 4 +- APL_Slave_1/src/main.cpp | 115 ++++++++++++++++++++++++++++++++++++- APL_Slave_2/platformio.ini | 4 +- APL_Slave_3/platformio.ini | 4 +- APL_Slave_4/platformio.ini | 4 +- APL_Slave_5/platformio.ini | 4 +- 8 files changed, 138 insertions(+), 9 deletions(-) diff --git a/APL_Master/README.md b/APL_Master/README.md index 66ab445..759e39a 100644 --- a/APL_Master/README.md +++ b/APL_Master/README.md @@ -10,4 +10,11 @@ Addresses: - Slave 2 -> `0x09` - Slave 3 -> `0x0A` - Slave 4 -> `0x0B` - - Slave 5 -> `0x0C` \ No newline at end of file + - Slave 5 -> `0x0C` + +# LED config + +Led Type: WS2812B +Pin: 5 +Count: 29 +Color Order: GRB diff --git a/APL_Master/src/main.cpp b/APL_Master/src/main.cpp index 9feee3d..3ff2a1f 100644 --- a/APL_Master/src/main.cpp +++ b/APL_Master/src/main.cpp @@ -38,6 +38,9 @@ void setup() void loop() { // put your main code here, to run repeatedly: + // TODO: Implement the main loop logic for I2C communication with slave devices + // TODO: Implement the logic to control the LED strip based on the received data from slave devices + // TODO: Send informations to PC via Serial communication, needs to be implemented based on the previous code snippets. } void testLedStrip() diff --git a/APL_Slave_1/platformio.ini b/APL_Slave_1/platformio.ini index 7d842a1..2283aef 100644 --- a/APL_Slave_1/platformio.ini +++ b/APL_Slave_1/platformio.ini @@ -13,4 +13,6 @@ platform = espressif32 board = esp32dev framework = arduino -monitor_speed = 115200 \ No newline at end of file +monitor_speed = 115200 + +lib_deps = miguelbalboa/MFRC522@^1.4.12 diff --git a/APL_Slave_1/src/main.cpp b/APL_Slave_1/src/main.cpp index 895c624..cadbf52 100644 --- a/APL_Slave_1/src/main.cpp +++ b/APL_Slave_1/src/main.cpp @@ -1,13 +1,64 @@ #include #include +#include #define SDA_PIN 21 #define SCL_PIN 22 #define SLAVE_ADDRESS 0x08 +// Card reader pins +#define READER_COUNT 6 + +#define RST_PIN 9 + +#define SS_ONE_PIN 10 +#define SS_TWO_PIN 5 +#define SS_THREE_PIN 4 +#define SS_FOUR_PIN 2 +#define SS_FIVE_PIN 15 +#define SS_SIX_PIN 13 + +// Card status definitions +#define CARD_NOT_DETECTED 0 +#define CARD_OK 1 +#define CARD_WRONG 2 + +// Slave select pins for each reader +const byte SS_PINS[READER_COUNT] = {SS_ONE_PIN, SS_TWO_PIN, SS_THREE_PIN, SS_FOUR_PIN, SS_FIVE_PIN, SS_SIX_PIN}; + +// I2C addresses for each reader +// TODO: Update the addresses to specific setup +const byte READER_ADDRESSES[READER_COUNT] = { + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; + +// List of proper cards uuid's +const byte CORRECT_UIDS[READER_COUNT][4] = { + {0xDE, 0xAD, 0xBE, 0xEF}, // Reader 1 + {0xCA, 0xFE, 0xBA, 0xBE}, // Reader 2 + {0xFA, 0xCE, 0xB0, 0x0C}, // Reader 3 + {0xBA, 0xAD, 0xF0, 0x0D}, // Reader 4 + {0xFE, 0xED, 0xFA, 0xCE}, // Reader 5 + {0xC0, 0xFF, 0xEE, 0x00} // Reader 6 +}; + +// Reader statuses: 0 - not detected, 1 - okey, 2 - wrong card +volatile byte readerStatus[READER_COUNT] = { + CARD_NOT_DETECTED, + CARD_NOT_DETECTED, + CARD_NOT_DETECTED, + CARD_NOT_DETECTED, + CARD_NOT_DETECTED, + CARD_NOT_DETECTED}; + +MFRC522 mfrc522[READER_COUNT]; // Create MFRC522 instances for each reader + void requestEvent(); +void initializeReaders(); + +bool compareUID(byte *readUID, const byte *correctUID, byte size); + void setup() { Serial.begin(115200); @@ -15,15 +66,73 @@ void setup() Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins Wire.onRequest(requestEvent); + + initializeReaders(); } void loop() { + for (byte i = 0; i < READER_COUNT; i++) + { + if (!mfrc522[i].PICC_IsNewCardPresent() || !mfrc522[i].PICC_ReadCardSerial()) + { + MFRC522::StatusCode buffer_status; + byte buffer_atqa[2]; + byte buffer_size = sizeof(buffer_atqa); + + buffer_status = mfrc522[i].PICC_WakeupA(buffer_atqa, &buffer_size); + + if (buffer_status != MFRC522::STATUS_OK) + { + readerStatus[i] = CARD_NOT_DETECTED; + } + continue; + } + + if (compareUID(mfrc522[i].uid.uidByte, CORRECT_UIDS[i], mfrc522[i].uid.size)) + { + readerStatus[i] = CARD_OK; + } + else + { + readerStatus[i] = CARD_WRONG; + } + + mfrc522[i].PICC_HaltA(); + mfrc522[i].PCD_StopCrypto1(); + } + + delay(50); +} + +void initializeReaders() +{ + for (byte i = 0; i < READER_COUNT; i++) + { + mfrc522[i].PCD_Init(SS_PINS[i], RST_PIN); + } +} + +bool compareUID(byte *readUID, const byte *correctUID, byte size) +{ + for (byte i = 0; i < size; i++) + { + if (readUID[i] != correctUID[i]) + { + return false; + } + } + return true; } void requestEvent() { - // TODO: Send data to the master when requested - Serial.println("Master requested data from Slave."); - Wire.write("Hello from Slave!"); + byte outputData[READER_COUNT]; + + for (byte i = 0; i < READER_COUNT; i++) + { + outputData[i] = READER_ADDRESSES[i] + readerStatus[i]; + } + + Wire.write(outputData, READER_COUNT); } \ No newline at end of file diff --git a/APL_Slave_2/platformio.ini b/APL_Slave_2/platformio.ini index 7d842a1..2f6d349 100644 --- a/APL_Slave_2/platformio.ini +++ b/APL_Slave_2/platformio.ini @@ -13,4 +13,6 @@ platform = espressif32 board = esp32dev framework = arduino -monitor_speed = 115200 \ No newline at end of file +monitor_speed = 115200 + +lib_deps = miguelbalboa/MFRC522@^1.4.12 \ No newline at end of file diff --git a/APL_Slave_3/platformio.ini b/APL_Slave_3/platformio.ini index 7d842a1..2f6d349 100644 --- a/APL_Slave_3/platformio.ini +++ b/APL_Slave_3/platformio.ini @@ -13,4 +13,6 @@ platform = espressif32 board = esp32dev framework = arduino -monitor_speed = 115200 \ No newline at end of file +monitor_speed = 115200 + +lib_deps = miguelbalboa/MFRC522@^1.4.12 \ No newline at end of file diff --git a/APL_Slave_4/platformio.ini b/APL_Slave_4/platformio.ini index 7d842a1..2f6d349 100644 --- a/APL_Slave_4/platformio.ini +++ b/APL_Slave_4/platformio.ini @@ -13,4 +13,6 @@ platform = espressif32 board = esp32dev framework = arduino -monitor_speed = 115200 \ No newline at end of file +monitor_speed = 115200 + +lib_deps = miguelbalboa/MFRC522@^1.4.12 \ No newline at end of file diff --git a/APL_Slave_5/platformio.ini b/APL_Slave_5/platformio.ini index 7d842a1..2f6d349 100644 --- a/APL_Slave_5/platformio.ini +++ b/APL_Slave_5/platformio.ini @@ -13,4 +13,6 @@ platform = espressif32 board = esp32dev framework = arduino -monitor_speed = 115200 \ No newline at end of file +monitor_speed = 115200 + +lib_deps = miguelbalboa/MFRC522@^1.4.12 \ No newline at end of file -- 2.54.0 From f7572e82ea281fbdb32b41537d5393550dbf536d Mon Sep 17 00:00:00 2001 From: SWETRAK Date: Fri, 3 Jul 2026 23:59:58 +0200 Subject: [PATCH 4/7] feat: added proper config for SPI config --- APL_Slave_1/src/main.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/APL_Slave_1/src/main.cpp b/APL_Slave_1/src/main.cpp index cadbf52..0183c1e 100644 --- a/APL_Slave_1/src/main.cpp +++ b/APL_Slave_1/src/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #define SDA_PIN 21 #define SCL_PIN 22 @@ -10,9 +11,13 @@ // Card reader pins #define READER_COUNT 6 -#define RST_PIN 9 +#define MISO_PIN 19 +#define MOSI_PIN 23 +#define SCK_PIN 18 -#define SS_ONE_PIN 10 +#define RST_PIN 27 + +#define SS_ONE_PIN 26 #define SS_TWO_PIN 5 #define SS_THREE_PIN 4 #define SS_FOUR_PIN 2 @@ -33,6 +38,7 @@ const byte READER_ADDRESSES[READER_COUNT] = { 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; // List of proper cards uuid's +// TODO: Update this UUID's to the specific cards that will be used const byte CORRECT_UIDS[READER_COUNT][4] = { {0xDE, 0xAD, 0xBE, 0xEF}, // Reader 1 {0xCA, 0xFE, 0xBA, 0xBE}, // Reader 2 @@ -67,6 +73,9 @@ void setup() Wire.onRequest(requestEvent); + // Initialize SPI with specified pins + SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, -1); + initializeReaders(); } -- 2.54.0 From 8f84e04f0bad5e1c64e7c5db5da56c3287c01b3a Mon Sep 17 00:00:00 2001 From: SWETRAK Date: Sat, 4 Jul 2026 10:11:18 +0200 Subject: [PATCH 5/7] feat: added initial support for user buttons --- APL_Master/src/main.cpp | 101 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/APL_Master/src/main.cpp b/APL_Master/src/main.cpp index 3ff2a1f..f7bb204 100644 --- a/APL_Master/src/main.cpp +++ b/APL_Master/src/main.cpp @@ -11,6 +11,18 @@ #define SLAVE_FOUR_ADDRESS 0x0B #define SLAVE_FIVE_ADDRESS 0x0C +// Buttons pins +#define PLAYER_ONE_BUTTON_PIN 32 +#define PLAYER_ONE_A_BUTTON_PIN 33 +#define PLAYER_ONE_B_BUTTON_PIN 25 +#define PLAYER_ONE_C_BUTTON_PIN 26 + +#define PLAYER_TWO_BUTTON_PIN 27 +#define PLAYER_TWO_A_BUTTON_PIN 14 +#define PLAYER_TWO_B_BUTTON_PIN 12 +#define PLAYER_TWO_C_BUTTON_PIN 13 + +// LEDs pins and configuration #define LED_DATA_PIN 5 #define LED_COUNT 29 #define BRIGHTNESS 64 @@ -24,6 +36,18 @@ const CRGB ERROR_COLOR = CRGB::Red; void testLedStrip(); +void initializeButtonInterrupts(); + +void playerOneButtonPressedInterrupt(); +void playerOneAButtonPressedInterrupt(); +void playerOneBButtonPressedInterrupt(); +void playerOneCButtonPressedInterrupt(); + +void playerTwoButtonPressedInterrupt(); +void playerTwoAButtonPressedInterrupt(); +void playerTwoBButtonPressedInterrupt(); +void playerTwoCButtonPressedInterrupt(); + void setup() { Wire.begin(SDA_PIN, SCL_PIN); @@ -32,6 +56,10 @@ void setup() // Initialize FastLED with the specified LED type, data pin, and LED count FastLED.addLeds(leds, LED_COUNT).setCorrection(TypicalLEDStrip); FastLED.setBrightness(BRIGHTNESS); + + // Initialize button interrupts + initializeButtonInterrupts(); + testLedStrip(); } @@ -53,4 +81,75 @@ void testLedStrip() delay(100); // Wait for a short duration leds[i] = CRGB::Black; // Turn off the LED } -} \ No newline at end of file +} + +void initializeButtonInterrupts() +{ + pinMode(PLAYER_ONE_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_ONE_A_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_ONE_B_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_ONE_C_BUTTON_PIN, INPUT_PULLUP); + + pinMode(PLAYER_TWO_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_TWO_A_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_TWO_B_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_TWO_C_BUTTON_PIN, INPUT_PULLUP); + + attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_BUTTON_PIN), playerOneButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_A_BUTTON_PIN), playerOneAButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_B_BUTTON_PIN), playerOneBButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_C_BUTTON_PIN), playerOneCButtonPressedInterrupt, FALLING); + + attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_BUTTON_PIN), playerTwoButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_A_BUTTON_PIN), playerTwoAButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_B_BUTTON_PIN), playerTwoBButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_C_BUTTON_PIN), playerTwoCButtonPressedInterrupt, FALLING); +} + +void playerOneButtonPressedInterrupt() +{ + // Handle Player One button press interrupt + Serial.println("Player One button pressed"); +} + +void playerOneAButtonPressedInterrupt() +{ + // Handle Player One A button press interrupt + Serial.println("Player One A button pressed"); +} + +void playerOneBButtonPressedInterrupt() +{ + // Handle Player One B button press interrupt + Serial.println("Player One B button pressed"); +} + +void playerOneCButtonPressedInterrupt() +{ + // Handle Player One C button press interrupt + Serial.println("Player One C button pressed"); +} + +void playerTwoButtonPressedInterrupt() +{ + // Handle Player Two button press interrupt + Serial.println("Player Two button pressed"); +} + +void playerTwoAButtonPressedInterrupt() +{ + // Handle Player Two A button press interrupt + Serial.println("Player Two A button pressed"); +} + +void playerTwoBButtonPressedInterrupt() +{ + // Handle Player Two B button press interrupt + Serial.println("Player Two B button pressed"); +} + +void playerTwoCButtonPressedInterrupt() +{ + // Handle Player Two C button press interrupt + Serial.println("Player Two C button pressed"); +} -- 2.54.0 From 535ecc84f259bcaab1bc26e21942843938a165bd Mon Sep 17 00:00:00 2001 From: SWETRAK Date: Mon, 6 Jul 2026 22:09:46 +0200 Subject: [PATCH 6/7] feat: added vs-code workspace --- APL_PlatformIO.code-workspace | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 APL_PlatformIO.code-workspace diff --git a/APL_PlatformIO.code-workspace b/APL_PlatformIO.code-workspace new file mode 100644 index 0000000..e324da6 --- /dev/null +++ b/APL_PlatformIO.code-workspace @@ -0,0 +1,28 @@ +{ + "folders": [ + { + "path": "APL_Master" + }, + { + "name": "APL_Slave_1", + "path": "APL_Slave_1" + }, + { + "name": "APL_Slave_2", + "path": "APL_Slave_2" + }, + { + "name": "APL_Slave_3", + "path": "APL_Slave_3" + }, + { + "name": "APL_Slave_4", + "path": "APL_Slave_4" + }, + { + "name": "APL_Slave_5", + "path": "APL_Slave_5" + } +], + "settings": {} +} -- 2.54.0 From 0a34467ccbe7f07154ff9b822e7abd52b88e1273 Mon Sep 17 00:00:00 2001 From: SWETRAK Date: Fri, 10 Jul 2026 16:12:47 +0200 Subject: [PATCH 7/7] feat: fixed some pins, added RESET pins for each device --- APL_Master/lib/Conts/Conts.h | 28 +++++++++++ APL_Master/src/main.cpp | 28 +---------- APL_Slave_1/src/main.cpp | 96 +++++++++++++++++++++++------------- 3 files changed, 92 insertions(+), 60 deletions(-) create mode 100644 APL_Master/lib/Conts/Conts.h diff --git a/APL_Master/lib/Conts/Conts.h b/APL_Master/lib/Conts/Conts.h new file mode 100644 index 0000000..dda76d2 --- /dev/null +++ b/APL_Master/lib/Conts/Conts.h @@ -0,0 +1,28 @@ +// I2C pins +#define SDA_PIN 21 +#define SCL_PIN 22 + +// I2C slave addresses +#define SLAVE_ONE_ADDRESS 0x08 +#define SLAVE_TWO_ADDRESS 0x09 +#define SLAVE_THREE_ADDRESS 0x0A +#define SLAVE_FOUR_ADDRESS 0x0B +#define SLAVE_FIVE_ADDRESS 0x0C + +// Buttons pins +#define PLAYER_ONE_BUTTON_PIN 32 +#define PLAYER_ONE_A_BUTTON_PIN 33 +#define PLAYER_ONE_B_BUTTON_PIN 25 +#define PLAYER_ONE_C_BUTTON_PIN 26 + +#define PLAYER_TWO_BUTTON_PIN 27 +#define PLAYER_TWO_A_BUTTON_PIN 14 +#define PLAYER_TWO_B_BUTTON_PIN 12 +#define PLAYER_TWO_C_BUTTON_PIN 13 + +// LEDs pins and configuration +#define LED_DATA_PIN 5 +#define LED_COUNT 29 +#define BRIGHTNESS 64 +#define LED_TYPE WS2812B +#define COLOR_ORDER GRB \ No newline at end of file diff --git a/APL_Master/src/main.cpp b/APL_Master/src/main.cpp index f7bb204..b197db0 100644 --- a/APL_Master/src/main.cpp +++ b/APL_Master/src/main.cpp @@ -1,33 +1,7 @@ #include #include #include - -#define SDA_PIN 21 -#define SCL_PIN 22 - -#define SLAVE_ONE_ADDRESS 0x08 -#define SLAVE_TWO_ADDRESS 0x09 -#define SLAVE_THREE_ADDRESS 0x0A -#define SLAVE_FOUR_ADDRESS 0x0B -#define SLAVE_FIVE_ADDRESS 0x0C - -// Buttons pins -#define PLAYER_ONE_BUTTON_PIN 32 -#define PLAYER_ONE_A_BUTTON_PIN 33 -#define PLAYER_ONE_B_BUTTON_PIN 25 -#define PLAYER_ONE_C_BUTTON_PIN 26 - -#define PLAYER_TWO_BUTTON_PIN 27 -#define PLAYER_TWO_A_BUTTON_PIN 14 -#define PLAYER_TWO_B_BUTTON_PIN 12 -#define PLAYER_TWO_C_BUTTON_PIN 13 - -// LEDs pins and configuration -#define LED_DATA_PIN 5 -#define LED_COUNT 29 -#define BRIGHTNESS 64 -#define LED_TYPE WS2812B -#define COLOR_ORDER GRB +#include CRGB leds[LED_COUNT]; diff --git a/APL_Slave_1/src/main.cpp b/APL_Slave_1/src/main.cpp index 0183c1e..c874e11 100644 --- a/APL_Slave_1/src/main.cpp +++ b/APL_Slave_1/src/main.cpp @@ -3,42 +3,50 @@ #include #include +// I2C Pin definitions for ESP32 #define SDA_PIN 21 #define SCL_PIN 22 #define SLAVE_ADDRESS 0x08 -// Card reader pins +// Count of MFRC522 readers connected to the ESP32 #define READER_COUNT 6 +// SPI pins for MFRC522 readers #define MISO_PIN 19 #define MOSI_PIN 23 #define SCK_PIN 18 -#define RST_PIN 27 - -#define SS_ONE_PIN 26 -#define SS_TWO_PIN 5 +// Dedicated Slave Select (SS) pins for each reader +#define SS_ONE_PIN 14 +#define SS_TWO_PIN 32 #define SS_THREE_PIN 4 -#define SS_FOUR_PIN 2 -#define SS_FIVE_PIN 15 -#define SS_SIX_PIN 13 +#define SS_FOUR_PIN 33 +#define SS_FIVE_PIN 25 +#define SS_SIX_PIN 26 -// Card status definitions +// Dedicated reset pins for each reader +#define RST_ONE_PIN 27 +#define RST_TWO_PIN 13 +#define RST_THREE_PIN 2 +#define RST_FOUR_PIN 15 +#define RST_FIVE_PIN 12 +#define RST_SIX_PIN 17 + +// Definitions for card statuses #define CARD_NOT_DETECTED 0 #define CARD_OK 1 #define CARD_WRONG 2 -// Slave select pins for each reader +// Arrays for SS and RST pins for each reader const byte SS_PINS[READER_COUNT] = {SS_ONE_PIN, SS_TWO_PIN, SS_THREE_PIN, SS_FOUR_PIN, SS_FIVE_PIN, SS_SIX_PIN}; +const byte RST_PINS[READER_COUNT] = {RST_ONE_PIN, RST_TWO_PIN, RST_THREE_PIN, RST_FOUR_PIN, RST_FIVE_PIN, RST_SIX_PIN}; -// I2C addresses for each reader -// TODO: Update the addresses to specific setup +// Addresses for each reader (for I2C communication) const byte READER_ADDRESSES[READER_COUNT] = { 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; -// List of proper cards uuid's -// TODO: Update this UUID's to the specific cards that will be used +// List of correct UIDs for each reader (4 bytes each) const byte CORRECT_UIDS[READER_COUNT][4] = { {0xDE, 0xAD, 0xBE, 0xEF}, // Reader 1 {0xCA, 0xFE, 0xBA, 0xBE}, // Reader 2 @@ -48,7 +56,7 @@ const byte CORRECT_UIDS[READER_COUNT][4] = { {0xC0, 0xFF, 0xEE, 0x00} // Reader 6 }; -// Reader statuses: 0 - not detected, 1 - okey, 2 - wrong card +// Reader statuses: 0 - card not detected, 1 - OK, 2 - wrong card volatile byte readerStatus[READER_COUNT] = { CARD_NOT_DETECTED, CARD_NOT_DETECTED, @@ -57,47 +65,57 @@ volatile byte readerStatus[READER_COUNT] = { CARD_NOT_DETECTED, CARD_NOT_DETECTED}; -MFRC522 mfrc522[READER_COUNT]; // Create MFRC522 instances for each reader +MFRC522 mfrc522[READER_COUNT]; void requestEvent(); - void initializeReaders(); - bool compareUID(byte *readUID, const byte *correctUID, byte size); void setup() { Serial.begin(115200); + delay(1000); // Daj czas na zainicjalizowanie portu USB w komputerze + Serial.println("Starting ESP32..."); - Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins - + Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); Wire.onRequest(requestEvent); - // Initialize SPI with specified pins SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, -1); + Serial.println("SPI initialized successfully."); + + // SPI.setFrequency(1000000); // Set 1 MHz for whole SPI bus, but MFRC522 can handle up to 10 MHz. Adjust as needed. + // Serial.println("SPI set to 1 MHz"); initializeReaders(); + Serial.println("System initialized successfully. Waiting for card detection..."); } void loop() { for (byte i = 0; i < READER_COUNT; i++) { + // Check if a new card is present and read its UID if (!mfrc522[i].PICC_IsNewCardPresent() || !mfrc522[i].PICC_ReadCardSerial()) { - MFRC522::StatusCode buffer_status; - byte buffer_atqa[2]; - byte buffer_size = sizeof(buffer_atqa); - - buffer_status = mfrc522[i].PICC_WakeupA(buffer_atqa, &buffer_size); - - if (buffer_status != MFRC522::STATUS_OK) - { - readerStatus[i] = CARD_NOT_DETECTED; - } + readerStatus[i] = CARD_NOT_DETECTED; // Reset reader status if no card is present continue; } + // Card is detected, print its UID + Serial.print("Reader "); + Serial.print(i + 1); + Serial.print(" detected card with UID: "); + for (byte j = 0; j < mfrc522[i].uid.size; j++) + { + Serial.print(mfrc522[i].uid.uidByte[j], HEX); + if (j < mfrc522[i].uid.size - 1) + { + Serial.print(":"); + } + } + Serial.println(); + + // Check if the read UID matches the correct UID for this reader if (compareUID(mfrc522[i].uid.uidByte, CORRECT_UIDS[i], mfrc522[i].uid.size)) { readerStatus[i] = CARD_OK; @@ -107,18 +125,30 @@ void loop() readerStatus[i] = CARD_WRONG; } + // Close communication with the card and stop encryption on PCD mfrc522[i].PICC_HaltA(); mfrc522[i].PCD_StopCrypto1(); } - delay(50); + delay(100); } void initializeReaders() { for (byte i = 0; i < READER_COUNT; i++) { - mfrc522[i].PCD_Init(SS_PINS[i], RST_PIN); + pinMode(SS_PINS[i], OUTPUT); + digitalWrite(SS_PINS[i], HIGH); + + // Usage of the constructor with both SS and RST pins + mfrc522[i].PCD_Init(SS_PINS[i], RST_PINS[i]); + + Serial.print("Reader "); + Serial.print(i + 1); + Serial.print(" firmware version: "); + mfrc522[i].PCD_DumpVersionToSerial(); + + delay(100); } } -- 2.54.0