Skip to content

Commit 7660e8e

Browse files
author
Joel Crisp
committedMar 8, 2020
Add ESP32 and ili9341 files
1 parent eb7eb1e commit 7660e8e

File tree

6 files changed

+333
-30
lines changed

6 files changed

+333
-30
lines changed
 

‎.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@
3232
*.app
3333

3434
# EMACS backup files
35-
*~
35+
*~
36+
37+
# 3d files
38+
*.stl

‎openscad/ili9341.scad

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// all dimensions in mm
2+
// https://www.pjrc.com/store/display_ili9341_touch.html
3+
4+
screen_height = 50;
5+
screen_width = 69.2;
6+
screen_depth = 4;
7+
screen_clearance = 0.6;
8+
9+
pcb_height = 52;
10+
pcb_width = 87;
11+
pcb_depth = 6;
12+
13+
screen_offset_width = 1;
14+
screen_offset_height = 6.4;
15+
16+
hole_clearance=1.0;
17+
18+
// TODO: minkowski the top edges
19+
20+
module pcb_hole() {
21+
cylinder(h=pcb_depth+screen_depth+4,d=4-hole_clearance, center=true, $fn=32);
22+
}
23+
24+
module pcb_standoff() {
25+
cylinder(h=screen_depth+0.1,d=5, center=true, $fn=32);
26+
}
27+
28+
module display_ili9341_hull_void() {
29+
difference() {
30+
union() {
31+
translate([screen_offset_height-0.3, screen_offset_width-0.3,0]) {
32+
cube([screen_width+0.6,screen_height+0.6,screen_depth + screen_clearance]);
33+
}
34+
translate([0,0,-pcb_depth]) {
35+
cube([pcb_width,pcb_height,pcb_depth]);
36+
}
37+
// Additional clearance above PCB beyond screen end
38+
translate([0,1,0]) cube([screen_offset_height, pcb_height-2,screen_depth-1]);
39+
translate([pcb_width-10.4,1,0]) cube([10.4, pcb_height-2,screen_depth-1]);
40+
}
41+
translate([3,3,-pcb_depth/2]) pcb_hole();
42+
translate([pcb_width-6.92,3,-pcb_depth/2]) pcb_hole();
43+
translate([pcb_width-6.92,pcb_height-5,-pcb_depth/2]) pcb_hole();
44+
translate([3,pcb_height-5,-pcb_depth/2]) pcb_hole();
45+
46+
translate([3,3,screen_depth/2+0.1]) pcb_standoff();
47+
translate([pcb_width-6.92,3,screen_depth/2+0.1]) pcb_standoff();
48+
translate([pcb_width-6.92,pcb_height-5,screen_depth/2+0.1]) pcb_standoff();
49+
translate([3,pcb_height-5,screen_depth/2+0.1]) pcb_standoff();
50+
}
51+
}
52+
53+
union() {
54+
difference() {
55+
translate([-0.5,-0.5,3-pcb_depth]) {
56+
minkowski() {
57+
cube([pcb_width+1,pcb_height+1,(pcb_depth+screen_depth)/2]);
58+
cylinder(r=1,h=(pcb_depth+screen_depth)/2, center=true, $fn=32);
59+
}
60+
}
61+
display_ili9341_hull_void();
62+
}
63+
}
64+
65+
*display_ili9341_hull_void();

‎openscad/wemos_d32pro_esp32.scad

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// all dimensions in mm
2+
// https://docs.wemos.cc/en/latest/d32/d32_pro.html
3+
4+
pcb_width = 65;
5+
pcb_height = 25.4;
6+
pcb_depth = 6;
7+
8+
pcb_clearance = 0.2;
9+
10+
// TODO: minkowski edges
11+
12+
module pcb_hole() {
13+
cylinder(h=8, d=2, center=true, $fn=32);
14+
}
15+
16+
module d32pro_hull_void() {
17+
difference() {
18+
translate([-pcb_clearance/2,-pcb_clearance/2,0]) {
19+
cube([pcb_height+pcb_clearance,pcb_width+pcb_clearance,pcb_depth]);
20+
}
21+
22+
translate([2,2,4]) pcb_hole();
23+
translate([pcb_height-2,2,4]) pcb_hole();
24+
}
25+
}
26+
27+
*d32pro_hull_void();
28+
29+
difference() {
30+
translate([-0.5,-0.5,-0.5]) cube([26.4,66,7]);
31+
d32pro_hull_void();
32+
translate([-pcb_clearance/2,-pcb_clearance/2,-2]) {
33+
cube([25.4+pcb_clearance,65+pcb_clearance,3]);
34+
}
35+
}

