Andrea ZGuzAndres SabasMarcelo ArredondoJazmín Hernández
Published

Fortune Cat: Seeing the future

Cats are always curious, cats know things... Want to know where your life will go? Now your fortune teller is your own Cat!

IntermediateFull instructions provided2 hours528
Fortune Cat: Seeing the future

Things used in this project

Hardware components

Arduino Nano 33 BLE Sense
Arduino Nano 33 BLE Sense
×1
Grove - OLED Display 0.66" (SSD1306)- IIC - 3.3V/5V
Seeed Studio Grove - OLED Display 0.66" (SSD1306)- IIC - 3.3V/5V
×1

Software apps and online services

Arduino IDE
Arduino IDE
Cyberon Speech Recognition Engine

Hand tools and fabrication machines

Premium Female/Female Jumper Wires, 40 x 3" (75mm)
Premium Female/Female Jumper Wires, 40 x 3" (75mm)
USB micro cable

Story

Read more

Custom parts and enclosures

Case cover

This is the top of your case

Case box

This is the box to put in your board and OLED display

Code

FortuneCat

Arduino
This is the code running the fortune teller application
#include <Arduino.h>                //Default Arduino library
#include <DSpotterSDK_MakerHL.h>    //Speech Recognition Tool Library
#include <LED_Control.h>            //Controling the onboard LED for checking the status (trigger or command status)
#include <Wire.h>                   //Controlling I2C communication between Arduino Nano 33 BLE Sense and the OLED display
#include "nRF_SH1106Wire.h"         //OLED Display SH1106 library
#include "CybLicense_1696873329.h"  //The DSpotter License Data (License for your board using Cyberon Speech Recognition tool)
#include "Model_1696873329.h"       //Your model, contains your trigger word and command word (or words)
#include "images.h"                 //Electronic Cats Logo

#define DSPOTTER_LICENSE g_lpdwLicense
#define DSPOTTER_MODEL g_lpdwModel
#define COMMAND_FUTURE  10000      //ID number for your command word (more than one if you are using more command words)

static DSpotterSDKHL g_oDSpotterSDKHL;                     //The VR engine object. Only can exist one, otherwise not worked.
SH1106Wire display(0x3c, PIN_WIRE_SDA, PIN_WIRE_SCL);      //I2C ADDRESS, SDA, SCL 


const char* selectPhrase();   //Selecting phrase routine

void VRCallback(int nFlag, int nID, int nScore, int nSG, int nEnergy)     // Callback function for VR engine
{
  if (nFlag==DSpotterSDKHL::InitSuccess)
  {
      //ToDo
  }
  else if (nFlag==DSpotterSDKHL::GetResult)
  {
      /*
      When getting an recognition result,
      the following index and scores are also return to the VRCallback function:
          nID        The result command id (from de command word)
          nScore     nScore is used to evaluate how good or bad the result is.
                     The higher the score, the more similar the voice and the result command are.
          nSG        nSG is the gap between the voice and non-command (Silence/Garbage) models.
                     The higher the score, the less similar the voice and non-command (Silence/Garbage) models are.
          nEnergy    nEnergy is the voice energy level.
                     The higher the score, the louder the voice.
      */
      if(nID==COMMAND_FUTURE)   //If nID=="tell me my future"
        display.clear();        //Clear the display
        display.drawStringMaxWidth(0, 10, 128, selectPhrase());   //Display chosen phrase
        display.display();      //Write the buffer to the display
  }
  else if (nFlag==DSpotterSDKHL::ChangeStage)
  {
      switch(nID)
      {
          case DSpotterSDKHL::TriggerStage:     //If "Fortune Cat" trigger word has not been said yet
            LED_RGB_Off();                      
            LED_BUILTIN_Off();
            display.clear(); 
            display.drawStringMaxWidth(0, 10, 128, "Your future I can see... just ask");   //Display this phrase, waiting for "Fortune Cat" trigger word
            display.display();    
            break;
          case DSpotterSDKHL::CommandStage:    //If "Fortune Cat" trigger word has been said
            LED_BUILTIN_On();
            display.clear(); 
            display.drawStringMaxWidth(0, 10, 128, "Yes?");   //Display this phrase, waiting for "tell me my future" command word
            display.display();    
            break;
          default:
            break;
      }
  }
  else if (nFlag==DSpotterSDKHL::GetError)
  {
      if (nID == DSpotterSDKHL::LicenseFailed)  //If CybLicense_xxxxxxxxxx.h file is not valid (unvalid license)
      {
          Serial.print("DSpotter license failed! The serial number of your device is ");
          Serial.println(DSpotterSDKHL::GetSerialNumber());
      }
      g_oDSpotterSDKHL.Release();
      while(1);//hang loop
  }
  else if (nFlag == DSpotterSDKHL::LostRecordFrame)
  {
      //ToDo
  }
}

