Models flowcharts

  Our two models 



First model 



For the first model: Raspberry Pi communicates with ESP32 with UART we use small protocol to ensure that the data is valid,

 Steps of Communication:

  1. Initialize UART on Both Devices:
    • ESP32: Executes Serial.begin(115200) to configure UART0 (TX0/RX0) at a baud rate of 115200 bits per second (bps).
    • RPi4: Configures its UART interface (e.g., using pyserial in Python) to match the 115200 baud rate.
    • Hardware Setup: Connect ESP32’s TX pin to RPi4’s RX pin and ESP32’s RX pin to RPi4’s TX pin via GPIO pins. Ground pins are connected to ensure a common reference.
    • Purpose: Establishes a serial communication channel for bidirectional data transfer.
  2. ESP32 Requests Data:
    • The ESP32 initiates communication by sending a single request byte, 0xAA, using Serial.write(0xAA).
    • A 100ms delay (delay(100)) is introduced to allow the RPi4 sufficient time to prepare and send the response.
    • Purpose: Signals the RPi4 to transmit sensor data (e.g., distances and flags).
  3. RPi4 Sends Data Frame:
    • The RPi4 responds with an 8-byte frame containing:
      • Byte 1: Header (0xBB) to mark the start of a valid frame.
      • Bytes 2–5: Four distance values (e.g., from ultrasonic sensors).
      • Bytes 6–7: Two flag bytes (e.g., status indicators for safety features).
      • Byte 8: CRC byte for error checking.
    • Frame Format: [0xBB | Dist1 | Dist2 | Dist3 | Dist4 | Flag1 | Flag2 | CRC].
    • Purpose: Delivers structured sensor data to the ESP32.
  4. ESP32 Checks for Data Availability:
    • The ESP32 checks if at least 8 bytes are available in the serial buffer using Serial.available() >= 8.
    • If fewer than 8 bytes are present, the function returns false, indicating no valid data.
    • Purpose: Ensures the complete frame is received before processing.
  5. Validate Header:
    • The ESP32 reads the first byte using Serial.read() and verifies it equals 0xBB.
    • If the header is invalid (not 0xBB), the ESP32 skips further processing and returns false.
    • Purpose: Confirms the frame is correctly formatted and from the expected source.
  6. Read Sensor Data and Flags:
    • The ESP32 reads the next 4 bytes into the distances[] array (representing distance measurements).
    • Reads the following 2 bytes into the flags[] array (representing status or control flags).
    • Purpose: Extracts the payload data for use in safety algorithms (e.g., FCW, BSW).
  7. Verify CRC:
    • The ESP32 reads the 8th byte as the received CRC.
    • Calculates the expected CRC by XORing the 6 payload bytes: distances[0] ^ distances[1] ^ distances[2] ^ distances[3] ^ flags[0] ^ flags[1].
    • Compares the received CRC with the expected CRC.
    • Purpose: Detects transmission errors to ensure data integrity.
  8. Send Acknowledgment or Rejection:
    • If CRC Matches: The ESP32 sends 0xCC (ACK) using Serial.write(0xCC) and returns true, indicating successful data reception.
    • If CRC Fails: Sends 0xDD (rejection) using Serial.write(0xDD), displays an error message on the LCD (e.g., "Data Error! Re-requesting..."), and returns false.
    • Purpose: Provides feedback to the RPi4, enabling retransmission if needed.

 



Second model



AutoSense Guardian
Embedded Work
 Design of Our models