‎sketches/btconnect/btconnect.ino

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#include <BLEDevice.h>
2+
#include <BLEUtils.h>
3+
#include <BLEServer.h>
4+
#include <ESPDateTime.h>
5+
#include <string>
6+
7+
// See the following for generating UUIDs:
8+
// https://www.uuidgenerator.net/
9+
10+
#define SERVICE_UUID "0fab68b8-eb4d-4abc-9d6c-89fd057d5572"
11+
#define CHARACTERISTIC_UUID "d653575e-2b5b-4db2-a6c8-b93ad899690f"
12+
#define CHARACTERISTIC_MILLI_UUID "30989c48-03c0-4faa-8123-d27daee72554"
13+
14+
15+
// Define must come before GxEPD2 includes
16+
#define ENABLE_GxEPD2_GFX 1
17+
#include <GxEPD2_BW.h>
18+
#include <GxEPD2_3C.h>
19+
#include <Fonts/FreeMonoBold18pt7b.h>
20+
// 264x176
21+
22+
void timestamp();
23+
void initDisplay(GxEPD2_GFX& display);
24+
void helloWorld(GxEPD2_GFX& display, const char *msg);
25+
GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
26+
27+
#define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())
28+
29+
#define LED_ON LOW
30+
#define LED_OFF HIGH
31+
32+
String deviceName = "ESP_" + String(ESP_getChipId(), HEX);
33+
34+
const int PIN_LED = 22;
35+
36+
BLECharacteristic *pCharacteristicMsg;
37+
BLECharacteristic *pCharacteristicMilli;
38+
void setup() {
39+
pinMode(PIN_LED, OUTPUT);
40+
41+
// put your setup code here, to run once:
42+
Serial.begin(115200);
43+
DateTime.setTime(1262304000L);
44+
initDisplay(display);
45+
46+
Serial.println("Starting BLE work!");
47+
48+
BLEDevice::init(deviceName.c_str());
49+
BLEServer *pServer = BLEDevice::createServer();
50+
BLEService *pService = pServer->createService(SERVICE_UUID);
51+
pCharacteristicMsg = pService->createCharacteristic(
52+
CHARACTERISTIC_UUID,
53+
BLECharacteristic::PROPERTY_READ |
54+
BLECharacteristic::PROPERTY_WRITE
55+
);
56+
57+
pCharacteristicMsg->setValue("Hello World");
58+
pCharacteristicMilli = pService->createCharacteristic(
59+
CHARACTERISTIC_MILLI_UUID,
60+
BLECharacteristic::PROPERTY_READ |
61+
BLECharacteristic::PROPERTY_WRITE
62+
);
63+
pCharacteristicMilli->setValue("");
64+
pService->start();
65+
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
66+
pAdvertising->addServiceUUID(SERVICE_UUID);
67+
pAdvertising->setScanResponse(true);
68+
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
69+
pAdvertising->setMinPreferred(0x12);
70+
BLEDevice::startAdvertising();
71+
digitalWrite(PIN_LED, LED_ON);
72+
73+
Serial.println("Characteristic defined! Now you can read it in your phone!");
74+
}
75+
76+
std::string lastValue = "";
77+
78+
int lastMin = -1;
79+
80+
void loop() {
81+
std::string milli = pCharacteristicMilli->getValue();
82+
if (milli != "" ) {
83+
DateTime.setTime(atol(milli.c_str()));
84+
pCharacteristicMilli->setValue("");
85+
}
86+
// put your main code here, to run repeatedly:
87+
std::string value = pCharacteristicMsg->getValue();
88+
if (value != lastValue ) {
89+
if (value[0] == '!') display.setTextColor(GxEPD_RED);
90+
else display.setTextColor(GxEPD_BLACK);
91+
helloWorld(display, value.c_str());
92+
lastValue = value;
93+
lastMin = -1;
94+
}
95+
int min = DateTime.getParts().getMinutes();
96+
if (lastMin != min) {
97+
lastMin = min;
98+
timestamp();
99+
}
100+
delay(1000);
101+
}
102+
103+
void initDisplay(GxEPD2_GFX& display) {
104+
display.init(115200);
105+
display.setRotation(1);
106+
display.setFont(&FreeMonoBold18pt7b);
107+
display.setTextColor(GxEPD_BLACK);
108+
display.setFullWindow();
109+
display.fillScreen(GxEPD_WHITE);
110+
display.display(false);
111+
}
112+
113+
void printDigits(byte digits) {
114+
// utility function for digital clock display: prints preceding colon and leading 0
115+
display.print(":");
116+
if (digits < 10)
117+
display.print('0');
118+
display.print(digits, DEC);
119+
}
120+
121+
void timestamp() {
122+
display.setPartialWindow(0, 0, 128, 32);
123+
display.firstPage();
124+
do {
125+
display.fillRect(0, 0, 128, 32, GxEPD_WHITE);
126+
display.drawRect(1, 1, 126, 30, GxEPD_BLACK);
127+
display.drawRect(2, 2, 125, 29, GxEPD_BLACK);
128+
display.setCursor(12, 26);
129+
display.setTextColor(GxEPD_BLACK);
130+
String nowStr = DateTime.format("%l:%M");
131+
display.print(nowStr);
132+
}
133+
while (display.nextPage());
134+
}
135+
136+
void helloWorld(GxEPD2_GFX& display, const char* msg)
137+
{
138+
display.setFullWindow();
139+
int16_t tbx, tby; uint16_t tbw, tbh;
140+
display.getTextBounds(msg, 0, 0, &tbx, &tby, &tbw, &tbh);
141+
// center bounding box by transposition of origin:
142+
uint16_t x = ((display.width() - tbw) / 2) - tbx;
143+
uint16_t y = ((display.height() - tbh) / 2) - tby;
144+
display.fillScreen(GxEPD_WHITE);
145+
display.setCursor(x, y);
146+
display.print(msg);
147+
display.display(false);
148+
}

