Start from scratch
This commit is contained in:
parent
e0c4e28bb4
commit
8334c5115c
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
src/config.h
|
||||
|
@ -17,3 +17,5 @@ lib_deps =
|
||||
adafruit/Adafruit GFX Library@^1.11.11
|
||||
adafruit/Adafruit SSD1306@^2.5.13
|
||||
chunkysteveo/OctoPrintAPI@^1.1.6
|
||||
moononournation/GFX Library for Arduino@^1.4.9
|
||||
monitor_speed = 115200
|
||||
|
@ -12,4 +12,10 @@
|
||||
#define SCREEN_WIDTH 128
|
||||
#define SCREEN_HEIGHT 64
|
||||
#define OLED_RESET -1
|
||||
#define FRAMERATE 8
|
||||
#define FRAMERATE 8
|
||||
|
||||
// Buttons and buzzer
|
||||
#define PIN_BTN_L 12 // D6
|
||||
#define PIN_BTN_M 13 // D7
|
||||
#define PIN_BTN_R 15 // D8
|
||||
#define PIN_BUZZER 0 // D3
|
72
src/main.cpp
72
src/main.cpp
@ -1,7 +1,73 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include "config.h"
|
||||
#include "setup.h"
|
||||
// Initialize display with defined dimensions and reset pin
|
||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Power On");
|
||||
|
||||
// Initialize the SSD1306 display
|
||||
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Adjust I2C address if needed
|
||||
Serial.println("SSD1306 allocation failed");
|
||||
for(;;); // Don't proceed, loop forever
|
||||
}
|
||||
|
||||
// Rotate the display 180 degrees
|
||||
display.setRotation(2);
|
||||
|
||||
// Clear the display buffer
|
||||
display.clearDisplay();
|
||||
|
||||
// Display initial message
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0, 0);
|
||||
display.print("Connecting to WiFi...");
|
||||
display.display();
|
||||
|
||||
// Connect to WiFi
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
Serial.print("Connecting to WiFi");
|
||||
|
||||
int attemptCount = 0;
|
||||
while (WiFi.status() != WL_CONNECTED && attemptCount < 20) { // Timeout after 20 attempts
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
display.print(".");
|
||||
display.display();
|
||||
attemptCount++;
|
||||
}
|
||||
|
||||
// Check if connected
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
Serial.println("\nConnected to WiFi!");
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
// Display connection success and IP address
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
display.print("WiFi Connected!");
|
||||
display.setCursor(0, 10);
|
||||
display.print("IP: ");
|
||||
display.print(WiFi.localIP());
|
||||
display.display();
|
||||
} else {
|
||||
Serial.println("\nFailed to connect to WiFi.");
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
display.print("WiFi Connection");
|
||||
display.setCursor(0, 10);
|
||||
display.print("Failed");
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
// Nothing to do here for now
|
||||
}
|
||||
|
35
src/setup.h
35
src/setup.h
@ -1,35 +0,0 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include <OctoPrintAPI.h>
|
||||
|
||||
String printerOperational;
|
||||
String printerPaused;
|
||||
String printerPrinting;
|
||||
String printerReady;
|
||||
String printerText;
|
||||
String printerHotend;
|
||||
String printerTarget;
|
||||
String payload;
|
||||
|
||||
WiFiClient client;
|
||||
|
||||
OctoprintApi api(client, ip, octoprint_httpPort, octoprint_apikey);
|
||||
|
||||
void setup() {
|
||||
|
||||
// Connect to wifi
|
||||
Serial.begin(115200);
|
||||
Serial.println("Connecting to WiFi...");
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WIFI_SSID);
|
||||
|
||||
Serial.print("OctoPrint URL: ");
|
||||
Serial.println(OCTOPRINT_URL);
|
||||
Serial.print("OctoPrint API Key: ");
|
||||
Serial.println(OCTOPRINT_API_KEY);
|
||||
}
|
Loading…
Reference in New Issue
Block a user