Hackster is hosting Impact Spotlights highlighting smart energy storage. Start streaming on Thursday!Stream Impact Spotlights on Thursday!
Rucksikaa Raajkumar
Published © MIT

Play and study with M5Stack Core 2!

Children with ADHD can have difficulties in learning and this project focuses on this problem

IntermediateFull instructions provided4 hours407
Play and study with M5Stack Core 2!

Things used in this project

Hardware components

M5Stack Core2 ESP32 IoT Development Kit
M5Stack Core2 ESP32 IoT Development Kit
×1

Software apps and online services

Arduino IDE
Arduino IDE
Neuton
Neuton Tiny ML Neuton

Story

Read more

Schematics

ATECC608A Secure element

M5 Core2 for AWS

Code

Touch Test

Arduino
This is an example sketch file from M5GFX library that allows you to test your device and see how the touch points are drawn on the screen. Try using this example to understand how the device works and to verify that your device is working properly.
#include <M5GFX.h>

M5GFX display;

void setup(void)
{
  display.init();
  display.setFont(&fonts::Font4);

  if (!display.touch())
  {
    display.setTextDatum(textdatum_t::middle_center);
    display.drawString("Touch not found.", display.width() / 2, display.height() / 2);
  }

  display.setEpdMode(epd_mode_t::epd_fastest);
  display.startWrite();
}

void loop(void)
{
  static bool drawed = false;
  lgfx::touch_point_t tp[3];

  int nums = display.getTouchRaw(tp, 3);
  if (nums)
  {
    for (int i = 0; i < nums; ++i)
    {
      display.setCursor(16, 16 + i * 24);
      display.printf("Raw X:%03d  Y:%03d", tp[i].x, tp[i].y);
    }

    display.convertRawXY(tp, nums);

    for (int i = 0; i < nums; ++i)
    {
      display.setCursor(16, 128 + i * 24);
      display.printf("Convert X:%03d  Y:%03d", tp[i].x, tp[i].y);
    }
    display.display();

    display.setColor(display.isEPD() ? TFT_BLACK : TFT_WHITE);
    for (int i = 0; i < nums; ++i)
    {
      int s = tp[i].size + 3;
      switch (tp[i].id)
      {
      case 0:
        display.fillCircle(tp[i].x, tp[i].y, s);
        break;
      case 1:
        display.drawLine(tp[i].x-s, tp[i].y-s, tp[i].x+s, tp[i].y+s);
        display.drawLine(tp[i].x-s, tp[i].y+s, tp[i].x+s, tp[i].y-s);
        break;
      default:
        display.fillTriangle(tp[i].x-s, tp[i].y +s, tp[i].x+s, tp[i].y+s, tp[i].x, tp[i].y-s);
        break;
      }
      display.display();
    }
    drawed = true;
  }
  else if (drawed)
  {
    drawed = false;
    display.waitDisplay();
    display.clear();
    display.display();
  }
  vTaskDelay(1);
}

Data Collection

Arduino
Use this to collect data and prepare your dataset
#include <M5GFX.h>

M5GFX display;
int val;
int iteration;
const int Buffer_Size = "Your estimation of the number of pixels that are included when you draw a digit";
int* Buffer = (int*) calloc(Buffer_Size, sizeof(int));  

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  display.init();
  display.setFont(&fonts::Font4);

  if (!display.touch())
  {
    display.setTextDatum(textdatum_t::middle_center);
    display.drawString("Touch not found.", display.width() / 2, display.height() / 2);
  }

  display.setEpdMode(epd_mode_t::epd_fastest);
  display.startWrite();
  
  //Creating the header for the CSV file
  Serial.print("Label");
  for (int i=0;i<Buffer_Size;i++){
    Serial.print(",");
    Serial.print("pixel"+String(i));
  }
  Serial.println(); //Starts new row
  Serial.print("The digit for which you want to collect samples");
}

void loop() {
  // put your main code here, to run repeatedly:
  static bool drawed = false;
  lgfx::touch_point_t tp[3];

  int nums = display.getTouchRaw(tp, 3);

  if(nums)
  {
    display.convertRawXY(tp, nums);
    for (int i = 0; i < nums; ++i){
      if((tp[i].y * 320 + tp[i].x) != val && iteration < Buffer_Size){ //Prevents duplicate data
        Buffer[iteration] = (tp[i].y * 320) + tp[i].x; //Store pixel values. 320 is display width and can vary with different touchscreens
        val = Buffer[iteration];
        iteration++;
      }                 
     }
     display.display();
     display.setColor(display.isEPD() ? TFT_BLACK : TFT_WHITE);
     for (int i = 0; i < nums; ++i)
     {
      int s = tp[i].size + 3;
      switch (tp[i].id)
      {
      case 0:
        display.fillCircle(tp[i].x, tp[i].y, s);
        break;
      case 1:
        display.drawLine(tp[i].x-s, tp[i].y-s, tp[i].x+s, tp[i].y+s);
        display.drawLine(tp[i].x-s, tp[i].y+s, tp[i].x+s, tp[i].y-s);
        break;
      default:
        display.fillTriangle(tp[i].x-s, tp[i].y +s, tp[i].x+s, tp[i].y+s, tp[i].x, tp[i].y-s);
        break;
      }
      display.display();
    }
    drawed = true;
   }

   else if (drawed) //Implements after you finish drawing the digit
   {   
    for(int i = 0; i < Buffer_Size; i++){
      Serial.print(",");
      Serial.print(Buffer[i]);
      
    }
    Serial.println(); //Create a new row
    Serial.print("The digit for which you want to collect samples");

    drawed = false;
    display.waitDisplay();
    display.clear(); //Clear display to draw digit again
    display.display();
    val=iteration=0; //Reset iteration and val variables
    free(Buffer); //Clear buffer to allocate memory for the digits drawn again
    Buffer= (int*) calloc(Buffer_Size, sizeof(int));     
   }
   vTaskDelay(1);    
}

Color Initial Letter Recognition

This repository contains the C library containing the TinyML model and the Arduino sketch file required to embed your model on the microcontroller

Credits

Rucksikaa Raajkumar

Rucksikaa Raajkumar

43 projects • 93 followers
Amateur Arduino Developer. Undergraduate. YouTuber (https://www.youtube.com/c/RucksikaaRaajkumar/videos) and Blogger (Arduino Projects by R)

Comments