‎sketches/tft/tft.ino

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <Arduino.h>
2+
#include <TFT_eSPI.h>
3+
#include <SPI.h>
4+
5+
TFT_eSPI tft = TFT_eSPI();
6+
7+
#define PIN_LED 5
8+
#define ON LOW
9+
#define OFF HIGH
10+
#define TFT_GREY 0x5AEB
11+
12+
#define TFT_BL_ON HIGH
13+
#define TFT_BL_OFF LOW
14+
15+
void setup() {
16+
tft.init();
17+
tft.setRotation(1);
18+
19+
pinMode(PIN_LED, OUTPUT);
20+
digitalWrite(PIN_LED,ON);
21+
pinMode(TFT_BL,OUTPUT);
22+
digitalWrite(TFT_BL,TFT_BL_ON);
23+
}
24+
25+
void loop() {
26+
// Fill screen with grey so we can see the effect of printing with and without
27+
// a background colour defined
28+
tft.fillScreen(TFT_GREY);
29+
30+
// Set "cursor" at top left corner of display (0,0) and select font 2
31+
// (cursor will move to next line automatically during printing with 'tft.println'
32+
// or stay on the line is there is room for the text with tft.print)
33+
tft.setCursor(0, 0, 2);
34+
// Set the font colour to be white with a black background, set text size multiplier to 1
35+
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextSize(1);
36+
// We can now plot text on screen using the "print" class
37+
tft.println("Hello World!");
38+
39+
40+
while (true) {
41+
delay(1000);
42+
}
43+
}

‎sketches/wificonnect/wificonnect/wificonnect.ino ‎sketches/wificonnect/wificonnect.ino

+38-29
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
1+
#include <esp_wifi.h>
2+
#include <WiFi.h>
3+
#include <WiFiClient.h>
4+
// SPI is used by WiFi library
25
#include <SPI.h>
3-
#define ENABLE_GxEPD2_GFX 1
46

7+
// Define must come before GxEPD2 includes
8+
#define ENABLE_GxEPD2_GFX 1
59
#include <GxEPD2_BW.h>
610
#include <GxEPD2_3C.h>
711
#include <Fonts/FreeMonoBold9pt7b.h>
12+
// 264x176
813

14+
void initDisplay(GxEPD2_GFX& display);
915
void helloWorld(GxEPD2_GFX& display, const char *msg);
1016
GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
1117

@@ -14,25 +20,21 @@ char *ip_to_char(uint32_t ip);
1420
#define COLORED 0
1521
#define UNCOLORED 1
1622

17-
#include <esp_wifi.h>
18-
#include <WiFi.h>
19-
#include <WiFiClient.h>
20-
2123
#define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())
2224

2325
#define LED_ON LOW
2426
#define LED_OFF HIGH
2527

2628
// SSID and PW for Config Portal
2729
String ssid = "ESP_" + String(ESP_getChipId(), HEX);
28-
const char* password = "your_password";
30+
const char* password = "setup";
2931

3032
// SSID and PW for your Router
3133
String Router_SSID;
3234
String Router_Pass;
3335

36+
// Define must come before EPS_WiFiManager include
3437
#define USE_AVAILABLE_PAGES true
35-
3638
#include <ESP_WiFiManager.h>
3739

