-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecond_Console_Control.ino
More file actions
482 lines (393 loc) · 14.6 KB
/
Second_Console_Control.ino
File metadata and controls
482 lines (393 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/*
* Project: ESP8266 Wireless Console for Robotic Arm
* Version: 1.0.3
*
* Description:
* This firmware is designed to run on an ESP8266 module acting as a
* wireless console to control a robotic arm remotely over Wi-Fi.
* It sends HTTP GET requests to another ESP8266 module (mounted
* on the robotic arm) to trigger predefined movements or actions.
*
* Key Features:
* - Supports multiple preset commands (e.g., Do180, HighFive, Pickup, Dance)
* - Includes a connectivity check via /ping endpoint
* - Displays status and connection info on an OLED screen
* - Enhances interactivity by offering a handheld remote-style experience
*
* Author: Sunil Kummar , Mohd Amir
* Date: April 2025
*/
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define D2 5 //Bhai D2 ki pin SCL se connect ker.
#define D1 4 //Bhai D1 ki pin SDL se connect ker.
//<---------------------------------buttons------------------------------------->
#define BUTTON_UP 14 // D5
#define BUTTON_DOWN 12 // D6
#define BUTTON_A 13 // D7
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define ROBOT_IP "192.168.43.186"
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
WiFiClient client;
const char* ssid = "Robotic_hand";
const char* password = "12345678";
//<-----------------Change this to your Network IP------------------------>
IPAddress local_IP(192, 168, 43, 70);
IPAddress gateway(192, 168, 43, 1);
IPAddress subnet(255, 255, 255, 0);
//<---------------Bit MAP image------------------>
const unsigned char epd_bitmap_Outline_select[] PROGMEM = {
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00
};
// 'RoboticHandicon', 16x16px
const unsigned char epd_bitmap_RoboticHandicon[] PROGMEM = {
0x00, 0x3e, 0x00, 0x41, 0x01, 0x80, 0x03, 0x80, 0x07, 0x41, 0x1e, 0x3e, 0x3c, 0x00, 0x3c, 0x00,
0x3e, 0x00, 0x1f, 0x00, 0x03, 0x80, 0x01, 0xc0, 0x00, 0xe0, 0x00, 0x70, 0x07, 0xfe, 0x0f, 0xff
};
// 'TestIcon', 16x16px
const unsigned char epd_bitmap_TestIcon[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c, 0x00, 0x38,
0x40, 0x70, 0xe0, 0xe0, 0x71, 0xc0, 0x3b, 0x80, 0x1f, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'Checklink', 16x16px
const unsigned char epd_bitmap_Checklink[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x10, 0x08, 0x20, 0x04, 0x4f, 0xf2, 0x10, 0x08,
0x23, 0xc4, 0x04, 0x20, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char epd_bitmap_About[] PROGMEM = {
0x00, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0,
0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 496)
const int epd_bitmap_allArray_LEN = 5;
const unsigned char* epd_bitmap_allArray[5] = {
epd_bitmap_RoboticHandicon,
epd_bitmap_Checklink,
epd_bitmap_TestIcon,
epd_bitmap_About,
epd_bitmap_Outline_select
};
void startAnimation() {
display.setTextSize(1.5);
display.setTextColor(SSD1306_WHITE);
display.setCursor((SCREEN_WIDTH - 60) / 2, (SCREEN_HEIGHT + 22) / 2);
display.println("Starting...");
display.display();
delay(1000);
display.clearDisplay();
for (int i = 0; i < 3; i++) {
display.clearDisplay();
display.drawBitmap(
(SCREEN_WIDTH - 16) / 2,
(SCREEN_HEIGHT - 16) / 2,
epd_bitmap_allArray[i],
16, 16,
SSD1306_WHITE);
display.display();
delay(800);
}
delay(300);
display.clearDisplay();
}
void LoadingBar(int timeDelay) {
int barWidth = 80;
int barHeight = 10;
int barX = (SCREEN_WIDTH - barWidth) / 2;
int barY = 35;
display.drawRect(barX, barY, barWidth, barHeight, WHITE);
display.display();
for (int i = 0; i <= 100; i += 2) {
int fillWidth = (i * (barWidth - 2)) / 100;
display.fillRect(barX + 1, barY + 1, fillWidth, barHeight - 2, WHITE);
//presentage number bhai
display.fillRect((SCREEN_WIDTH - 20) / 2, barY + 15, 30, 10, BLACK);
display.setCursor((SCREEN_WIDTH - 20) / 2, barY + 15);
display.setTextColor(WHITE);
display.printf("%d%%", i);
display.display();
delay(timeDelay);
}
}
void showAbout() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor((128 - 96) / 2, 2);
display.println("Robotic Arm ");
display.setCursor((128 - 96) / 2, 20);
display.println("By Amir & Sunil");
display.setCursor((128 - 94) / 2, 38);
display.println("Guided by Anuj sir");
display.display();
delay(3000);
}
void test() {
display.clearDisplay();
display.setCursor((SCREEN_WIDTH - 60) / 2, (SCREEN_HEIGHT + 22) / 2 - 20);
display.println("Testing...");
LoadingBar(60);
display.display();
delay(1000);
}
void testServoandConnection() {
display.clearDisplay();
display.setCursor((SCREEN_WIDTH - 60) / 2, (SCREEN_HEIGHT + 22) / 2 - 20);
display.println("Please wait..");
LoadingBar(60);
display.display();
delay(1000);
}
void sendCommand(const char* funcName) {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = "http://" ROBOT_IP "/Preset?func=" + String(funcName);
http.begin(client, url);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
Serial.println("Response: " + payload);
} else {
Serial.println("GET request failed. Code: " + String(httpCode));
}
http.end();
} else {
Serial.println("WiFi not connected");
}
}
void highfive() {
display.clearDisplay();
display.setCursor((SCREEN_WIDTH - 60) / 2, (SCREEN_HEIGHT + 22) / 2 - 20);
display.println("HighFIVE");
LoadingBar(15);
display.display();
sendCommand("HighFive");
delay(500);
}
void Do180() {
display.clearDisplay();
display.setCursor((SCREEN_WIDTH - 60) / 2, (SCREEN_HEIGHT + 22) / 2 - 20);
display.println("Doing 180");
LoadingBar(15);
display.display();
sendCommand("Do180");
delay(500);
}
void pickup() {
display.clearDisplay();
display.setCursor((SCREEN_WIDTH - 60) / 2, (SCREEN_HEIGHT + 22) / 2 - 20);
display.println("Picking up");
LoadingBar(15);
display.display();
sendCommand("PickUp");
delay(500);
}
void Dance() {
display.clearDisplay();
display.setCursor((SCREEN_WIDTH - 60) / 2, (SCREEN_HEIGHT + 22) / 2 - 20);
display.println("Dancing...");
LoadingBar(15);
display.display();
sendCommand("Dance");
delay(500);
}
//Checks connection to the Robotic Hand
void Link() {
if (WiFi.status() == WL_CONNECTED) {
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 20);
display.println("Checking PING");
display.println("Please Wait");
display.display();
delay(700);
HTTPClient http;
String url = "http://" ROBOT_IP "/ping";
http.begin(client, url);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
Serial.println("Response: " + payload);
if (payload == "PONG") {
display.clearDisplay();
display.setCursor(30, 25);
display.println("PONG");
display.display();
delay(2000);
}
} else {
Serial.println("Ping request failed. Code: " + String(httpCode));
}
http.end();
} else {
Serial.println("WiFi not connected");
}
}
int num_item = 4; //<-----------Also update this variable if you updatethe manu_name
char manu_name[4][20] = {
{ "Preset Motions" },
{ "PING" },
{ "Test" },
{ "About" }
};
char preset_motions_manu[5][20] = {
{ "High Five" },
{ "Do 180" },
{ "Pick up" },
{ "Dance" },
{ "Main Manu" }
};
int item_selected = 0;
int next_item;
int prev_item;
//<-----------Preventing Fast scrolling change it if the manu jumps multiple times ----------------->
unsigned long lastButtonPress = 0;
const int debounceDelay = 200;
void setup() {
Wire.begin(D2, D1);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
delay(500);
startAnimation();
//<------------ Text size and Color---------------------->
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
pinMode(BUTTON_UP, INPUT_PULLUP);
pinMode(BUTTON_DOWN, INPUT_PULLUP); //Pull Uped by default so you have to connect the Pins to GND in order to activate it
pinMode(BUTTON_A, INPUT_PULLUP);
Serial.begin(115200);
if (!WiFi.config(local_IP, gateway, subnet)) {
Serial.println("STA Failed to configure");
}
// Connect to Wi-Fi
WiFi.begin(ssid, password);
// Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
// Serial.print(".");
}
display.clearDisplay();
display.setCursor(20, 32);
display.println(WiFi.localIP());
display.display();
delay(3000);
}
void loop() {
if (digitalRead(BUTTON_UP) == LOW && millis() - lastButtonPress > debounceDelay) {
item_selected -= 1;
if (item_selected < 0) item_selected = num_item - 1;
lastButtonPress = millis();
}
if (digitalRead(BUTTON_DOWN) == LOW && millis() - lastButtonPress > debounceDelay) {
item_selected += 1;
if (item_selected >= num_item) item_selected = 0;
lastButtonPress = millis();
}
prev_item = item_selected - 1;
//preventing overflow of list items
if (prev_item < 0) {
prev_item = num_item - 1;
}
next_item = item_selected + 1;
if (next_item >= num_item) {
next_item = 0;
}
display.clearDisplay();
display.setCursor(26, 8);
display.println(manu_name[prev_item]);
display.setCursor(26, 29);
display.println(manu_name[item_selected]);
display.setCursor(26, 50);
display.println(manu_name[next_item]);
display.drawBitmap(4, 2, epd_bitmap_allArray[prev_item], 16, 16, SSD1306_WHITE);
display.drawBitmap(4, 24, epd_bitmap_allArray[item_selected], 16, 16, SSD1306_WHITE);
display.drawBitmap(4, 46, epd_bitmap_allArray[next_item], 16, 16, SSD1306_WHITE);
display.drawBitmap(0, 22, epd_bitmap_allArray[4], 128, 21, SSD1306_WHITE);
display.display();
if (digitalRead(BUTTON_A) == LOW && millis() - lastButtonPress > debounceDelay) {
while (digitalRead(BUTTON_A) == LOW)
;
delay(200);
lastButtonPress = millis();
if (item_selected == 0) {
int preset_num_item = 5;
int preset_item_selected = 0;
int preset_prev_item;
int preset_next_item;
unsigned long preset_lastButtonPress = 0;
const int preset_debounceDelay = 200;
while (true) {
if (digitalRead(BUTTON_DOWN) == LOW && millis() - preset_lastButtonPress > preset_debounceDelay) {
preset_item_selected++;
if (preset_item_selected >= preset_num_item) preset_item_selected = 0;
preset_lastButtonPress = millis();
}
if (digitalRead(BUTTON_UP) == LOW && millis() - preset_lastButtonPress > preset_debounceDelay) {
preset_item_selected--;
if (preset_item_selected < 0) preset_item_selected = preset_num_item - 1;
preset_lastButtonPress = millis();
}
preset_prev_item = preset_item_selected - 1;
if (preset_prev_item < 0) preset_prev_item = preset_num_item - 1;
preset_next_item = preset_item_selected + 1;
if (preset_next_item >= preset_num_item) preset_next_item = 0;
display.clearDisplay();
display.setCursor(26, 8);
display.println(preset_motions_manu[preset_prev_item]);
display.setCursor(26, 29);
display.println(preset_motions_manu[preset_item_selected]);
display.setCursor(26, 50);
display.println(preset_motions_manu[preset_next_item]);
display.drawBitmap(4, 2, epd_bitmap_allArray[0], 16, 16, SSD1306_WHITE);
display.drawBitmap(4, 24, epd_bitmap_allArray[0], 16, 16, SSD1306_WHITE);
display.drawBitmap(4, 46, epd_bitmap_allArray[0], 16, 16, SSD1306_WHITE);
display.drawBitmap(0, 22, epd_bitmap_allArray[4], 128, 21, SSD1306_WHITE);
display.display();
//<-------------Calling Each function according to the Loock up table ----------------->
if (digitalRead(BUTTON_A) == LOW && millis() - preset_lastButtonPress > preset_debounceDelay) {
if (preset_item_selected == 0) highfive();
if (preset_item_selected == 1) Do180();
if (preset_item_selected == 2) pickup();
if (preset_item_selected == 3) Dance();
if (preset_item_selected == 4) delay(300);
break;
preset_lastButtonPress = millis();
}
}
}
if (item_selected == 1) {
Link();
}
if (item_selected == 2) {
testServoandConnection();
}
if (item_selected == 3) {
showAbout();
}
}
}