amc:ss2024:chicken_check:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
amc:ss2024:chicken_check:start [2024/07/14 14:03] – [NXP PN5180] rolf.becker | amc:ss2024:chicken_check:start [2024/07/31 15:20] (current) – [Chicken Check] rolf.becker | ||
---|---|---|---|
Line 1: | Line 1: | ||
~~NOTOC~~ | ~~NOTOC~~ | ||
+ | Group T: Jirad Al Massri (32323), Nour-Hamed-Raafat Hamed (31348) and Tarik Aydin (26751) | ||
====== Chicken Check ====== | ====== Chicken Check ====== | ||
- | <WRAP center round todo 60%> | + | **[[.: |
- | \\ | + | |
- | **Write your documentation here!** | + | |
- | </ | + | |
- | ===== First Draft Ideas ===== | + | =====1. Introduction===== |
+ | Written by Nour-Hamed-Raafat Hamed | ||
- | * RFID bird ringing, bird banding, tagging | + | In monitoring chickens there’s a lot of different parameters are measured to gain insight on chicken movement and behaviour and a more complex objective of monitoring health indicators like feeding and nesting habits. Where are the chicken? In the chicken coop? Sitting on the nest? Breeding? Outside? |
- | * 13.56 MHz HF band (not LF nor UHF) | + | |
- | * https:// | + | |
- | ===== About RFID ==== | + | Not only monitoring the chickens but also to track the long-term development of behaviour tracking for example it can help to register alarming trends and changes early on such that appropriate actions can be taken. This makes chicken checker a topic of importance in sustainable farming |
+ | The Chicken Checker project uses Radio Frequency Identification (RFID) technology to monitor and track the activity of chickens on a farm as shown in figure 1. By connecting two antennas to a ESP32 and placing them at the start and end of the entrance of the chicken coop | ||
+ | Microcontrollers are a valuable tool for farm owners and agricultural industries as they are cheap, small in size and easy to set up and use. They offer a lot of possibilities to help maintain a sustainable farming environment like reading results and transmitting the data to database where it can be assessed. The aim of this project is to scheme and program a small monitoring station for a chicken coop and learn how such technology works and its upsides and downside and how to set it up. | ||
- | * https:// | + | <WRAP centeralign> |
- | * https:// | + | {{:amc: |
- | ===== HF RFID Technology (13.56 MHz) ===== | + | <WRAP em> Figure 1 scheme of hardware on the farm</ |
+ | </ | ||
- | * :!: Matt Rose and Jon Kurtz (2016): **{{: | + | =====2. Materials & Methods===== |
+ | Written by Tarik Aydin | ||
+ | ====For this project the following materials were used:==== | ||
- | ==== ISO 14443: Proximity Communication (typ. range: 7-15 cm) ==== | + | \\ |
+ | **1) PN532 Adafruit board**\\ | ||
+ | The PN532 Adafruit board operates on a 13.56MHz frequency and the PN532 chip is commonly used in phones which are able to do NFC. This board creates an electromagnetic field which can reach approximately up to 10cm range according to Adafruit [2], tested around | ||
- | | + | \\ |
- | - **Purpose**: | + | **2) NFC cards type ISO14443 tags**\\ |
- | - **Read Range**: ISO 14443 has a shorter | + | The NFC cards acted passing chickens, the card consist of a small chip which is connected to a wire which is curled inside a plastic card. The card is a read by passive induction which is caused by the electromagnetic field of the PN532 board. The card can store up to 1KiloByte of data and has an unique identifier integrated in to the chip. These type of chips are usually used in train or bus passes [3]. |
- | - **Data Transfer Rate**: It offers a higher | + | |
- | - **Applications**: | + | |
- | ==== ISO 15693: Vicinity Communication (typ. range: < 100 cm) ==== | + | \\ |
+ | **3) Esp32 S3 Dev Module**\\ | ||
+ | The Esp32 S3 Dev Module worked as the brain of this project, the microcontroller controls the two PN532 boards and also sends the data to the computer. The Esp32 S3 Dev Module also has built in Wi-Fi, Bluetooth and low power functions, these function enable to collect the data automated viva Wi-Fi or Bluetooth [4]. | ||
- | | + | \\ |
- | - **Read Range**: ISO 15693 provides an extended read range of **up to 1 meter** (approximately 3.3 feet). | + | **4) Jumper wires**\\ |
- | - **Data Transfer Rate**: It has a slower data rate with a **26 kbps** Baud rate. | + | Jumper wires connect |
- | - **Applications**: | + | |
- | In summary, ISO 14443 is ideal for short-range applications like wireless payments, while ISO 15693 suits scenarios where longer read distances are necessary. 📡🔍🏷️¹² | + | \\ |
+ | **5) Bread board**\\ | ||
+ | The bread board was used to as a base to connect all the parts together. | ||
- | Source: Conversation with Copilot, 30/06/2024 | + | \\ |
+ | **6) USB-A to USB 2.0 micro B cable**\\ | ||
+ | This cable was used a simple data transmission cable from the computers serial port to the Esp32 S3 Dev module to program the microcontroller and to execute the code written in Arduino [1]. | ||
- | (1) NFC Reader Guide - Shop NFC. https:// | ||
\\ | \\ | ||
- | (2) The difference between ISO15693 and ISO14443 - RFID Card. https:// | + | **7) Soldering Iron**\\ |
+ | The PN532 boards were delivered with lose pins, in order to secure the pins in the wanted place an soldering iron was used. | ||
\\ | \\ | ||
- | (3) Understanding the ISO15693 Protocol: An In-depth Look. https:// | + | **8) ChatGPT**\\ |
- | \\ | + | ChatGPT is an AI tool which is able to answer questions in a conversational way and allows answer follow up questions. ChatGPT enables for a faster development of the Arduino code to program the ESP32 microcontroller and the PN532 boards. But always be cautions with answer from ChatGPT, because answer can be sounding plausible which are incorrect [5]. |
- | (4) NFC Reader Guide - Shop NFC. https://www.shopnfc.com/ | + | |
+ | =====3. Results===== | ||
+ | Written by Tarik Aydin | ||
\\ | \\ | ||
- | (5) What is ISO/IEC 15693? RFID Communication Standard | + | ====The code used for this project:==== |
+ | <code lang=arduino> | ||
+ | #include <Wire.h> | ||
+ | #include <SPI.h> | ||
+ | #include < | ||
- | ==== Differences between ISO/IEC 15693-26 and ISO/IEC 15693-53 | + | // Define the slave select |
+ | #define PN532_SS1 5 | ||
+ | #define PN532_SS2 1 | ||
- | **ISO/IEC 15693-26**: | + | // Create PN532 SPI instances |
- | - **Modulation Scheme**: ISO/IEC 15693-26 uses a subcarrier frequency of 423.75 kHz. | + | Adafruit_PN532 nfc1(PN532_SS1); |
- | - **Data Rate**: The data rate for ISO/IEC 15693-26 is **26.48 kbps.** | + | Adafruit_PN532 nfc2(PN532_SS2); |
- | - **Application**: | + | |
- | - **Read Range**: The read range is typically up to 1 meter (approximately 3.3 feet). | + | |
- | **ISO/IEC 15693-53**: | + | struct UIDCounter { |
- | - **Modulation Scheme**: ISO/IEC 15693-53 uses a subcarrier frequency of 847.5 kHz. | + | |
- | - **Data Rate**: The data rate for ISO/IEC 15693-53 is **53.98 kbps.** | + | |
- | - **Application**: | + | |
- | - **Read Range**: Similar to ISO/IEC 15693-26, the read range is up to 1 meter. | + | }; |
- | In summary, both variants are part of the ISO/IEC 15693 standard | + | UIDCounter uidCounters1[10]; |
+ | UIDCounter uidCounters2[10]; | ||
- | Source: Conversation with Copilot, 30/06/2024 | + | void setup(void) { |
+ | Serial.begin(115200); | ||
+ | Serial.println(" | ||
- | ==== GAO RFID ==== | + | // Set up the SPI pins |
+ | SPI.begin(13, | ||
- | | + | // Initialize both PN532 modules |
- | | + | |
- | | + | |
- | * Separation: 300 tags at once | + | |
- | ==== NXP NFC Solutions ==== | + | // Check if PN532 modules are ready |
+ | uint32_t versiondata | ||
+ | if (!versiondata) { | ||
+ | Serial.println(" | ||
+ | while (1); | ||
+ | } | ||
- | | + | |
- | ==== NXP CLRC663 plus (CLRC66303HN) - High performance multi-protocol NFC frontend ==== | + | if (!versiondata) { |
+ | | ||
+ | while (1); | ||
+ | } | ||
- | **https://www.nxp.com/ | + | |
+ | nfc1.SAMConfig(); | ||
+ | nfc2.SAMConfig(); | ||
- | | {{https://www.nxp.com/ | + | |
- | | Source: **[[https:// | + | nfc1.setPassiveActivationRetries(0x00); |
+ | nfc2.setPassiveActivationRetries(0x00); | ||
+ | } | ||
- | | {{https:// | + | void loop(void) |
- | | Evaluation Board **CLEV6630B** (NXP) | Development Kit **OM26630FDKM** | + | uint8_t success1; |
+ | uint8_t uid1[7] = { 0 }; | ||
+ | uint8_t uidLength1; | ||
+ | uint8_t success2; | ||
+ | uint8_t uid2[7] = { 0 }; // Buffer to store the returned UID | ||
+ | uint8_t uidLength2; | ||
- | | + | // Activate the first PN532 module and read |
+ | nfc1.setPassiveActivationRetries(0x0A); | ||
+ | digitalWrite(PN532_SS1, | ||
+ | success1 = nfc1.readPassiveTargetID(PN532_MIFARE_ISO14443A, | ||
+ | digitalWrite(PN532_SS1, | ||
+ | nfc1.setPassiveActivationRetries(0x00); | ||
- | | + | |
- | * Eval Board Name: **CLEV6630B** | + | updateUIDCounter(uidCounters1, uid1, uidLength1); |
- | * Dev Kit Name: **OM26630FDKM** | + | |
+ | } | ||
+ | // Add a small delay to ensure the second board does not activate too soon | ||
+ | delay(50); | ||
- | | + | // Activate the second PN532 module and read |
- | | + | nfc2.setPassiveActivationRetries(0x0A); |
+ | digitalWrite(PN532_SS2, | ||
+ | success2 = nfc2.readPassiveTargetID(PN532_MIFARE_ISO14443A, | ||
+ | | ||
+ | nfc2.setPassiveActivationRetries(0x00); | ||
+ | if (success2) { | ||
+ | updateUIDCounter(uidCounters2, | ||
+ | printUIDs(uidCounters2, | ||
+ | } | ||
+ | // Add a delay to control the loop timing | ||
+ | | ||
+ | } | ||
+ | void updateUIDCounter(UIDCounter *uidCounters, | ||
+ | for (int i = 0; i < 10; i++) { | ||
+ | if (uidCounters[i].count == 0) { | ||
+ | // Empty slot, add new UID | ||
+ | memcpy(uidCounters[i].uid, | ||
+ | uidCounters[i].uidLength = uidLength; | ||
+ | uidCounters[i].count = 1; | ||
+ | return; | ||
+ | } else if (memcmp(uidCounters[i].uid, | ||
+ | // UID found, increment counter | ||
+ | uidCounters[i].count++; | ||
+ | return; | ||
+ | } | ||
+ | } | ||
+ | } | ||
- | | + | void printUIDs(UIDCounter |
- | | + | Serial.print(label); |
- | ==== NXP PN5180 | + | Serial.println(" |
+ | | ||
+ | if (uidCounters[i].count > 0) { | ||
+ | Serial.print(" | ||
+ | for (uint8_t j = 0; j < uidCounters[i].uidLength; j++) { | ||
+ | if (uidCounters[i].uid[j] <= 0xF) | ||
+ | Serial.print(" | ||
+ | Serial.print(uidCounters[i].uid[j], | ||
+ | if (j < uidCounters[i].uidLength | ||
+ | Serial.print(" | ||
+ | | ||
+ | Serial.print(" | ||
+ | Serial.println(uidCounters[i].count); | ||
+ | | ||
+ | } | ||
+ | Serial.println(" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===Explanation of the code:=== | ||
+ | - In the first part of the code the libraries and the chip select pins are defined. | ||
+ | - The libraries used are < | ||
+ | - The chip select pins are set at pin 5 for the first PN532 board and at pin 1 for the second PN532 board is set. | ||
+ | - The Adafruit_PN532 nfc function creates instances which define which pin has to be used for which board. Two PN532 boards were used in this project so two instances have to be created. This enables to distinguish the two boards. | ||
+ | - Then the struct UIDCounter is defined which enables to store read UIDs and also tracks how many times a specific UID has been read. | ||
+ | - The UIDCounter uidCounters1[10] and the UIDCounter uidCounters2[10] are storing for each board individually the UIDs detected for the corresponding board. | ||
+ | - The SPI pins are defined in the set up. | ||
+ | - Pin 13 is defined for the serial clock. | ||
+ | - Pin 12 is defined for MISO. | ||
+ | - Pin 11 is defined for MOSI. | ||
+ | - The nfc1.begin() and nfc2.begin() functions initializes the communication for the boards. | ||
+ | - The code uint32_t versiondata | ||
+ | - The functions nfc1.SAMConfig() and nfc2.SAMConfig() configures the board to use the Secure Access Module which enables to read RFID cards. | ||
+ | - The last functions nfc1.setPassiveActivationRetries(0x00) and nfc2.setPassiveActivationRetries(0x00) in the void set up turns the antenna of the PN532 boards off. | ||
+ | - The void loop contains variable storing functions success1, success2 as well as control of the two PN532 boards. As in 8. The function nfc.setPassiveActivationRetries() is used. Here in the beginning the function sets the PN532 board up to try ten times to read a nfc card. The digitalWrite(PN532_SS1, | ||
+ | - Small delay of 50ms is added to make sure that the second board starts bit later which ensures that the boards do not interfere with each other. Point nine is then done again just with changed variable names for the second board. | ||
- | | {{https:// | ||
- | | OM25180FDK Dev. Kit + Extras from [[https:// | ||
- | * :!: **[[https:// | + | ===Generation of the code:=== |
+ | The code used for the project was generated in a conversation with ChatGPT, small adaptations were made in the code. The AI added a delay which wasn’t necessary, as well as the delay of the second board was set a 100ms which would lead to interference of the two boards, because the first board tries ten times a second to read a card. The delay for the second board was changed to 50ms. | ||
- | * Chip Name: **PN5180B** (I_T(max) 250 mA) (PN5180A0HN??? | + | ===Results in the serial monitor in Arduino=== |
- | * Eval Board Name: **PNEV5180B** | + | In figure 2 the serial monitor is displayed. Here is shown that the boards each have an individual counter for the different UIDs and that the UIDs have an individual counter as well. This enables to see in which direction the chicken walks, because one of the boards will be placed before the exit/ |
- | * Dev Kit Name: **OM25180FDKM** (includes PNEV5180B) | + | |
+ | <WRAP centeralign> | ||
+ | {{: | ||
- | * NXP [[https:// | + | <WRAP em> Figure 2 Serial Monitor in Arduino</WRAP> |
- | * :!: Datasheet PN5180, **C3,C4** (Rev. 4.1, 2023-03-13): | + | </WRAP> |
- | * Datasheet PN5180, **C1,C2** (Rev. 3.6, 2018-05-07): | + | |
+ | ===Code that did not work for the project=== | ||
+ | \\ | ||
+ | The function nfc.readPassiveTargetID() is set as a standard to 0xFF [6], this means the function will run for ever. This is a problem when two PN532 boards are used, because in the void loop the function will be needed two times once for board one and once for board two. When the code is set up in the way that the first board comes first and the second board comes second, code will run in the sequence first board one and then board two. So, this allows only to start reading with the first boards and the code also will only read one signal at the time at one board. One way to avoid to be stuck in the sequence is to use the freeRTOS library, which will allow to create tasks in Arduino. In each task the function nfc.readPassiveTargetID() is used and still operates in the standard setting 0xFF. Here the two tasks will work in parallel, avoiding to sequence the nfc card. Using the freeRTOS library only solves the sequencing issue, the bigger issue here is then that the two boars will be permanently on. Which is causing electromagnetic interference. | ||
- | | {{https:// | + | =====4. Discussion===== |
- | | A cheap PN5180 board (R1.1-170710) for Arduino-like projects. | Schematic | + | Written |
+ | \\ | ||
- | === PN5180 Application Notes === | + | First challenge was the usage of I2C, where it uses 7-bit to 10-bit addresses to make the identification of devices on the bus, with many PN532 address conflict can increase because of the limited number of unique addresses. In addition, data collision and bus contention can increase in an environment with high communication traffic because I2C use the same set of wires (SDA and SCL) to the communication of multiple devices. Switching to SPI was the choice since SPI uses separate Chip select for each PN532 that eliminate address conflict, make device management more easy. Moreover, SPI enable a fast communication between the microcontroller and the PN532 because it has a higher data rate as well as it allows simultaneous data transmission and reception. The usage of SPI facilitate the addition of new PN532 to the system since its only require to identify a specific chip select line for every new PN532.\\ |
+ | Second challenge was the electromagnetic interference. When the PN532 where on, they were interfering with each other, causing a disruption in their operation. This interference created a dead spot in the detection area because both boards were not able to read data. Additionally, | ||
- | * {{https:// | + | =====5. Conclusion===== |
- | * {{https:// | + | Written by Jihad Al Massri and Nour-Hamed-Raafat Hamed |
+ | \\ | ||
- | * {{https://www.nxp.com/ | + | In this project, the initial use of I2C communication for PN532 NFC/RFID has faced a challenge, to distinguish between multiple boards. The switch to SPI communication has solved the issue by the usage separate chip select lines that made the communication more reliable and stable. Despite these improvements, |
- | * {{https:// | + | Because of the challenges we faced, a lot of insight was gained. |
- | * {{https:// | + | \\ |
- | * {{https:// | + | Technology Integration: Learned to combine ESP32 microcontrollers and PN532 with RFID tags technology for tracking. |
- | * {{https:// | + | \\ |
- | === PN5180 Arduino Libraries === | + | Understanding Antennas :\\ |
+ | Gained knowledge on how antennas work with RFID systems and UID detection. | ||
+ | \\ | ||
- | * https:// | + | UID detection:\\ |
- | * https://github.com/ | + | Gained knowledge on how NFC/RFID tags interacts with readers like the PN532. |
- | * https:// | + | \\ |
- | * https:// | + | |
- | ==== PN532 Module V3 by Elechouse (5V, red board) ==== | + | |
- | This is the cheap version (the red board with 8 + 4 pin headers / connectors) you still can buy everywhere. Drawback: Only the 5V is exposed to the connector and not the 3.3V output. The board has to be modified to be usable with a 3.3V voltage source, e.g. by desoldering the voltage regulator | + | System Design:\\ |
+ | | ||
+ | \\ | ||
- | * {{https://www.elechouse.com/ | + | I2C and SPI:\\ |
- | * [[https:// | + | I2C has a communication serial line to all antennas (sda scl), and for the SPI can distinguish between the antennas through chip select. |
+ | \\ | ||
- | | {{:amc: | + | Future work:\\ |
+ | Where to pick up this project? | ||
+ | The main focus should be on advanced method to reduce electromagnetic interference as this was the main challenge in our project , improve system flexibility where it can track multiple behaviors like chicken nesting habits and health tracking, and real world testing to apply the methods and then accordingly make changes in hardware or software. | ||
- | ==== Adafruit RFID/NFC PN532 Breakout | + | =====6. References===== |
+ | - https:// | ||
+ | - https:// | ||
+ | - https:// | ||
+ | - https:// | ||
+ | - https:// | ||
+ | - https:// | ||
- | [[.: | ||
- | ==== Other version of the red board (3.3V, 5V) ==== | ||
- | Wiki: http:// | ||
- | |||
- | {{: | ||
- | |||
- | Instructables: | ||
- | |||
- | {{https:// | ||
- | |||
- | {{http:// | ||
- | |||
- | ===== Terminology ===== | ||
- | |||
- | Bird ringing is the term used in the UK and in some other parts of Europe and the world. Bird banding is the term used in the US. Organised ringing efforts are called ringing or banding schemes, and the organisations that run them are ringing or banding authorities. (Birds are ringed rather than rung) Those who ring or band are known as ringers or banders, and they are typically active at ringing or banding stations. | ||
- | \\ | ||
- | [[https:// | ||
amc/ss2024/chicken_check/start.1720958607.txt.gz · Last modified: 2024/07/14 14:03 by rolf.becker