This shows you the differences between two versions of the page.
pm:prj2025:iivasciuc:marius.zaharia2305 [2025/05/17 23:05] marius.zaharia2305 [BankApp] |
pm:prj2025:iivasciuc:marius.zaharia2305 [2025/05/25 18:30] (current) marius.zaharia2305 [Results] |
||
---|---|---|---|
Line 2: | Line 2: | ||
//Designed by:// Marius-Tudor Zaharia, 333CA, May 2025 | //Designed by:// Marius-Tudor Zaharia, 333CA, May 2025 | ||
\\ //Contact:// marius.zaharia2305@stud.acs.upb.ro | \\ //Contact:// marius.zaharia2305@stud.acs.upb.ro | ||
- | \\ //GitHub repository:// [[https://github.com/tudorz23/BankProjectArduino|here]] | + | \\ [[https://github.com/tudorz23/BankProjectArduino|GitHub repository]] |
===== Introduction ===== | ===== Introduction ===== | ||
Line 99: | Line 99: | ||
===== Functionalities ===== | ===== Functionalities ===== | ||
==== State diagram ==== | ==== State diagram ==== | ||
+ | {{:pm:prj2025:iivasciuc:marius.zaharia2305:bankapp_state_diagram.png?800|}} | ||
* **Notes**: | * **Notes**: | ||
* The ''LOGOUT'' menu can be reached by pressing the ''red button'' from any menu of the ''LOGGED IN'' state (i.e. the yellow menus). | * The ''LOGOUT'' menu can be reached by pressing the ''red button'' from any menu of the ''LOGGED IN'' state (i.e. the yellow menus). | ||
Line 150: | Line 150: | ||
====Background and General details==== | ====Background and General details==== | ||
* The project was developed using the **PlatformIO** extension for VSCode. | * The project was developed using the **PlatformIO** extension for VSCode. | ||
- | * The following external libraries were used: | + | * The following **external libraries** were used: |
- | * ''LiquidCrystal_I2C'' - [[https://github.com/johnrickman/LiquidCrystal_I2C|GitHub]] | + | * ''Arduino.h'' - from PlatformIO |
+ | * Contains macro-definitions for Arduino pins and basic functions such as ''pinMode()'' or ''tone()''. | ||
+ | * ''LiquidCrystal_I2C.h'' - [[https://github.com/johnrickman/LiquidCrystal_I2C|GitHub]] | ||
* Used for interfacing the LCD, using the I2C protocol. Provides the ''LiquidCrystal_I2C'' class, which offers methods for initialization, cursor placing and writing characters. | * Used for interfacing the LCD, using the I2C protocol. Provides the ''LiquidCrystal_I2C'' class, which offers methods for initialization, cursor placing and writing characters. | ||
- | * ''MFRC522'' - [[https://github.com/miguelbalboa/rfid|GitHub]] | + | * ''MFRC522.h'' - [[https://github.com/miguelbalboa/rfid|GitHub]] |
* Used for interfacing the RFID card scanner, using the SPI protocol. Provides the ''MFRC522'' class, which offers methods for initialization, card detection and UID reading. | * Used for interfacing the RFID card scanner, using the SPI protocol. Provides the ''MFRC522'' class, which offers methods for initialization, card detection and UID reading. | ||
- | * ''TTP229'' - [[https://github.com/optimusdigital/ttp229-arduino|GitHub]] | + | * ''TTP229.h'' - [[https://github.com/optimusdigital/ttp229-arduino|GitHub]] |
* Used for interfacing the TTP229 capacitive keyboard. Provides the ''TTP229'' class, which offers a non-blocking method for key reading. | * Used for interfacing the TTP229 capacitive keyboard. Provides the ''TTP229'' class, which offers a non-blocking method for key reading. | ||
+ | * **Novelty elements** - a banking device that uses a joystick as primary navigation method, adding the fun element to the sobriety of a financial app. | ||
+ | * **Laboratories functionalities used** | ||
+ | * ''Lab 0 - GPIO'': The RGB LED is connected to 3 digital GPIO pins of the Arduino, which are set as output. | ||
+ | * ''Lab 2 - Interrupts'': The Watchdog Timer is programmed to generate an interrupt every second (to manage the interest gain times for the savings accounts). | ||
+ | * ''Lab 3 - PWM'': The passive buzzer is controlled using the ''tone()'' function, which uses PWM behind the scenes. | ||
+ | * ''Lab 4 - ADC'': The Arduino reads analog values from the Joystick - ''analogRead(JOYSTICK_VRX_PIN)''. | ||
+ | * ''Lab 5 - SPI'': The Arduino communicates by SPI with the RFID card scanner. | ||
+ | * ''Lab 6 - I2C'': The Arduino communicates by I2C with the LCD. | ||
- | ===== Results ===== | + | ====Implementation details==== |
+ | ===Modules=== | ||
+ | **pins** | ||
+ | * Contains the mappings between Arduino pins and peripheral components pins. | ||
+ | **sounds** | ||
+ | * Contains various sounds for the buzzer, used as audio feedback for the user after certain actions. | ||
+ | **lights** | ||
+ | * Contains multiple color schemes for the RGB LED, used as visual indicators of the menus the user is navigating. | ||
- | ===== Conclusions ===== | + | **wdt_counter** |
+ | * Controls the Watchdog Timer, by setting it up to generate an interrupt every second. | ||
+ | * It is used as a time-keeper for managing the interest gain of the savings accounts (every 15 seconds, interest is applied). | ||
+ | * It is preferred instead of Timer0/1/2, because these might be controlled by the ''millis()'' function, which is also used in the project. | ||
+ | * If, at a later time, another configuration of the WDT might be preferred (i.e. interrupt after a time interval), only this module is to be modified, without interfering with other sections that use timers. | ||
+ | * The source file contains a static variable (private to the file) that represents the counter, offering an init and a getter method for outside modules. | ||
+ | * The ISR is rather short and simple, by only incrementing the counter value. | ||
+ | * The live value of the counter can be observed in the debug menu. | ||
- | ===== Download ===== | + | **debounce** |
+ | * Offers methods for checking if the joystick is flicked to the right/left/up/down, if the joystick button is pressed and if the red button is pressed. | ||
+ | * In the source file, multiple static variables for debounce handling are used, which must not be accessible from the outside. | ||
+ | * For button debouncing, a generic function is implemented, which is used by specific functions for the two buttons. | ||
+ | * For joystick flicks checking, it is verified if a certain time has passed since the last registered flick, such that there is a delay in the menu navigation system (i.e. the menus do not fall through instantly). | ||
+ | **utils** | ||
+ | * Contains utility data structures, constants, global variables marked as ''extern'' and various helper functions. | ||
+ | * The ''User'' structure is declared here, containing the necessary information each user must posses. | ||
+ | * Functions for keyboard reading, user management, UID card reading and notification handling are specified here. | ||
+ | **menus** | ||
+ | * The enum class that encodes the menus and the functionality of each menu are described here. | ||
- | ===== Timeline ===== | + | **main** |
+ | * Initializes the global variables, the user database and all the peripheral devices. | ||
+ | * Contains the main loop, which presents the ''switch'' statement by which the current menu function is chosen | ||
+ | |||
+ | ===How it works=== | ||
+ | * The users are stored in a statically allocated array, each of them having a predefined name and UID. Initially, all of them are marked as not registered and have to go through the ''register'' menu to become active. | ||
+ | * The ''main loop'' is rather simple: at each iteration, it checks the value of the ''curr_menu'' global variable via a ''switch'' and launches the associated routine accordingly. Each such routine then displays its message and enters a ''while(true)'' loop, waiting for user input. | ||
+ | * The menus communicate with each other by altering the values of the global variables and of the static variables from the ''menus.cpp'' file. | ||
+ | * The goal was to develop a device as realistic and error-less as possible, so extreme cases are always considered, such that: the user is forced to enter a 4-digit PIN code (is not allowed to submit it until it has 4 digits and cannot input more than 4 digits), the user is always allowed to cancel his current action if he changes his mind, hypothetical error states are checked, sending the system to the ''ERROR'' menu if such a case occurs (i.e. if the current menu is the home page of a user, but there is no user logged in). | ||
+ | * ''enum class'' have been used for their own namespace feature and for their expressivity compared to numerical constants. | ||
+ | |||
+ | ===Correctness validation=== | ||
+ | * Each component was firstly tested alone to validate that the hardware was functional. | ||
+ | * The system as a whole was incrementally tested, after each new feature added. | ||
+ | |||
+ | ===Optimizations=== | ||
+ | * Because the maximum number of users is 6, their ''registered'' status was saved as a single 8-bit variable, using bitwise operations: user i is registered if the i-th bit (from the right) of the variable is 1. If each user had a boolean variable associated for this matter, 6 bytes would have been used in total, instead of 1. Thus, 5 bytes are saved. | ||
+ | * As the available RAM memory is limited, all the menu message strings were stored on the Flash rather than the RAM, via the ''F()'' macro. Also, variable types from ''<stdint.h>'' were used, for a better control. | ||
+ | * The notifications are encoded for memory efficiency: the ''Notification'' struct contains the type (''RecvFromFriend'', ''FriendReq'', ''ReqAccepted''), the index of the user who sent it and the sum of money sent (used when it is the case). | ||
+ | |||
+ | |||
+ | |||
+ | ===== Results ===== | ||
+ | * The final result is a fully functional, robust device, that encompasses all the proposed features in an intuitive and efficient way, both hardware and software wise. | ||
+ | * [[https://youtu.be/4Y1_n8hq_Kc|Demo on YouTube]] | ||
+ | |||
+ | |||
+ | |||
+ | ===== Conclusions ===== | ||
+ | * To sum up, this project achieved its goal of getting hands-on experience with embedded design, from wiring up the components all the way to writing efficient and functional software. | ||
+ | * For me, it was a fun experience with satisfactory results, which I will surely cherish in the future! | ||
===== Bibliography ===== | ===== Bibliography ===== | ||
+ | * [[https://randomnerdtutorials.com/security-access-using-mfrc522-rfid-reader-with-arduino/|MFRC522 setup]] | ||
+ | * [[https://arduinogetstarted.com/tutorials/arduino-joystick|Joystick setup]] | ||
+ | * [[https://forum.arduino.cc/t/configure-ttp229-capacitive-touch-keypad/1094055|TTP229 setup]] | ||
+ | * [[https://lastminuteengineers.com/i2c-lcd-arduino-tutorial/|LCD setup]] | ||
+ | * [[https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf|ATmega328P Datasheet]] | ||
+ | * [[https://docs.arduino.cc/built-in-examples/digital/Debounce/|Button debouncing]] | ||
+ | * [[https://forum.arduino.cc/t/watchdog-timer-interrupt-mode-related-question/1087738|Watchdog timer setup]] | ||
+ | * [[https://www.geeksforgeeks.org/enumeration-in-cpp/|C++ enum class]] | ||
<html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> |