-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathobd2-oled-arduino.ino
493 lines (434 loc) · 20.7 KB
/
obd2-oled-arduino.ino
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
483
484
485
486
487
488
489
490
491
492
493
/*********************************************************************
Golf MK6 CANBUS OLED DISPLAY
- Created by Davey Kropf
*********************************************************************/
#include <Canbus.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSansBold12pt7b.h>
#include <Fonts/FreeSansBold18pt7b.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
// 'Volkswagen', 64x32px
const unsigned char startupBitmap [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x1f, 0x80, 0x00, 0x00,
0x00, 0x00, 0x03, 0x9c, 0x31, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0c, 0x30, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x07, 0x0e, 0x70, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0x86, 0x61, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x0f, 0x86, 0xe1, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x83, 0xc3, 0xb0, 0x00, 0x00,
0x00, 0x00, 0x0d, 0xc3, 0xc3, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xc0, 0x07, 0x30, 0x00, 0x00,
0x00, 0x00, 0x0c, 0xe0, 0x06, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x63, 0xce, 0x30, 0x00, 0x00,
0x00, 0x00, 0x0c, 0x77, 0xce, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x36, 0x6c, 0x70, 0x00, 0x00,
0x00, 0x00, 0x06, 0x3e, 0x7c, 0x60, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1c, 0x78, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x03, 0x1c, 0x39, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0x88, 0x13, 0x80, 0x00, 0x00,
0x00, 0x00, 0x01, 0xe8, 0x17, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'sleep-icon', 64x32px
const unsigned char standbyBitmap [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x04, 0x20, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0e, 0x70, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x04, 0x20, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00,
0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char batteryBitmap [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0xf8, 0x00, 0x00,
0x00, 0x00, 0x1f, 0x80, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x01, 0xf8, 0x00, 0x00,
0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00,
0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x00, 0x01, 0xf9, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xf9, 0xff, 0xff, 0xff, 0x80, 0x00,
0x00, 0x01, 0xe0, 0x7f, 0xff, 0x07, 0x80, 0x00, 0x00, 0x01, 0xe0, 0x7f, 0xff, 0x07, 0x80, 0x00,
0x00, 0x01, 0xf9, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xf9, 0xff, 0xff, 0xff, 0x80, 0x00,
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char oilBitmap [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xe0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x18, 0x00, 0x07, 0x00, 0x00,
0x00, 0x06, 0x3f, 0x18, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x06, 0x0f, 0xff, 0x80, 0xfe, 0x00, 0x00,
0x00, 0x07, 0x0f, 0xff, 0xc3, 0xfc, 0x00, 0x00, 0x00, 0x07, 0xec, 0x00, 0xff, 0xb8, 0x00, 0x00,
0x00, 0x00, 0xfc, 0x00, 0x7c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x30, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x0c, 0x00, 0x01, 0xc0, 0x40, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x03, 0x80, 0x60, 0x00,
0x00, 0x00, 0x0c, 0x00, 0x07, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0e, 0x00, 0xe0, 0x00,
0x00, 0x00, 0x0f, 0xff, 0xfc, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'engine-rpm', 64x32px
const unsigned char engineRPMBitmap [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf1, 0x8f, 0x80, 0x00, 0x00,
0x00, 0x00, 0x03, 0xf1, 0x8f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0x90, 0x09, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x70, 0x00, 0x00,
0x00, 0x00, 0x0f, 0x80, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x06, 0x38, 0x00, 0x00,
0x00, 0x00, 0x1c, 0x00, 0x1c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x18, 0x03, 0xf8, 0x18, 0x00, 0x00,
0x00, 0x00, 0x1c, 0x07, 0xe0, 0x38, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x07, 0xe0, 0x78, 0x00, 0x00,
0x00, 0x00, 0x18, 0x03, 0xc0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x01, 0x80, 0x38, 0x00, 0x00,
0x00, 0x00, 0x1c, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0xb8, 0x00, 0x00,
0x00, 0x00, 0x0f, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x70, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'engine-coolant', 64x32px
const unsigned char engineCoolantBitmap [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x31, 0xcc, 0x07, 0x00, 0x00,
0x00, 0x00, 0xf0, 0x73, 0xce, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xe7, 0xe7, 0xfe, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xc7, 0xe3, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x07, 0xe0, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x40, 0x07, 0xe0, 0x02, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x39, 0x8c, 0x07, 0x00, 0x00,
0x00, 0x00, 0xf0, 0x7c, 0x3e, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xfe, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xcf, 0xf3, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x07, 0x03, 0xc0, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'intake-temp', 64x32px
const unsigned char intakeTempBitmap [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x01, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3f, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x01, 0xfe, 0x00, 0x00,
0x00, 0x00, 0x00, 0x63, 0x81, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x81, 0xfe, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x01, 0xff, 0xfe, 0x01, 0xc0, 0x00, 0x00,
0x00, 0x01, 0xff, 0xfc, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xe1, 0xc0, 0x00, 0x00,
0x00, 0x01, 0xff, 0xff, 0xf1, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0xfe, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x19, 0xff, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x0c, 0x19, 0xfe, 0x00, 0x00,
0x00, 0x01, 0xff, 0x8e, 0x39, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc7, 0xf1, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc3, 0xe1, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x38, 0xc0, 0x83, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x19, 0xc0, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x07, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 5;
// Variables will change:
int totalObdModusOptions = 6;
int currentObdModus = 0;
int lastModusBeforeSleep = 0;
int buttonState;
int lastButtonState = HIGH;
int inStandbyModus = false;
bool shouldShowIcon = true;
bool isShowingIcon = false;
unsigned long timeToShowIcon = 1000;
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
unsigned long previousMillis = 0;
unsigned long previousLastCheckResponseMillis = 0;
const long updateDataIntervalShort = 50;
const long updateDataIntervalLong = 500;
const long updateDataIntervalStandby = 2000;
const long checkForLastResponseInterval = 1000;
char buffer[456]; // Canbus data will be temporarily stored to this buffer before being outputted to the display
char oilTempDisplayBuffer[100];
// Variables for calculating and reading OIL_TEMP
int oilTempSensorPin = 0; // Pin: A0
int oilTempRawValue = 0;
int oilTempVin = 5;
float oilTempVout = 0;
float oilTempR1 = 1000;
float oilTempR2 = 0;
float oilTempBuffer = 0;
float oilTempResistance = 0;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
Serial.println("Golf MK6 CANBUS DISPLAY");
showStartupLogo();
if (Canbus.init(CANSPEED_500)) /* Initialise MCP2515 CAN controller at the specified speed */
{
Serial.println("CAN Init ok");
showCanbusInitResponse(true);
} else
{
Serial.println("Can't init CAN");
showCanbusInitResponse(false);
}
delay(1000);
resetValues(millis());
}
void loop() {
unsigned long currentMillis = millis();
// milis van response opslaan
// Als laatste response ouder is dan 4 seconden, dan standby aan.
// In standby de channel ENGINE_RUNTIME checken. Bij response, standby weer uit.
checkForButtonChanges(currentMillis);
checkForStandbyMode(currentMillis);
if (shouldShowIcon) {
showIcon(currentMillis);
} else {
updateData(currentMillis);
}
checkForLastResponse(currentMillis);
}
void checkForButtonChanges(unsigned long currentMillis) {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = currentMillis;
}
if ((currentMillis - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
currentObdModus++;
if (currentObdModus > (totalObdModusOptions - 1)) {
currentObdModus = 0;
}
resetValues(currentMillis);
}
}
}
lastButtonState = reading;
}
void checkForStandbyMode(unsigned long currentMillis) {
if (currentObdModus == 5 && !shouldShowIcon && !inStandbyModus) {
inStandbyModus = true;
sleepDisplay();
} else if (currentObdModus != 5 && inStandbyModus) {
inStandbyModus = false;
wakeDisplay();
showStartupLogo();
resetValues(millis());
}
}
void showStartupLogo() {
display.clearDisplay();
display.drawBitmap(0, 0, startupBitmap, 64, 32, WHITE);
display.display();
delay(2000);
}
void resetValues(unsigned long currentMillis) {
shouldShowIcon = true;
isShowingIcon = false;
previousMillis = currentMillis;
memset(buffer, 0, sizeof(buffer));
}
void showIcon(unsigned long currentMillis) {
if (!isShowingIcon) {
isShowingIcon = true;
display.clearDisplay();
switch (currentObdModus) {
case 0: // ECU_VOLTAGE
display.drawBitmap(0, 0, batteryBitmap, 64, 32, WHITE);
break;
case 1: // OIL_TEMP
display.drawBitmap(0, 0, oilBitmap, 64, 32, WHITE);
break;
case 2: // ENGINE_COOLANT_TEMP
display.drawBitmap(0, 0, engineCoolantBitmap, 64, 32, WHITE);
break;
case 3: // INTAKE_TEMP
display.drawBitmap(0, 0, intakeTempBitmap, 64, 32, WHITE);
break;
case 4: // ENGINE_RPM
display.drawBitmap(0, 0, engineRPMBitmap, 64, 32, WHITE);
break;
case 5: // STANDBY
display.drawBitmap(0, 0, standbyBitmap, 64, 32, WHITE);
break;
}
display.display();
}
if ((currentMillis - previousMillis) > timeToShowIcon) {
shouldShowIcon = false;
isShowingIcon = false;
}
}
void updateData(unsigned long currentMillis) {
long currentUpdateDataInterval;
if (currentObdModus == 4) {
currentUpdateDataInterval = updateDataIntervalShort;
} else if (currentObdModus == 5) {
currentUpdateDataInterval = updateDataIntervalStandby;
} else {
currentUpdateDataInterval = updateDataIntervalLong;
}
if (currentMillis - previousMillis >= currentUpdateDataInterval) {
switch (currentObdModus) {
case 0: // ECU_VOLTAGE
Canbus.ecu_req(ECU_VOLTAGE, buffer);
showVoltage(buffer);
break;
case 1: // OIL TEMP
// Just ask for some data from OBD, otherwise the display will turn into standby mode.
Canbus.ecu_req(ENGINE_RUNTIME, buffer);
readOilTemperatureSensor();
showTemperature(oilTempDisplayBuffer);
break;
case 2: // ENGINE_COOLANT_TEMP
Canbus.ecu_req(ENGINE_COOLANT_TEMP, buffer);
showTemperature(buffer);
break;
case 3: // INTAKE_TEMP
Canbus.ecu_req(INTAKE_TEMP, buffer);
showTemperature(buffer);
break;
case 4: // ENGINE_RPM
Canbus.ecu_req(ENGINE_RPM, buffer);
showEngineRPM(buffer);
break;
case 5: // ENGINE_RUNTIME
Canbus.ecu_req(ENGINE_RUNTIME, buffer);
break;
}
previousMillis = currentMillis;
}
}
void checkForLastResponse(unsigned long currentMillis) {
if (currentMillis - previousLastCheckResponseMillis >= checkForLastResponseInterval) {
unsigned long lastResponse = Canbus.last_response();
unsigned long diff = currentMillis - lastResponse;
if (diff > 5000 && !inStandbyModus && currentObdModus != 5) {
lastModusBeforeSleep = currentObdModus;
currentObdModus = 5;
resetValues(currentMillis);
}
if (diff < 2000 && currentObdModus == 5 && inStandbyModus) {
currentObdModus = lastModusBeforeSleep;
resetValues(currentMillis);
}
previousLastCheckResponseMillis = currentMillis;
}
}
void showVoltage(char voltage[]) {
if (strlen(voltage) == 0 || voltage == "") return;
display.clearDisplay();
display.setFont(&FreeSansBold12pt7b);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(6, 24);
display.print(voltage);
display.setCursor(54, 24);
display.setFont();
display.setTextSize(1);
display.println("v");
display.display();
}
void showTemperature(char temperature[]) {
if (strlen(temperature) == 0 || temperature == "") return;
display.clearDisplay();
if (strlen(temperature) < 3) {
display.setFont(&FreeSansBold18pt7b);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(6, 28);
display.print(temperature);
display.setCursor(48, 13);
} else {
display.setFont(&FreeSansBold12pt7b);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(6, 24);
display.print(temperature);
display.setCursor(48, 15);
}
display.setFont();
display.setTextSize(1);
display.print((char)247);
display.println("C");
display.display();
}
void showEngineRPM(char rpm[]) {
if (strlen(rpm) == 0 || rpm == "") return;
display.clearDisplay();
display.setFont(&FreeSansBold12pt7b);
display.setTextSize(1);
display.setTextColor(WHITE);
if (strlen(rpm) < 2) {
display.setCursor(26, 19);
} else if (strlen(rpm) < 4) {
display.setCursor(12, 19);
} else {
display.setCursor(6, 19);
}
display.print(rpm);
display.setFont();
display.setTextSize(1);
display.setCursor(24, 23);
display.println("rpm");
display.display();
}
void showCanbusInitResponse(bool success) {
display.clearDisplay();
display.setFont(&FreeSansBold12pt7b);
display.setTextSize(1);
display.setTextColor(WHITE);
if (success) {
display.setCursor(14, 24);
display.print("OK");
} else {
display.setCursor(6, 24);
display.print("FAIL");
}
display.display();
}
void sleepDisplay() {
display.ssd1306_command(SSD1306_DISPLAYOFF);
}
void wakeDisplay() {
display.ssd1306_command(SSD1306_DISPLAYON);
}
void readOilTemperatureSensor() {
oilTempRawValue = analogRead(oilTempSensorPin);
if (oilTempRawValue) {
oilTempBuffer = oilTempRawValue * oilTempVin;
oilTempVout = (oilTempBuffer) / 1024.0;
oilTempBuffer = (oilTempVin / oilTempVout) - 1;
oilTempR2 = oilTempR1 * oilTempBuffer;
oilTempResistance = oilTempR2;
float tempInKelvin = log(oilTempResistance);
tempInKelvin = 1 / (9.3058310e-4 + (3.7101259e-4 * tempInKelvin) + (-5.8947468e-7 * tempInKelvin * tempInKelvin * tempInKelvin)); // Temperature in Kelvin
float tempInCelsius = tempInKelvin - 273.15;
sprintf(oilTempDisplayBuffer,"%d",(int) tempInCelsius);
}
}