Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Pbrown
Published © GPL3+

Endangered Animal Detector

Uses small low cost Grove Ai and wio elements to track endangered animals (first case birds) to then provide evidence for protection.

IntermediateWork in progress20 hours260
Endangered Animal Detector

Things used in this project

Hardware components

SenseCAP K1100 - The Sensor Prototype Kit with LoRa® and AI
Seeed Studio SenseCAP K1100 - The Sensor Prototype Kit with LoRa® and AI
×1
Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
used as a comparison, and p2p lora receiver
×1
Pi NoIR Camera V2
Raspberry Pi Pi NoIR Camera V2
used to confirm the ML on another system when I had trouble with the vision module
×1
IoT LoRa Node pHAT for Raspberry Pi (Multi Frequency)
Pi Supply IoT LoRa Node pHAT for Raspberry Pi (Multi Frequency)
lora receiver for testing
×1
Solar Panel, 2.5 W
Solar Panel, 2.5 W
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Proof of concept bench top build

It is the K1100 with the Vision and E5 lora modules attached.

Code

Environment Monitoring Code - Req debug

Arduino
This is the Bird detection ML model - Lora is commented out due to the gateway not active to RX.
#include <U8g2lib.h>

#include <Arduino.h>

#include <Wire.h>

#include <Seeed_Arduino_GroveAI.h>

#include"TFT_eSPI.h"


//Lora commented during debugging 

// #define NODE_SLAVE
 
//U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/U8X8_PIN_NONE);
// U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // OLEDs without Reset of the Display
 
//static char recv_buf[512];
//static bool is_exist = false;
//

TFT_eSPI tft;

GroveAI ai(Wire);

uint8_t state = 0;

// at check send response
//static int at_send_check_response(char *p_ack, int timeout_ms, char *p_cmd, ...)
//{
//    int ch = 0;
//    int index = 0;
//    int startMillis = 0;
//    va_list args;
//    memset(recv_buf, 0, sizeof(recv_buf));
//    va_start(args, p_cmd);
//    Serial1.printf(p_cmd, args);
//    Serial.printf(p_cmd, args);
//    va_end(args);
//    delay(200);
//    startMillis = millis();
// 
//    if (p_ack == NULL)
//    {
//        return 0;
//    }
// 
//    do
//    {
//        while (Serial1.available() > 0)
//        {
//            ch = Serial1.read();
//            recv_buf[index++] = ch;
//            Serial.print((char)ch);
//            delay(2);
//        }
// 
//        if (strstr(recv_buf, p_ack) != NULL)
//        {
//            return 1;
//        }
// 
//    } while (millis() - startMillis < timeout_ms);
//    return 0;
//}

///////node_send function

//static int node_send(uint8_t results)
//{
//    static uint16_t count = 0;
//    int ret = 0;
//    char data[32];
//    char cmd[128];
// 
//    memset(data, 0, sizeof(data));
//    sprintf(data, "%04X", count);
//    sprintf(cmd, "AT+TEST=TXLRPKT,\"5345454544%s\"\r\n", data);
// 
//    u8x8.setCursor(0, 3);
//    u8x8.print("                ");
//    u8x8.setCursor(2, 3);
//    u8x8.print("TX: 0x");
//    u8x8.print(data);
//
//    u8x8.print(results); // added to rx the ai feed
// 
//    ret = at_send_check_response("TX DONE", 2000, cmd);
//    if (ret == 1)
//    {
// 
//        count++;
//        Serial.print("Sent successfully!\r\n");
//    }
//    else
//    {
//        Serial.print("Send failed!\r\n");
//    }
//    return ret;
//}



/////////////////////////////// Setup///////

