Hi. Im using a ESP8226 Arduino with a 1331 OLED with colors. Im using this sketch
GitHub - alexrus/marax_timer wich i have modified for the OLED. Problem is the OLED uses D5 Pin wich is sclk. The sketch also uses D5 to communicate to get Temperatures from the Machine. If i use another free Pin to get Temp informations it shows weird signs in the Temp section. Ive tried different Power supplys or a 5v Power directly to the Board nothings changed.
Any Suggestions?
> #define D6 (12)
> #define D8 (15)
> #define RX (3)
>
> #define PUMP_PIN RX
>
> #include <Adafruit_SSD1331.h>
> #include <Adafruit_GFX.h>
> #include <SPI.h>
> #include <ESP8266WiFi.h>
> #include <Wire.h>
> #include <Timer.h>
> #include <SoftwareSerial.h>
>
> //Declare ESP8266 SPI pins:
> #define sclk 14 //D5
> #define mosi 13 //D7
> #define cs 4 //D2
> #define dc 5 //D1
>
> ///////////////////////
> #define clear() fillScreen(0)
>
> // Color definitions
> #define BLACK 0x0000
> #define BLUE 0x001F
> #define RED 0xF800
> #define GREEN 0x07E0
> #define CYAN 0x07FF
> #define MAGENTA 0xF81F
> #define YELLOW 0xFFE0
> #define WHITE 0xFFFF
>
> Adafruit_SSD1331 display = Adafruit_SSD1331(&SPI, cs, dc);
> SoftwareSerial mySerial(D8, D6);
> Timer t;
>
> bool displayOn = true;
> int timerCount = 0;
> int prevTimerCount = 0;
> bool timerStarted = false;
> long timerStartMillis = 0;
> long timerStopMillis = 0;
> long timerDisplayOffMillis = 0;
> long serialUpdateMillis = 0;
>
> const byte numChars = 32;
> char receivedChars[numChars];
> static byte ndx = 0;
> char endMarker = '\n';
> char rc;
>
>
> void setup() {
> WiFi.mode(WIFI_OFF);
>
> Serial.begin(9600);
> Serial.print("hello!");
> mySerial.begin(9600);
>
> pinMode(PUMP_PIN, INPUT_PULLUP);
> pinMode(LED_BUILTIN, OUTPUT);
> digitalWrite(LED_BUILTIN, HIGH);
>
> memset(receivedChars, 0, numChars );
>
> t.every(1000, updateDisplay);
> display.begin();
> display.clear();
> //display.display();
> mySerial.write(0x11);
>
> }
>
> void loop() {
> t.update();
> detectChanges();
> getMachineInput();
> }
>
> void getMachineInput() {
> while (mySerial.available() ) {
> serialUpdateMillis = millis();
> rc = mySerial.read();
>
> if (rc != endMarker) {
> receivedChars[ndx] = rc;
> ndx++;
> if (ndx >= numChars) {
> ndx = numChars - 1;
> }
> } else {
> receivedChars[ndx] = '\0';
> ndx = 0;
> Serial.println(receivedChars);
> }
> }
>
> if (millis() - serialUpdateMillis > 5000) {
> serialUpdateMillis = millis();
> memset(receivedChars, 0, numChars );
> Serial.println("Request serial update");
> mySerial.write(0x11);
> }
> }
>
> void detectChanges() {
> digitalWrite(LED_BUILTIN, digitalRead(PUMP_PIN));
> if (!timerStarted && !digitalRead(PUMP_PIN)) {
> timerStartMillis = millis();
> timerStarted = true;
> displayOn = true;
> Serial.println("Start pump");
> }
> if (timerStarted && digitalRead(PUMP_PIN)) {
> if (timerStopMillis == 0) {
> timerStopMillis = millis();
> }
> if (millis() - timerStopMillis > 500) {
> timerStarted = false;
> timerStopMillis = 0;
> timerDisplayOffMillis = millis();
> display.invertDisplay(false);
> Serial.println("Stop pump");
> }
> } else {
> timerStopMillis = 0;
> }
> if (!timerStarted && displayOn && timerDisplayOffMillis >= 0 && (millis() - timerDisplayOffMillis > 1000 * 60 * 60)) {
> timerDisplayOffMillis = 0;
> timerCount = 0;
> prevTimerCount = 0;
> displayOn = false;
> Serial.println("Sleep");
> }
> }
>
> String getTimer() {
> char outMin[2];
> if (timerStarted) {
> timerCount = (millis() - timerStartMillis ) / 1000;
> if (timerCount > 15) {
> prevTimerCount = timerCount;
> }
> } else {
> timerCount = prevTimerCount;
> }
> if (timerCount > 99) {
> return "99";
> }
> sprintf( outMin, "%02u", timerCount);
> return outMin;
> }
>
> void updateDisplay() {
> display.clear();
> if (displayOn) {
> if (timerStarted) {
> display.setTextSize(5);
> display.setCursor(20, 13);
> display.setTextColor(WHITE);
> display.print(getTimer());
> } else {
> // draw line
> display.drawLine(56, 0, 56, 64,BLUE );
> // draw time seconds
> display.setTextSize(3);
> display.setTextColor(WHITE);
> display.setCursor(display.width() / 2 - 1 + 13, 20);
> display.print(getTimer());
> // draw machine state C/S
> if (receivedChars[0] ) {
> display.setTextSize(1);
> display.setCursor(1, 1);
> if (String(receivedChars[0]) == "C") {
> display.print("C");
> } else if (String(receivedChars[0]) == "V") {
> display.print("S");
> } else {
> display.print("X");
>
> }
> }
> if (String(receivedChars).substring(18, 22) == "0000") {
> // not in boost heating mode
> // draw fill circle if heating on
> if (String(receivedChars[23]) == "1") {
> display.fillCircle(45, 7, 6, WHITE);
> }
> // draw empty circle if heating off
> if (String(receivedChars[23]) == "0") {
> display.drawCircle(45, 7, 6, WHITE);
> }
> } else {
> // in boost heating mode
> // draw fill rectangle if heating on
> if (String(receivedChars[23]) == "1") {
> display.fillRect(39, 1, 12, 12, WHITE);
> }
> // draw empty rectangle if heating off
> if (String(receivedChars[23]) == "0") {
> display.drawRect(39, 1, 12, 12, WHITE);
> }
> }
> // draw temperature
> if (receivedChars[14] && receivedChars[15] && receivedChars[16]) {
> display.setTextSize(1);
> display.setCursor(1, 20);
> if (String(receivedChars[14]) != "0") {
> display.print(String(receivedChars[14]));
> }
> display.print(String(receivedChars[15]));
> display.print(String(receivedChars[16]));
> display.print((char)247);
> if (String(receivedChars[14]) == "0") {
> display.print("C");
> }
> }
> // draw steam temperature
> if (receivedChars[6] && receivedChars[7] && receivedChars[8]) {
> display.setTextSize(1);
> display.setCursor(1, 48);
> if (String(receivedChars[6]) != "0") {
> display.print(String(receivedChars[6]));
> }
> display.print(String(receivedChars[7]));
> display.print(String(receivedChars[8]));
> display.print((char)247);
> display.print("C");
> }
> }
> }
> }