I was one of those awarded by Seeed Studio with a kit containing a Grove Vision AI V2 and a Xiao ESP32-C3. I'm developing an application that integrates object recognition with home automation and I look forward to the integration between SenseCraft and HomeAssistant working at some point.
For now, I'm doing some experiments with the pre-existing models in Seeed's sscma-model-zoo repository. And with the Arduino SSCMA library.
This is a very simple application, which infers the user's gestures in front of the camera. And it detects gestures referring to Paper, Rock and Scissors (in this order). It then makes a random choice and compares it with the player's choice and checks who is the winner.
I can attest that I have already managed to connect the Xiao via Bluetooth with another device and also that the Wifi and MQTT settings are read, although I have not yet been able to carry out the setup for HomeAssistant, as indicated on Seeed Studio's own Wiki.
The inference is performed so quickly by the board that I had to insert some delays into the code.
I added two versions. One simple and the other with Bluetooth functionality. The Seeed Xiao ESP32-C3 unit that will release the prize to the winner needs to be programmed with the ESPHOME firmware and attached YAML configuration file.
The work that the people at Seeed Studio are doing is truly incredible. I eagerly await the proper functioning of the Home Assistant integration and also tutorials indicating how to directly program the Grove Vision AI V2, using the board own SDK.
Will Seeed launch a board with this integrated AI solution and with the possibility of WIFI connection and free use of GPIO? I can't wait...
/**
Simple Paper, Rock, Scissor Game
2024 - By Djair Guilherme @nicolaudosbrinquedos
Using Grove Vision AI V2 - with Seeed XIAO ESP32-S3
and Gesture Detection Model
https://github.com/Seeed-Studio/sscma-model-zoo/blob/main/docs/en/Gesture_Detection_Swift-YOLO_192.md
*/
String myGame, yourGame;
#ifdef ESP32
#include <HardwareSerial.h>
HardwareSerial atSerial(0);
#else
#define atSerial Serial1
#endif
// Communication with Grove Vision AI V2
#include <Seeed_Arduino_SSCMA.h>
SSCMA GrooveAI;
// The inference returns Index of Object, not String
#define PAPER_TARGET 0
#define ROCK_TARGET 1
#define SCISSOR_TARGET 2
bool is_paper = false;
bool is_rock = false;
bool is_scissor = false;
int computerGuess = -1;
int score = 0;
int found = -1;
int lastGuess = -1;
unsigned long lastGuessTime = 0;
void setup()
{
randomSeed(analogRead(0));
GrooveAI.begin(&atSerial, D3);
Serial.begin(115200);
delay(2000);
Serial.println("PAPER ROCK SCISSOR GAME WITH AI");
}
void loop() {
if (!GrooveAI.invoke(1, false, true)) {
bool found = false;
int playerGuess = -1;
// Last Guess Time
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - lastGuessTime;
// For each Box, detect if is PAPER ROCK or SCISSOR
for (int i = 0; i < GrooveAI.boxes().size(); i++) {
if (GrooveAI.boxes()[i].target == ROCK_TARGET) {
is_rock = true;
playerGuess = ROCK_TARGET;
} else if (GrooveAI.boxes()[i].target == PAPER_TARGET) {
is_paper = true;
playerGuess = PAPER_TARGET;
} else if (GrooveAI.boxes()[i].target == SCISSOR_TARGET) {
is_scissor = true;
playerGuess = SCISSOR_TARGET;
} else {
is_rock = false;
is_paper = false;
is_scissor = false;
found = false;
}
}
// Update 'found' only if playerGuess is different than before or if 3s of last guess
if ((playerGuess != lastGuess || elapsedTime > 3000) && playerGuess != -1) {
found = true;
lastGuess = playerGuess;
}
if (found) {
// Create Computer Guess after inference
computerGuess = random(0, 3);
Serial.println("+++++++++++++++");
String yourGame = (playerGuess == 0) ? "PAPER" :
(playerGuess == 1) ? "ROCK" : "SCISSOR";
String myGame = (computerGuess == 0) ? "PAPER" :
(computerGuess == 1) ? "ROCK" : "SCISSOR";
int result = determine_winner(playerGuess, computerGuess);
if (result == 2) {
Serial.println("DRAW");
} else if (result == 1) {
Serial.println("Human WIN");
} else {
Serial.println("AI WIN");
}
Serial.print("Your guess is ");
Serial.print(yourGame);
Serial.print(" and mine is ");
Serial.println(myGame);
Serial.println("+++++++++++++++");
Serial.println();
// Reset conditions
is_rock = false;
is_paper = false;
is_scissor = false;
found = false;
}
}
delay(1000);
}
// WINNING CONDITIONS
int determine_winner(int playerGuess, int computerGuess) {
if (playerGuess == computerGuess) {
return 2; // Empate
} else if ((playerGuess == 0 && computerGuess == 1) || // Papel contra Pedra
(playerGuess == 1 && computerGuess == 2) || // Pedra contra Tesoura
(playerGuess == 2 && computerGuess == 0)) { // Tesoura contra Papel
return 1; // playerGuess vence
} else {
return 0; // computerGuess vence
}
}
Comments
Please log in or sign up to comment.