void setup()
{
  
  tft.begin();
  tft.setRotation(3);
  digitalWrite(LCD_BACKLIGHT, HIGH); // turn on the backlight
    
  tft.fillScreen(TFT_GREEN); // fills entire the screen with colour red
  delay(2000);
    // Turning off the LCD backlight
  
  //digitalWrite(LCD_BACKLIGHT, LOW);
  
  tft.println("Environment Monitoring Initialising");
  tft.println("Starting Lora");

//    // the lora init code
//    
//    u8x8.begin();
//    u8x8.setFlipMode(1);
//    u8x8.setFont(u8x8_font_chroma48medium8_r);
// 
//    Serial.begin(115200);
//    // while (!Serial);
// 
//    Serial1.begin(9600);
//    Serial.print("ping pong communication!\r\n");
//    u8x8.setCursor(0, 0);
// 
//    if (at_send_check_response("+AT: OK", 100, "AT\r\n"))
//    {
//        is_exist = true;
//        at_send_check_response("+MODE: TEST", 1000, "AT+MODE=TEST\r\n");
//        at_send_check_response("+TEST: RFCFG", 1000, "AT+TEST=RFCFG,866,SF12,125,12,15,14,ON,OFF,OFF\r\n");
//        delay(200);
//#ifdef NODE_SLAVE
//        u8x8.setCursor(5, 0);
//        u8x8.print("slave");
//#else
//        u8x8.setCursor(5, 0);
//        u8x8.print("master");
//#endif
//    }
//    else
//    {
//        is_exist = false;
//        Serial.print("No E5 module found.\r\n");
//        u8x8.setCursor(0, 1);
//        u8x8.print("unfound E5 !");
//    }
  
  delay(10000);

  

  
  Wire.begin();
  
  /// Serial.begin(115200); commented and moved earlier

  delay(10000);
  
  Serial.println("begin");
  tft.println("begin");
 
  
 if (ai.begin(ALGO_OBJECT_DETECTION, MODEL_EXT_INDEX_1)) // image classification changed from OBJECT_DETECTION and externel model 1
  {
    Serial.print("AI initiated");
    Serial.print("Version: ");
    Serial.println(ai.version());
    Serial.print("ID: ");
    Serial.println( ai.id());
    Serial.print("Algo: ");
    Serial.println( ai.algo());
    Serial.print("Model: ");
    Serial.println(ai.model());
    Serial.print("Confidence: ");
    Serial.println(ai.confidence());
    state = 1;
  }
  else
  {
    Serial.println("Algo begin failed.");
  }
}

void loop()
{
  if (state == 1)
  {
    Serial.println(state);
    tft.print("state:");
    tft.println(state);
    
    uint32_t tick = millis();
    if (ai.invoke()) // begin invoke
    {
      tft.println("invoke");
      
      while (1) // wait for invoking finished
      {
        CMD_STATE_T ret = ai.state(); 
        if (ret == CMD_STATE_IDLE)
        {
          break;
        }
        delay(2000);
       // tft.println("Invoke complete");
        //delay(2000);
        
      }

     uint8_t len = ai.get_result_len(); // receive how many objects
     Serial.println("len:");
     Serial.println(len);

     Serial.println("state:");
     Serial.println(state);
     
     if(len)
     {
       int time1 = millis() - tick; 
       Serial.print("Time consuming: ");
       Serial.println(time1);
       Serial.print("Number of Birds: ");
       Serial.println(len);
       object_detection_t data;       //get data // obj detect ... object_detection_t data;  //image classification image_classification_t
       
       
     

       for (int i = 0; i < len; i++)
       {
          Serial.println("result:detected");
          Serial.print("Detecting and calculating: ");
          Serial.println(i+1);
          ai.get_result(i, (uint8_t*)&data, sizeof(object_detection_t)); //get result // image classification again 
  
          Serial.print("confidence:");
          Serial.print(data.confidence);
          Serial.println();

          Serial.print("Target:"); // added to print the target
          Serial.print(data.target);
          Serial.println();
          tft.println("Target:...");
          tft.println(data.target);
         // node_send(data.target); // send the results to the lora
         // uint8_t result = data.target; // not required
        }
     }
     else
     {
       Serial.println("No identification");
     }
    }
    else
    {
      delay(3000);
      Serial.println("Invoke Failed.");
    }
  }
  else
  {
    state == 0;
  }
}


 

Credits

Pbrown

Pbrown

1 project • 0 followers
Thanks to The Seeed wikis and example code. .

Comments