3840
const int PIN_LED = 22;
@@ -71,26 +73,25 @@ void check_status()
7173
}
7274
}
7375

76+
char textBuffer[80];
77+
7478
void setup() {
7579
pinMode(PIN_LED, OUTPUT);
7680
digitalWrite(PIN_LED, LED_ON);
7781

7882
// put your setup code here, to run once:
7983
Serial.begin(115200);
8084

81-
unsigned long startedAt = millis();
85+
initDisplay(display);
8286

83-
Serial.println("Hello world");
87+
unsigned long startedAt = millis();
8488

85-
delay(100);
86-
display.init(115200);
87-
// first update should be full refresh
88-
helloWorld(display, "Waiting for Network");
89+
strcpy(textBuffer, "Hello ");
90+
strcat(textBuffer, ssid.c_str());
91+
helloWorld(display, textBuffer);
8992

9093
delay(1000);
9194

92-
digitalWrite(PIN_LED, LED_OFF); // turn the LED on by making the voltage LOW to tell us we are in configuration mode.
93-
9495
ESP_WiFiManager ESP_wifiManager;
9596
ESP_wifiManager.setMinimumSignalQuality(-1);
9697
// Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
@@ -109,7 +110,6 @@ void setup() {
109110
//Check if there is stored WiFi router/password credentials.
110111
//If not found, device will remain in configuration mode until switched off via webserver.
111112
Serial.print("Opening configuration portal.");
112-
digitalWrite(PIN_LED, LED_ON);
113113

114114
if (Router_SSID != "")
115115
{
@@ -122,6 +122,10 @@ void setup() {
122122
// SSID to uppercase
123123
ssid.toUpperCase();
124124

125+
strcpy(textBuffer, "Start AP ");
126+
strcat(textBuffer, ssid.c_str());
127+
helloWorld(display, textBuffer);
128+
125129
//it starts an access point
126130
//and goes into a blocking loop awaiting configuration
127131
if (!ESP_wifiManager.startConfigPortal((const char *) ssid.c_str(), password))
@@ -137,8 +141,9 @@ void setup() {
137141
#define WHILE_LOOP_DELAY 200L
138142
#define WHILE_LOOP_STEPS (WIFI_CONNECT_TIMEOUT / ( 3 * WHILE_LOOP_DELAY ))
139143

140-
startedAt = millis();
144+
helloWorld(display, "Waiting for Network");
141145

146+
startedAt = millis();
142147
while ( (WiFi.status() != WL_CONNECTED) && (millis() - startedAt < WIFI_CONNECT_TIMEOUT ) )
143148
{
144149
WiFi.mode(WIFI_STA);
@@ -174,6 +179,7 @@ void setup() {
174179
void loop() {
175180
// put your main code here, to run repeatedly:
176181
check_status();
182+
delay(5000);
177183
}
178184

179185
static char ipCstring[16]; //size the char array large enough to hold 4 x 3 digit numbers + 3 x dot + null terminator
@@ -188,23 +194,26 @@ char *ip_to_char(const uint32_t ip) {
188194
}
189195
return ipCstring;
190196
}
191-
void helloWorld(GxEPD2_GFX& display, const char* msg)
192-
{
197+
198+
void initDisplay(GxEPD2_GFX& display) {
199+
display.init(115200);
193200
display.setRotation(1);
194201
display.setFont(&FreeMonoBold9pt7b);
195202
display.setTextColor(GxEPD_BLACK);
203+
display.setFullWindow();
204+
display.fillScreen(GxEPD_WHITE);
205+
display.display(false);
206+
}
207+
208+
void helloWorld(GxEPD2_GFX& display, const char* msg)
209+
{
196210
int16_t tbx, tby; uint16_t tbw, tbh;
197211
display.getTextBounds(msg, 0, 0, &tbx, &tby, &tbw, &tbh);
198212
// center bounding box by transposition of origin:
199213
uint16_t x = ((display.width() - tbw) / 2) - tbx;
200214
uint16_t y = ((display.height() - tbh) / 2) - tby;
201-
display.setFullWindow();
202-
display.firstPage();
203-
do
204-
{
205-
display.fillScreen(GxEPD_WHITE);
206-
display.setCursor(x, y);
207-
display.print(msg);
208-
}
209-
while (display.nextPage());
215+
display.fillScreen(GxEPD_WHITE);
216+
display.setCursor(x, y);
217+
display.print(msg);
218+
display.display(false);
210219
}

0 commit comments

Comments
 (0)
Please sign in to comment.