yihui meng
Published

What to eat today?

Are you used to being confused what to eat? We design this project to solve the problem using sensor.

IntermediateShowcase (no instructions)3 hours80
What to eat today?

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

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
Utility knife
Glue

Story

Read more

Custom parts and enclosures

eat

Schematics

eat

Code

what to eat

C/C++
#include "TFT_eSPI.h"
#include "Seeed_FS.h" //Including SD card library
#include "RawImage.h"  //Including image processing library
#include "Wire.h"
#include "DHT.h"
#include "Free_Fonts.h"
#include "Seeed_Arduino_GroveAI.h"

GroveAI ai(Wire);
uint8_t state = 0;


TFT_eSPI tft = TFT_eSPI();
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite
const char* list[] = {"0.bmp", "1.bmp", "2.bmp", "3.bmp", "4.bmp", "5.bmp", "6.bmp", "7.bmp", "8.bmp", "9.bmp", "10.bmp", "11.bmp", "12.bmp", "13.bmp", "14.bmp", "15.bmp"};



int flat = 0;

int hot = 0;
int num = 0;
int cold = 0;

void read_VisionAI()  //VisionAI
{
 
    Serial.println("if state == 1");
    uint32_t tick = millis();
    if (ai.invoke()) // begin invoke
    {
      Serial.println("if(ai.invoke())");
      while (1) // wait for invoking finished
      {
        CMD_STATE_T ret = ai.state();
        if (ret == CMD_STATE_IDLE)
        {
          Serial.println("break");
          break;
        }
        delay(20);
      }
      uint8_t len = ai.get_result_len(); // receive how many people detect
      if (len)
      {


        num = len;
        Serial.println("num = len");

        object_detection_t data;       //get data
      }
      else
      {
        Serial.println("No identification");
        num = 0;

      }
    }
    else
    {
      Serial.println("Invoke Failed.");
      delay(100);
    }
 

}



void setup() {


  Wire.begin();
  Serial.begin(115200);
ai.begin(ALGO_OBJECT_DETECTION, MODEL_EXT_INDEX_1);

  if (!SD.begin(SDCARD_SS_PIN, SDCARD_SPI, 4000000UL)) {
    while (1);
  }
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(TFT_BLACK);

}

void loop() {

  read_VisionAI();
  randomSeed(analogRead(4));
  cold = random(1, 10);

  if (num == 1) {
    Serial.print("num = 1");
    flat = 1;
    Serial.print("flat = 1");
  }

  if (flat == 0) {
    drawImage<uint16_t>("0.bmp", 0, 0);
    Serial.println("good");
    delay(100);
  }

  if (flat == 1) {

    Serial.println(cold);

    if (cold == 1) {
      drawImage<uint16_t>("1.bmp", 0, 0);
      flat = 0;
      Serial.println(11);
    }

    if (cold == 2) {
      drawImage<uint16_t>("2.bmp", 0, 0);
      flat = 0;
      Serial.println(12);
    }


    if (cold == 3) {
      drawImage<uint16_t>("3.bmp", 0, 0);
      flat = 0;
      Serial.println(13);
    }

    if (cold == 4) {
      drawImage<uint16_t>("4.bmp", 0, 0);
      flat = 0;
      Serial.println(14);
    }

    if (cold == 5) {
      drawImage<uint16_t>("5.bmp", 0, 0);
      flat = 0;
      Serial.println(15);
    }

    if (cold == 6) {
      drawImage<uint16_t>("6.bmp", 0, 0);
      flat = 0;
      Serial.println(16);
    }

    if (cold == 7) {
      drawImage<uint16_t>("7.bmp", 0, 0);
      flat = 0;
      Serial.println(17);
    }


    if (cold == 8) {
      drawImage<uint16_t>("8.bmp", 0, 0);
      flat = 0;
      Serial.println(18);
    }

    if (cold == 9) {
      drawImage<uint16_t>("9.bmp", 0, 0);
      flat = 0;
      Serial.println(19);
    }


    if (cold == 10) {
      drawImage<uint16_t>("10.bmp", 0, 0);
      flat = 0;
      Serial.println(110);
    }

    if (cold == 11) {
      drawImage<uint16_t>("11.bmp", 0, 0);
      flat = 0;
      Serial.println(111);
    }

    if (cold == 12) {
      drawImage<uint16_t>("12.bmp", 0, 0);
      flat = 0;
      Serial.println(112);
    }

    if (cold == 13) {
      drawImage<uint16_t>("13.bmp", 0, 0);
      flat = 0;
      Serial.println(113);
    }

    if (cold == 14) {
      drawImage<uint16_t>("14.bmp", 0, 0);
      flat = 0;
      Serial.println(114);
    }

    if (cold == 15) {
      drawImage<uint16_t>("15.bmp", 0, 0);
      flat = 0;
      Serial.println(115);
    }

    delay(5000);


  }







}

Credits

yihui meng
0 projects • 0 followers
Thanks to Meng Yihui.

Comments