Skip to main content

Transmisión RS485 de datos de Vision AI V2

Preparación de Hardware

Seeed Studio XIAO ESP32S3Grove Vision AI V2Módulo de Cámara OV5647-62 FOV
para Raspberry Pi 3B+4B
Seeed Studio XIAO RS485-Expansion-Board

Método de conexión

En primer lugar, prepara dos placas de expansión, dos placas de desarrollo de la serie XIAO y una Vision AI V2, y conecta los pines correspondientes según el diagrama. Esta rutina utiliza el XIAO ESP32C3 como demostración.

Paso 1. Prepara dos placas de expansión RS485 y dos placas de desarrollo de la serie XIAO y conecta los pines según la siguiente figura

Paso 2. Prepara la Vision AI V2 para montarla en la parte posterior de una de las dos placas de expansión RS485 como emisor

tip

Si estás usando una placa de expansión RS485 por primera vez y no estás seguro de cómo cablearla, haz clic en este enlace(https://wiki.seeedstudio.com/es/XIAO-RS485-Expansion-Board/)

Si no sabes cómo grabar el modelo y añadir el código de salida del modelo, haz clic en este enlace(https://wiki.seeedstudio.com/es/grove_vision_ai_v2_software_support/), que te explicará cada paso en detalle

¡Para un mejor uso posterior, no te saltes estos dos pasos!

Preparación del Software

Código del Emisor

#include <Seeed_Arduino_SSCMA.h>

#ifdef ESP32
#include <HardwareSerial.h>

HardwareSerial Serial3(1);

// Define two Serial devices mapped to the two internal UARTs
HardwareSerial atSerial(0);

#else
#define atSerial Serial1
#endif

#define enable_pin D2 // Define the enable pin as D2

SSCMA AI;

void setup()
{
Serial3.begin(115200, SERIAL_8N1, 7, 6); // Initialize Serial3 with 115200 baud rate, 8 data bits, no parity, 1 stop bit
Serial.begin(9600); // Initialize Serial for debugging output
AI.begin(&atSerial); // Initialize the AI module with the AT serial

pinMode(enable_pin, OUTPUT); // Set the enable pin as an output
digitalWrite(enable_pin, HIGH); // Set the enable pin to high to enable the AI module
}

void loop()
{
if (!AI.invoke(1, false, true)) { // Invoke the AI to start processing

Serial.println("invoke success"); // Print success message

// Print performance metrics
Serial.print("perf: prepocess=");
Serial.print(AI.perf().prepocess);
Serial.print(", inference=");
Serial.print(AI.perf().inference);
Serial.print(", postpocess=");
Serial.println(AI.perf().postprocess);

// Loop through detected boxes
for (int i = 0; i < AI.boxes().size(); i++) {
Serial.print("Box[");
Serial.print(i);
Serial.print("] target=");
Serial.print(AI.boxes()[i].target);
Serial.print(", score=");
Serial.print(AI.boxes()[i].score);
Serial.print(", x=");
Serial.print(AI.boxes()[i].x);
Serial.print(", y=");
Serial.print(AI.boxes()[i].y);
Serial.print(", w=");
Serial.print(AI.boxes()[i].w);
Serial.print(", h=");
Serial.println(AI.boxes()[i].h);
}

// Loop through detected classes
for (int i = 0; i < AI.classes().size(); i++) {
Serial.print("Class[");
Serial.print(i);
Serial.print("] target=");
Serial.println(AI.classes()[i].target);

// Check the target class and send corresponding status
if (AI.classes()[i].target == 0) {
String status_a = "no people detected"; // Define status for no people detected
Serial3.println(status_a); // Send status to Serial3
Serial.println(status_a); // Print status to Serial monitor
} else if (AI.classes()[i].target == 1) {
String status_b = "people detected"; // Define status for people detected
Serial3.println(status_b); // Send status to Serial3
Serial.println(status_b); // Print status to Serial monitor
}
}
delay(1000); // Wait for 1 second before the next loop iteration
}
}

Funciones Detalladas del Código

  • Inclusión de Librerías

    • Incluir la librería HardwareSerial para usar la funcionalidad de serie por hardware.
    • Incluir la librería Seeed_Arduino_SSCMA para el control del módulo de IA.
  • Creación de Objetos Serie

    HardwareSerial Serial3(1); 
    HardwareSerial atSerial(0);

    Crear objetos Serial3 y atSerial para comunicación serie.

  • Creación de Objeto IA

    SSCMA AI;

    Crear una instancia de la clase SSCMA para procesamiento de IA.

  • Métricas de Rendimiento

    Serial.print("perf: prepocess=");
    Serial.print(AI.perf().prepocess);
    Serial.print(", inference=");
    Serial.print(AI.perf().inference);
    Serial.print(", postpocess=");
    Serial.println(AI.perf().postprocess);

    Imprimir métricas de rendimiento de las etapas de procesamiento de IA: preprocesamiento, inferencia y postprocesamiento.

  • Bucle de Cajas Detectadas


    for (int i = 0; i < AI.boxes().size(); i++) {
    Serial.print("Box[");
    Serial.print(i);
    Serial.print("] target=");
    Serial.print(AI.boxes()[i].target);
    Serial.print(", score=");
    Serial.print(AI.boxes()[i].score);
    Serial.print(", x=");
    Serial.print(AI.boxes()[i].x);
    Serial.print(", y=");
    Serial.print(AI.boxes()[i].y);
    Serial.print(", w=");
    Serial.print(AI.boxes()[i].w);
    Serial.print(", h=");
    Serial.println(AI.boxes()[i].h);
    }

    Recorrer las cajas detectadas e imprimir sus detalles, incluyendo objetivo, puntuación y coordenadas del cuadro delimitador.

  • Bucle de Clases Detectadas

    for (int i = 0; i < AI.classes().size(); i++) {
    Serial.print("Class[");
    Serial.print(i);
    Serial.print("] target=");
    Serial.println(AI.classes()[i].target);

    Recorrer las clases detectadas e imprimir sus objetivos.

  • Definición de Macro

    pinMode(enable_pin, OUTPUT); // Set the enable pin as an output
    digitalWrite(enable_pin, LOW);

    Definir el pin de habilitación como D2.

  • Enviar Mensaje

    // Check the target class and send corresponding status
    if (AI.classes()[i].target == 0) {
    String status_a = "no people detected"; // Define status for no people detected
    Serial3.println(status_a); // Send status to Serial3
    Serial.println(status_a); // Print status to Serial monitor
    } else if (AI.classes()[i].target == 1) {
    String status_b = "people detected"; // Define status for people detected
    Serial3.println(status_b); // Send status to Serial3
    Serial.println(status_b); // Print status to Serial monitor
    }

    Determinar si se detecta una persona, si se detecta una persona se envía al receptor PEOPLE DETECTED, si no se detecta ninguna persona se envía al receptor NO PEOPLE DETECTED.

Código del Receptor

#include <HardwareSerial.h>

HardwareSerial Serial3(1); // Use UART2
#define enable_pin D2 // Define the enable pin as D2


void setup() {
Serial.begin(115200); // Initialize the hardware serial with a baud rate of 115200
Serial3.begin(115200, SERIAL_8N1, 7, 6); // Initialize Serial3 with 115200 baud rate, 8 data bits, no parity, 1 stop bit (RX=D4(GPIO4), TX=D5(GPIO5))

// Wait for the hardware serial to be ready
while(!Serial3);
while(!Serial); // This line is generally unnecessary as Serial.begin() is ready immediately

pinMode(enable_pin, OUTPUT); // Set the enable pin as an output
digitalWrite(enable_pin, LOW); // Set the enable pin to low to enable the device
}

void loop() {
delay(100); // Delay for 100 milliseconds
// Check if there is data available from the hardware serial
if (Serial3.available()) {
String receivedData = Serial3.readStringUntil('\n'); // Read string until newline character
Serial.print("Received data: "); // Print label for received data
Serial.println(receivedData); // Directly print the received data
}
}

Funciones Detalladas del Código

  • Inclusión de Biblioteca

    • Incluir la biblioteca HardwareSerial para usar la funcionalidad de serie por hardware.
  • Creación de Objeto Serial

    • Crear un objeto Serial3 usando UART2.
  • Definición de Macro

    pinMode(enable_pin, OUTPUT); // Set the enable pin as an output
    digitalWrite(enable_pin, LOW);

    Definir el pin de habilitación como D2.

  • Función Setup

    Serial3.begin(115200, SERIAL_8N1, 7, 6);

    Inicializar el puerto serie principal y Serial3, configurando la velocidad de baudios, bits de datos, etc. Este es el puerto serie que se comunica con el vision ai v2 para transferir datos.

    while(!Serial3);
    while(!Serial);

    Esperar a que todos los puertos serie estén listos, configurar el pin de habilitación como salida, y ponerlo en bajo para habilitar el dispositivo.

  • Función Loop

    • if (Serial3.available());: Verificar cada 100 milisegundos si hay datos disponibles en Serial3.
    • String receivedData = Serial3.readStringUntil('\n');: Si hay datos disponibles, leerlos hasta un carácter de nueva línea e imprimir los datos recibidos al puerto serie principal.
  • Imprimir resultados

    Serial.print("Received data: "); 
    Serial.println(receivedData);

    Imprimir el mensaje del emisor

Gráfico de Resultados

Sin embargo, la cámara enviará "people detected" cuando reconozca a una persona y "no people detected" cuando no reconozca a una persona, y el receptor mostrará el resultado del reconocimiento del emisor en el puerto serie.

Soporte Técnico y Discusión de Productos

¡Gracias por elegir nuestros productos! Estamos aquí para brindarle diferentes tipos de soporte para asegurar que su experiencia con nuestros productos sea lo más fluida posible. Ofrecemos varios canales de comunicación para satisfacer diferentes preferencias y necesidades.

Loading Comments...