void setup()
{
  LED_Init_All();          //Init LED control
  Serial.begin(115200);    //Init Serial output for show debug info
  display.init();          //Init display
  display.flipScreenVertically();             //Use vertical displaying mode
  display.setFont(ArialMT_Plain_10);          //Use this font
  display.setTextAlignment(TEXT_ALIGN_LEFT);  //Start typing from left side
  display.clear();                            //Clears display 
  display.drawXbm(34, 5, EC_Logo_width, EC_Logo_height, EC_Logo_bits);    //Display Electronic Cats logo, available in "images.h" file
  display.drawString(25, 40, "FORTUNE CAT");  //Display "Fortune Cat" as well
  display.display();                          //Write the buffer to the display
  delay(5000);                                //Hold on 5 sec
  display.clear();                            //Clears display
  display.setFont(ArialMT_Plain_16);          //Use this font
  
  DSpotterSDKHL::ShowDebugInfo(true);

  //Init Voice Recognition Engine & Audio
  if (g_oDSpotterSDKHL.Init(DSPOTTER_LICENSE, sizeof(DSPOTTER_LICENSE), DSPOTTER_MODEL, VRCallback) != DSpotterSDKHL::Success)
    return;
}

void loop()
{
  g_oDSpotterSDKHL.DoVR();     //Do Voice Recognition, constantly
}

const char* selectPhrase()    //Selects a random number, this random number matches one phrase, this phrase is then displayed
{
  byte number;
  number=random(1, 20);
  switch (number)
  {
    case 1:
      return "You will win the lottery!";
      break;
    case 2:
      return "Your cat will get lost";
      break;
    case 3:
      return "Your cat will live forever";
      break;
    case 4:
      return "You're not finding the bug";
      break;
    case 5:
      return "You're the next boss";
      break;
    case 6:
      return "You'll become a linuxer";
      break;
    case 7:
      return "You'll find the bug";
      break;
    case 8:
      return "Your board is a fake Arduino";
      break;
    case 9:
      return "You will travel to Bermudas triangle";
      break;
    case 10:
      return "Day off. Not working now.";
      break;
    case 11:
      return "You will not finish this video game at 100%";
      break;
    case 12:
      return "You will be promoted to customer";
      break;
    case 13:
      return "You won't be better than an AI";
      break;
    case 14:
      return "Be careful what you wish for";
      break;
    case 15:
      return "Your luck is about to run out";
      break;
    case 16:
      return "Universe will conspire with you";
      break;
    case 17:
      return "Be careful what's behind you";
      break;
    case 18:
      return "You will get your Engineering Degree";
      break;
    case 19:
      return "You will get shocked";
      break;
    case 20:
      return "Wait a lot will be your downfall";
      break;
    default:
      break;
  }
}

Credits

Andrea ZGuz

Andrea ZGuz

6 projects • 2 followers
Electronic Engineer. Support Engineer at Electronic Cats.
Andres Sabas

Andres Sabas

40 projects • 44 followers
Co-Founder of The Inventor's House Hackerspace, DIY, Workaholic
Marcelo Arredondo

Marcelo Arredondo

6 projects • 2 followers
Jazmín Hernández

Jazmín Hernández

5 projects • 0 followers
Electronics Engineer. Passionate for tech and languages.

Comments