cute_useless_robot.ino 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Cute Useless Robot (´・ω・`)
  3. Developed by tobychui
  4. Idea come from Kairoshi
  5. Board Settings:
  6. ESP32 v2.014
  7. -> ESP32 Dev Module
  8. -> Flash Mode: DIO
  9. */
  10. /* Libraries */
  11. #include <MD_MAX72xx.h>
  12. #include <SPI.h>
  13. #include <SD.h>
  14. #include <FS.h>
  15. #include <ESP32Servo.h> //Require ESP32Servo
  16. #include <WiFi.h>
  17. #include <ESPAsyncWebServer.h>
  18. #include <DNSServer.h>
  19. /* Pins Definations */
  20. #define STP_DATA_PIN 4 // Stepper Shift Register DS
  21. #define STP_CLOCK_PIN 16 // Stepper Shift Register SH_CP
  22. #define STP_LATCH_PIN 17 // Stepper Shift Register ST_CP
  23. #define SERVO_SWITCH 27 //Servo to push the switch
  24. #define SERVO_COVER 14 //Servo to push the cover
  25. #define DP_CLK_PIN 32 //Display CLK
  26. #define DP_DATA_PIN 33 //Display DIN
  27. #define DP_CS_PIN 25 //Display CS
  28. #define SD_CS_PIN 5 //SD Card CS pin
  29. #define TOGGLE_SWITCH 13 //Switch on top of the matrix display
  30. /* Display settings generated by trial and error. Don't touch these */
  31. #define HARDWARE_TYPE MD_MAX72XX::DR1CR0RR0_HW
  32. #define MAX_DEVICES 8
  33. /* WiFI AP Settings */
  34. #define AP_SSID "(´・ω・`)"
  35. #define ENABLE_WIFI_DEBUG true //Set to true to use WiFi Client mode for remote debugging
  36. #define DEBUG_SSID "LENS" //Debug SSID, usually your home WiFi SSID
  37. #define DEBUG_PWD "1a21b998f4" //Debug Password, your home WiFi Password
  38. AsyncWebServer server(80);
  39. DNSServer dnsServer;
  40. /* Calibrated offset for switch pusher servo, in degrees */
  41. #define SERVO_ALIGNMENT_OFFSET 1
  42. /* Hardware Type Definations */
  43. Servo servoSwitchPusher;
  44. Servo servoCoverPusher;
  45. MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DP_DATA_PIN, DP_CLK_PIN, DP_CS_PIN, MAX_DEVICES);
  46. /* Global Variables */
  47. char animation = 'a'; //Animation ID to render
  48. int movingDirection = 0; //Debug mode -> Moving direction
  49. bool movingActive = false; //Debug mode -> Is Moving direction active
  50. void setup() {
  51. delay(1000);
  52. Serial.begin(115200);
  53. // Allow allocation of all timers
  54. ESP32PWM::allocateTimer(0);
  55. ESP32PWM::allocateTimer(1);
  56. ESP32PWM::allocateTimer(2);
  57. ESP32PWM::allocateTimer(3);
  58. /* Stepper IO */
  59. pinMode(STP_DATA_PIN, OUTPUT);
  60. pinMode(STP_CLOCK_PIN, OUTPUT);
  61. pinMode(STP_LATCH_PIN, OUTPUT);
  62. standbySteppers();
  63. /* Servo IO */
  64. servoSwitchPusher.setPeriodHertz(50);
  65. servoCoverPusher.setPeriodHertz(50);
  66. servoSwitchPusher.attach(SERVO_SWITCH);
  67. servoCoverPusher.attach(SERVO_COVER);
  68. servoCoverPusher.write(0);
  69. servoSwitchPusher.write(0);
  70. /* Display Module */
  71. mx.begin();
  72. setDisplayBrightness(0x4);
  73. renderFrame(); //Render the default frame to matrix
  74. /* SD Card */
  75. // Initialize SD card
  76. if (!SD.begin(SD_CS_PIN, SPI, 4000000U, "/sd", 10U, false)) {
  77. Serial.println("[Error] Unable to mount SD card. Retrying in 10 seconds");
  78. loadSDErrorToFrameBuffer(); //Render SD ERROR to display
  79. renderFrame();
  80. //Retry in 10 seconds
  81. delay(5000);
  82. ESP.restart();
  83. }
  84. /* Start Dual-core processes */
  85. createSemaphore();
  86. startCoreTasks();
  87. }
  88. void loop() {
  89. //Process has been handled in tasks.ino
  90. //Do not use this loop
  91. }