mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-29 17:19:50 +02:00
Oled2 (#834)
* WIP * WIP * Update platformio.ini * WIP * Cleanup * Update platformio.ini
This commit is contained in:
288
Grbl_Esp32/Custom/oled_basic.cpp
Normal file
288
Grbl_Esp32/Custom/oled_basic.cpp
Normal file
@@ -0,0 +1,288 @@
|
|||||||
|
/*
|
||||||
|
oled_basic.cpp
|
||||||
|
Part of Grbl_ESP32
|
||||||
|
|
||||||
|
copyright (c) 2018 - Bart Dring This file was modified for use on the ESP32
|
||||||
|
CPU. Do not use this with Grbl for atMega328P
|
||||||
|
|
||||||
|
Grbl is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Grbl is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
--------------------------------------------------------------
|
||||||
|
|
||||||
|
This is a minimal implentation of a display as a test project.
|
||||||
|
It is designed to be used with a machine that has no easily accessible serial connection
|
||||||
|
It shows basic status and connection information.
|
||||||
|
|
||||||
|
When in alarm mode it will show the current Wifi/BT paramaters and status
|
||||||
|
Most machines will start in alarm mode (needs homing)
|
||||||
|
If the machine is running a job from SD it will show the progress
|
||||||
|
In other modes it will show state and 3 axis DROs
|
||||||
|
Thats All!
|
||||||
|
|
||||||
|
Library Infor:
|
||||||
|
https://github.com/ThingPulse/esp8266-oled-ssd1306
|
||||||
|
|
||||||
|
Install to PlatformIO with this typed at the terminal
|
||||||
|
platformio lib install 562
|
||||||
|
|
||||||
|
Add this to your machine definition file
|
||||||
|
#define DISPLAY_CODE_FILENAME "Custom/oled_basic.cpp"
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Include the correct display library
|
||||||
|
|
||||||
|
#include "SSD1306Wire.h" // legacy: #include "SSD1306.h"
|
||||||
|
#include "../src/WebUI/WebSettings.h"
|
||||||
|
|
||||||
|
#ifndef OLED_ADDRESS
|
||||||
|
# define OLED_ADDRESS 0x3c
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef OLED_SDA
|
||||||
|
# define OLED_SDA GPIO_NUM_14
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef OLED_SCL
|
||||||
|
# define OLED_SCL GPIO_NUM_13
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef OLED_GEOMETRY
|
||||||
|
# define OLED_GEOMETRY GEOMETRY_128_64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SSD1306Wire display(OLED_ADDRESS, OLED_SDA, OLED_SCL, OLED_GEOMETRY);
|
||||||
|
|
||||||
|
static TaskHandle_t displayUpdateTaskHandle = 0;
|
||||||
|
|
||||||
|
// returns the position of a machine axis
|
||||||
|
// wpos =true for corrected work postion
|
||||||
|
float getPosition(uint8_t axis, bool wpos = true) {
|
||||||
|
float wco; // work coordinate system offset
|
||||||
|
|
||||||
|
float current_position = sys_position[axis] / axis_settings[axis]->steps_per_mm->get();
|
||||||
|
|
||||||
|
if (wpos) {
|
||||||
|
// Apply work coordinate offsets and tool length offset to current position.
|
||||||
|
wco = gc_state.coord_system[axis] + gc_state.coord_offset[axis];
|
||||||
|
if (axis == TOOL_LENGTH_OFFSET_AXIS) {
|
||||||
|
wco += gc_state.tool_length_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_position -= wco;
|
||||||
|
}
|
||||||
|
return current_position;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getStateText() {
|
||||||
|
String str = "";
|
||||||
|
|
||||||
|
switch (sys.state) {
|
||||||
|
case State::Idle:
|
||||||
|
str = "Idle";
|
||||||
|
break;
|
||||||
|
case State::Cycle:
|
||||||
|
str = "Run";
|
||||||
|
break;
|
||||||
|
case State::Hold:
|
||||||
|
if (!(sys.suspend.bit.jogCancel)) {
|
||||||
|
str = "Hold:";
|
||||||
|
sys.suspend.bit.holdComplete ? str += "0" : str += "1"; // Ready to resume
|
||||||
|
break;
|
||||||
|
} // Continues to print jog state during jog cancel.
|
||||||
|
case State::Jog:
|
||||||
|
str = "Jog";
|
||||||
|
break;
|
||||||
|
case State::Homing:
|
||||||
|
str = "Homing";
|
||||||
|
break;
|
||||||
|
case State::Alarm:
|
||||||
|
str = "Alarm";
|
||||||
|
break;
|
||||||
|
case State::CheckMode:
|
||||||
|
str = "Check";
|
||||||
|
break;
|
||||||
|
case State::SafetyDoor:
|
||||||
|
str = "Door:";
|
||||||
|
if (sys.suspend.bit.initiateRestore) {
|
||||||
|
str += "3"; // Restoring
|
||||||
|
} else {
|
||||||
|
if (sys.suspend.bit.retractComplete) {
|
||||||
|
sys.suspend.bit.safetyDoorAjar ? str += "1" : str += "0"; // Door ajar
|
||||||
|
// Door closed and ready to resume
|
||||||
|
} else {
|
||||||
|
str += "2"; // Retracting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case State::Sleep:
|
||||||
|
str = "Sleep";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This displays the status of the ESP32 Radios...BT, WiFi, etc
|
||||||
|
void displayRadioInfo() {
|
||||||
|
String radio_info = "";
|
||||||
|
|
||||||
|
const uint8_t row1 = 18;
|
||||||
|
const uint8_t row2 = 30;
|
||||||
|
const uint8_t row3 = 42;
|
||||||
|
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
display.setFont(ArialMT_Plain_10);
|
||||||
|
|
||||||
|
#ifdef ENABLE_BLUETOOTH
|
||||||
|
if (WebUI::wifi_radio_mode->get() == ESP_BT) {
|
||||||
|
radio_info = String("Bluetooth: ") + WebUI::bt_name->get();
|
||||||
|
display.drawString(0, row1, radio_info);
|
||||||
|
radio_info = String("Status: ") + String(WebUI::SerialBT.hasClient() ? "Connected" : "Not connected");
|
||||||
|
display.drawString(0, row2, radio_info);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_WIFI
|
||||||
|
if ((WiFi.getMode() == WIFI_MODE_STA) || (WiFi.getMode() == WIFI_MODE_APSTA)) {
|
||||||
|
radio_info = "STA SSID: " + WiFi.SSID();
|
||||||
|
display.drawString(0, row1, radio_info);
|
||||||
|
|
||||||
|
radio_info = "IP: " + WiFi.localIP().toString();
|
||||||
|
display.drawString(0, row2, radio_info);
|
||||||
|
|
||||||
|
radio_info = "Status: ";
|
||||||
|
(WiFi.status() == WL_CONNECTED) ? radio_info += "Connected" : radio_info += "Not connected";
|
||||||
|
display.drawString(0, row3, radio_info);
|
||||||
|
//}
|
||||||
|
} else if ((WiFi.getMode() == WIFI_MODE_AP) || (WiFi.getMode() == WIFI_MODE_APSTA)) {
|
||||||
|
radio_info = String("AP SSID: ") + WebUI::wifi_ap_ssid->get();
|
||||||
|
|
||||||
|
display.drawString(0, row1, radio_info);
|
||||||
|
|
||||||
|
radio_info = "IP: " + WiFi.softAPIP().toString();
|
||||||
|
display.drawString(0, row2, radio_info);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIFI_OR_BLUETOOTH
|
||||||
|
if (WebUI::wifi_radio_mode->get() == ESP_RADIO_OFF) {
|
||||||
|
display.drawString(0, row1, "Radio Mode: None");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
display.drawString(0, row1, "Wifi and Bluetooth Disabled");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayDRO() {
|
||||||
|
char axisVal[20];
|
||||||
|
|
||||||
|
display.setFont(ArialMT_Plain_16);
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
display.drawString(0, 13, String('X') + ":");
|
||||||
|
display.drawString(0, 30, "Y:");
|
||||||
|
display.drawString(0, 47, "Z:");
|
||||||
|
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||||
|
snprintf(axisVal, 20 - 1, "%.3f", getPosition(X_AXIS, true));
|
||||||
|
display.drawString(100, 13, axisVal);
|
||||||
|
|
||||||
|
snprintf(axisVal, 20 - 1, "%.3f", getPosition(Y_AXIS, true));
|
||||||
|
display.drawString(100, 30, axisVal);
|
||||||
|
|
||||||
|
snprintf(axisVal, 20 - 1, "%.3f", getPosition(Z_AXIS, true));
|
||||||
|
display.drawString(100, 47, axisVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayUpdate(void* pvParameters) {
|
||||||
|
TickType_t xLastWakeTime;
|
||||||
|
const TickType_t xDisplayFrequency = 100; // in ticks (typically ms)
|
||||||
|
xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time.
|
||||||
|
|
||||||
|
vTaskDelay(2500);
|
||||||
|
uint16_t sd_file_ticker = 0;
|
||||||
|
|
||||||
|
display.init();
|
||||||
|
display.flipScreenVertically();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
display.clear();
|
||||||
|
|
||||||
|
String state_string = getStateText();
|
||||||
|
|
||||||
|
state_string.toUpperCase();
|
||||||
|
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
display.setFont(ArialMT_Plain_16);
|
||||||
|
display.drawString(0, 0, state_string);
|
||||||
|
|
||||||
|
if (get_sd_state(false) == SDState::BusyPrinting) {
|
||||||
|
display.clear();
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
|
display.setFont(ArialMT_Plain_16);
|
||||||
|
state_string = "SD File";
|
||||||
|
for (int i = 0; i < sd_file_ticker % 10; i++) {
|
||||||
|
state_string += ".";
|
||||||
|
}
|
||||||
|
sd_file_ticker++;
|
||||||
|
display.drawString(25, 0, state_string);
|
||||||
|
|
||||||
|
int progress = sd_report_perc_complete();
|
||||||
|
// draw the progress bar
|
||||||
|
display.drawProgressBar(0, 45, 120, 10, progress);
|
||||||
|
|
||||||
|
// draw the percentage as String
|
||||||
|
display.setFont(ArialMT_Plain_16);
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||||
|
display.drawString(64, 25, String(progress) + "%");
|
||||||
|
|
||||||
|
} else if (sys.state == State::Alarm) {
|
||||||
|
displayRadioInfo();
|
||||||
|
} else {
|
||||||
|
displayDRO();
|
||||||
|
}
|
||||||
|
display.display();
|
||||||
|
|
||||||
|
vTaskDelayUntil(&xLastWakeTime, xDisplayFrequency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void display_init() {
|
||||||
|
// Initialising the UI will init the display too.
|
||||||
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Init Basic OLED SDA:%s SCL:%s", pinName(OLED_SDA), pinName(OLED_SCL));
|
||||||
|
|
||||||
|
display.init();
|
||||||
|
display.flipScreenVertically();
|
||||||
|
display.clear();
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||||
|
display.setFont(ArialMT_Plain_16);
|
||||||
|
|
||||||
|
String mach_name = MACHINE_NAME;
|
||||||
|
// remove characters from the end until the string fits
|
||||||
|
while (display.getStringWidth(mach_name) > 128) {
|
||||||
|
mach_name = mach_name.substring(0, mach_name.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
display.drawString(63, 0, mach_name);
|
||||||
|
display.display();
|
||||||
|
|
||||||
|
xTaskCreatePinnedToCore(displayUpdate, // task
|
||||||
|
"displayUpdateTask", // name for task
|
||||||
|
4096, // size of task stack
|
||||||
|
NULL, // parameters
|
||||||
|
1, // priority
|
||||||
|
&displayUpdateTaskHandle,
|
||||||
|
CONFIG_ARDUINO_RUNNING_CORE // must run the task on same core
|
||||||
|
// core
|
||||||
|
);
|
||||||
|
}
|
@@ -6,3 +6,7 @@
|
|||||||
#ifdef CUSTOM_CODE_FILENAME
|
#ifdef CUSTOM_CODE_FILENAME
|
||||||
# include CUSTOM_CODE_FILENAME
|
# include CUSTOM_CODE_FILENAME
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DISPLAY_CODE_FILENAME
|
||||||
|
# include DISPLAY_CODE_FILENAME
|
||||||
|
#endif
|
@@ -31,6 +31,7 @@ void grbl_init() {
|
|||||||
WiFi.enableAP(false);
|
WiFi.enableAP(false);
|
||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
serial_init(); // Setup serial baud rate and interrupts
|
serial_init(); // Setup serial baud rate and interrupts
|
||||||
|
display_init();
|
||||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Grbl_ESP32 Ver %s Date %s", GRBL_VERSION, GRBL_VERSION_BUILD); // print grbl_esp32 verion info
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Grbl_ESP32 Ver %s Date %s", GRBL_VERSION, GRBL_VERSION_BUILD); // print grbl_esp32 verion info
|
||||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Compiled with ESP32 SDK:%s", ESP.getSdkVersion()); // print the SDK version
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Compiled with ESP32 SDK:%s", ESP.getSdkVersion()); // print the SDK version
|
||||||
// show the map name at startup
|
// show the map name at startup
|
||||||
@@ -116,6 +117,7 @@ void run_once() {
|
|||||||
|
|
||||||
void __attribute__((weak)) machine_init() {}
|
void __attribute__((weak)) machine_init() {}
|
||||||
|
|
||||||
|
void __attribute__((weak)) display_init() {}
|
||||||
/*
|
/*
|
||||||
setup() and loop() in the Arduino .ino implements this control flow:
|
setup() and loop() in the Arduino .ino implements this control flow:
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
// Grbl versioning system
|
// Grbl versioning system
|
||||||
const char* const GRBL_VERSION = "1.3a";
|
const char* const GRBL_VERSION = "1.3a";
|
||||||
const char* const GRBL_VERSION_BUILD = "20210311";
|
const char* const GRBL_VERSION_BUILD = "20210319";
|
||||||
|
|
||||||
//#include <sdkconfig.h>
|
//#include <sdkconfig.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
@@ -65,6 +65,8 @@ const char* const GRBL_VERSION_BUILD = "20210311";
|
|||||||
|
|
||||||
#include "UserOutput.h"
|
#include "UserOutput.h"
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
// Do not guard this because it is needed for local files too
|
// Do not guard this because it is needed for local files too
|
||||||
#include "SDCard.h"
|
#include "SDCard.h"
|
||||||
|
|
||||||
@@ -90,8 +92,8 @@ const char* const GRBL_VERSION_BUILD = "20210311";
|
|||||||
void grbl_init();
|
void grbl_init();
|
||||||
void run_once();
|
void run_once();
|
||||||
|
|
||||||
// Called if USE_MACHINE_INIT is defined
|
void machine_init(); // weak definition in Grbl.cpp
|
||||||
void machine_init();
|
void display_init(); // weak definition in Grbl.cpp
|
||||||
|
|
||||||
bool user_defined_homing(uint8_t cycle_mask); // weak definition in Limits.cpp
|
bool user_defined_homing(uint8_t cycle_mask); // weak definition in Limits.cpp
|
||||||
|
|
||||||
|
@@ -1,8 +1,18 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
src_dir=Grbl_Esp32
|
src_dir = Grbl_Esp32
|
||||||
lib_dir=libraries
|
lib_dir = libraries
|
||||||
data_dir=Grbl_Esp32/data
|
data_dir = Grbl_Esp32/data
|
||||||
default_envs=release
|
default_envs = release
|
||||||
;extra_configs=debug.ini
|
;extra_configs=debug.ini
|
||||||
|
|
||||||
[common_env_data]
|
[common_env_data]
|
||||||
@@ -24,16 +34,14 @@ lib_deps_builtin =
|
|||||||
|
|
||||||
[common]
|
[common]
|
||||||
build_flags =
|
build_flags =
|
||||||
;-DMACHINE_FILENAME=test_drive.h ;Remove ";" from the beginning of this line and specify the machine file
|
;-DMACHINE_FILENAME=test_drive.h ;Remove ";" from the beginning of this line and specify the machine file
|
||||||
-DCORE_DEBUG_LEVEL=0
|
-DCORE_DEBUG_LEVEL=0
|
||||||
-Wno-unused-variable
|
-Wno-unused-variable
|
||||||
-Wno-unused-function
|
-Wno-unused-function
|
||||||
;-DDEBUG_REPORT_HEAP_SIZE
|
|
||||||
;-DDEBUG_REPORT_STACK_FREE
|
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
lib_deps =
|
;lib_deps =
|
||||||
TMCStepper@>=0.7.0,<1.0.0
|
; TMCStepper@>=0.7.0,<1.0.0
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
@@ -45,15 +53,20 @@ monitor_flags =
|
|||||||
--echo
|
--echo
|
||||||
--filter=esp32_exception_decoder
|
--filter=esp32_exception_decoder
|
||||||
board_build.f_cpu = 240000000L
|
board_build.f_cpu = 240000000L
|
||||||
; set frequency to 80MHz
|
|
||||||
board_build.f_flash = 80000000L
|
board_build.f_flash = 80000000L
|
||||||
board_build.flash_mode = qio
|
board_build.flash_mode = qio
|
||||||
build_flags = ${common.build_flags}
|
build_flags = ${common.build_flags}
|
||||||
src_filter =
|
src_filter =
|
||||||
+<*.h> +<*.s> +<*.S> +<*.cpp> +<*.c> +<*.ino> +<src/>
|
+<*.h> +<*.s> +<*.S> +<*.cpp> +<*.c> +<*.ino> +<src/>
|
||||||
-<.git/> -<data/> -<test/> -<tests/>
|
-<.git/> -<data/> -<test/> -<tests/>
|
||||||
|
|
||||||
[env:release]
|
[env:release]
|
||||||
|
lib_deps =
|
||||||
|
TMCStepper@>=0.7.0,<1.0.0
|
||||||
|
squix78/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0
|
||||||
|
|
||||||
[env:debug]
|
[env:debug]
|
||||||
build_type = debug
|
build_type = debug
|
||||||
|
lib_deps =
|
||||||
|
TMCStepper@>=0.7.0,<1.0.0
|
||||||
|
squix78/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0
|
||||||
|
Reference in New Issue
Block a user