cute_useless_robot.ino 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "" //Debug SSID, usually your home WiFi SSID
  37. #define DEBUG_PWD "" //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. bool SD_exists = true; //Keep track of the animation SD card exists
  49. void setup() {
  50. Serial.begin(115200);
  51. // Allow allocation of all timers
  52. ESP32PWM::allocateTimer(0);
  53. ESP32PWM::allocateTimer(1);
  54. ESP32PWM::allocateTimer(2);
  55. ESP32PWM::allocateTimer(3);
  56. /* Stepper IO */
  57. pinMode(STP_DATA_PIN, OUTPUT);
  58. pinMode(STP_CLOCK_PIN, OUTPUT);
  59. pinMode(STP_LATCH_PIN, OUTPUT);
  60. standbySteppers();
  61. /* Servo IO */
  62. servoSwitchPusher.setPeriodHertz(50);
  63. servoCoverPusher.setPeriodHertz(50);
  64. servoSwitchPusher.attach(SERVO_SWITCH);
  65. servoCoverPusher.attach(SERVO_COVER);
  66. servoCoverPusher.write(0);
  67. servoSwitchPusher.write(0);
  68. /* Display Module */
  69. mx.begin();
  70. setDisplayBrightness(0x4);
  71. renderFrame(); //Render the default frame to matrix
  72. /* SD Card */
  73. // Initialize SD card
  74. if (!SD.begin(SD_CS_PIN,SPI,4000000U,"/sd",10U,false)) {
  75. Serial.println("[Error] Unable to mount SD card");
  76. loadSDErrorToFrameBuffer(); //Render SD ERROR to display
  77. renderFrame();
  78. while(1);
  79. }
  80. /* Start Dual-core processes */
  81. createSemaphore();
  82. startCoreTasks();
  83. }
  84. void loop() {
  85. //Process has been handled in tasks.ino
  86. //Do not use this loop
  87. }