You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tactile_eeg_router.ino 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // Arduino -> Adafruit ESP32 Feather auswählen
  2. #include <WiFi.h>
  3. #include <WiFiUDP.h>
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. /* Firmware v1.1 04.04.2019
  7. * Christian Schuster
  8. * cchschuster@gmail.com
  9. *
  10. * Firmware v1.2 03.08.2020
  11. * Igor Beloschapkin
  12. * beloschapkin@protonmail.com
  13. * Implement Autoconnect to Home Network
  14. *
  15. * Firmware v1.3 06.11.2020
  16. * Igor Beloschapkin
  17. * beloschapkin@protonmail.com
  18. * Add Support for 6 Taktilos
  19. *
  20. */
  21. // define PINs
  22. #define PIN_LED 13
  23. #define PIN_TAC6 12
  24. #define PIN_TAC5 27
  25. #define PIN_TAC4 33
  26. #define PIN_TAC3 15
  27. #define PIN_TAC2 32
  28. #define PIN_TAC1 14
  29. #define PIN_13 13
  30. #define PIN_A5 4
  31. #define PIN_A1 25
  32. #define PIN_A0 26
  33. #define SCRIPTMODE 1 // 0 = local filtering, 1 = laptop script filtering
  34. char ssid[] = "ssid";
  35. char pass[] = "pass";
  36. char packetBuffer[255]; // buffer to hold incoming packet
  37. unsigned int localPort = 8888;
  38. char sig_nr;
  39. int i_sig_nr;
  40. WiFiUDP udp;
  41. void setup()
  42. {
  43. setInitGPIO();
  44. // Initialize serial
  45. Serial.begin(115200);
  46. Serial.println();
  47. Serial.print("Connecting to WIFI at SSID: ");
  48. Serial.print(ssid);
  49. // Connect to WPA/WPA2 network:
  50. bool result = WiFi.begin(ssid, pass);
  51. // Wait 10 seconds for connection:
  52. delay(10000);
  53. //result = false; // for error testing
  54. if(result)
  55. {
  56. successWiFi();
  57. udp.begin(localPort);
  58. } else {
  59. errorWiFi();
  60. }
  61. }
  62. void printWifiData() {
  63. // print your WiFi shield's IP address:
  64. IPAddress ip = WiFi.localIP();
  65. Serial.print("IP Address: ");
  66. Serial.println(ip);
  67. Serial.println(ip);
  68. // print your MAC address:
  69. byte mac[6];
  70. WiFi.macAddress(mac);
  71. Serial.print("MAC address: ");
  72. Serial.print(mac[5], HEX);
  73. Serial.print(":");
  74. Serial.print(mac[4], HEX);
  75. Serial.print(":");
  76. Serial.print(mac[3], HEX);
  77. Serial.print(":");
  78. Serial.print(mac[2], HEX);
  79. Serial.print(":");
  80. Serial.print(mac[1], HEX);
  81. Serial.print(":");
  82. Serial.println(mac[0], HEX);
  83. }
  84. void printCurrentNet() {
  85. // print the SSID of the network you're attached to:
  86. Serial.print("SSID: ");
  87. Serial.println(WiFi.SSID());
  88. // print the MAC address of the router you're attached to:
  89. // byte bssid[6];
  90. // WiFi.BSSID(bssid);
  91. // Serial.print("BSSID: ");
  92. // Serial.print(bssid[5], HEX);
  93. // Serial.print(":");
  94. // Serial.print(bssid[4], HEX);
  95. // Serial.print(":");
  96. // Serial.print(bssid[3], HEX);
  97. // Serial.print(":");
  98. // Serial.print(bssid[2], HEX);
  99. // Serial.print(":");
  100. // Serial.print(bssid[1], HEX);
  101. // Serial.print(":");
  102. // Serial.println(bssid[0], HEX);
  103. // print the received signal strength:
  104. long rssi = WiFi.RSSI();
  105. Serial.print("signal strength (RSSI):");
  106. Serial.println(rssi);
  107. // print the encryption type:
  108. // byte encryption = WiFi.encryptionType();
  109. // Serial.print("Encryption Type:");
  110. // Serial.println(encryption, HEX);
  111. // Serial.println();
  112. }
  113. void loop()
  114. {
  115. int packetSize = udp.parsePacket();
  116. if(packetSize)
  117. {
  118. int len = udp.read(packetBuffer, 255);
  119. if(len)
  120. {
  121. packetBuffer[len] = 0;
  122. }
  123. if(SCRIPTMODE) // == 1
  124. {
  125. // laptop script filtering
  126. sig_nr = packetBuffer[0];
  127. Serial.println(sig_nr);
  128. vibrate(sig_nr);
  129. } else {
  130. // local filtering
  131. if(strstr(packetBuffer,"usCode "))
  132. {
  133. sig_nr = packetBuffer[13];
  134. Serial.println(sig_nr);
  135. vibrate(sig_nr);
  136. }
  137. }
  138. }
  139. }
  140. void setInitGPIO()
  141. {
  142. // Set all as OUTPUT
  143. pinMode(PIN_LED, OUTPUT);
  144. pinMode(PIN_TAC6, OUTPUT);
  145. pinMode(PIN_TAC5, OUTPUT);
  146. pinMode(PIN_TAC4, OUTPUT);
  147. pinMode(PIN_TAC3, OUTPUT);
  148. pinMode(PIN_TAC2, OUTPUT);
  149. pinMode(PIN_TAC1, OUTPUT);
  150. // Bisher ungenutzte Pins
  151. pinMode(PIN_13, OUTPUT);
  152. pinMode(PIN_A5, OUTPUT);
  153. pinMode(PIN_A1, OUTPUT);
  154. pinMode(PIN_A0, OUTPUT);
  155. allLow();
  156. }
  157. void allLow()
  158. {
  159. // Set all LOW
  160. digitalWrite(PIN_LED, LOW);
  161. digitalWrite(PIN_TAC6, LOW);
  162. digitalWrite(PIN_TAC5, LOW);
  163. digitalWrite(PIN_TAC4, LOW);
  164. digitalWrite(PIN_TAC3, LOW);
  165. digitalWrite(PIN_TAC2, LOW);
  166. digitalWrite(PIN_TAC1, LOW);
  167. // Bisher ungenutzte Pins
  168. digitalWrite(PIN_13, LOW);
  169. digitalWrite(PIN_A5, LOW);
  170. digitalWrite(PIN_A1, LOW);
  171. digitalWrite(PIN_A0, LOW);
  172. }
  173. void errorWiFi()
  174. {
  175. Serial.println("...Failed while connecting to Network");
  176. delay(2000);
  177. while(true)
  178. {
  179. digitalWrite(PIN_LED, HIGH);
  180. delay(100);
  181. digitalWrite(PIN_LED, LOW);
  182. delay(100);
  183. digitalWrite(PIN_LED, HIGH);
  184. delay(100);
  185. digitalWrite(PIN_LED, LOW);
  186. delay(1000);
  187. }
  188. }
  189. void successWiFi()
  190. {
  191. Serial.print("You're connected to the network");
  192. // Print out data
  193. printCurrentNet();
  194. printWifiData();
  195. delay(2000);
  196. for(int i = 0; i < 5; i++)
  197. {
  198. digitalWrite(PIN_LED, HIGH);
  199. delay(1000);
  200. digitalWrite(PIN_LED, LOW);
  201. delay(200);
  202. }
  203. }
  204. void vibrate(const char signr)
  205. {
  206. switch(signr)
  207. {
  208. case '6': digitalWrite(PIN_TAC6, HIGH); break;
  209. case '5': digitalWrite(PIN_TAC5, HIGH); break;
  210. case '4': digitalWrite(PIN_TAC4, HIGH); break;
  211. case '3': digitalWrite(PIN_TAC3, HIGH); break;
  212. case '2': digitalWrite(PIN_TAC2, HIGH); break;
  213. case '1': digitalWrite(PIN_TAC1, HIGH); break;
  214. case '0': allLow(); break;
  215. }
  216. }