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_v1.2.ino 5.1KB

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