• Система автоматизации с открытым исходным кодом на базе esp8266/esp32 микроконтроллеров и приложения IoT Manager. Наша группа в Telegram

Oled дисплей

Georik13

New member
Доброго времени суток уважаемые форумчане,
у меня есть 2 платы WEMOS D1 MINI и WEMOS D1 MINI PRO и один дисплей Oled 0.96 128x64 работающий по I2C. Обе платы прошиты одинаково (см. код ниже), однако почему-то когда я подключаю дисплей к первой плате WEMOS D1 MINI (пины V5, grd, D3 для SDA и D4 для SCL) дисплей работает, а когда я подключаю на те же пины WEMOS D1 MINI PRO дисплей даже не загорается. Подскажите, пожалуйста, в чем может быть причина? Может нужны другие библиотеки? Обе платы прошиваются и в мониторе порта работают.

Вот код:

Код:
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <OpenTherm.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XX";

// Use Virtual pin 0 for current room temperature display
#define ROOM_TEMP_PIN V0
// Use Virtual pin 1 for setpoint manage & display
#define SETPOINT_PIN V1
// Use Virtual pin 2 for modulation display
#define MODULATION_PIN V2
// Use Virtual pin 3 for error display
#define ERR_PIN V3
// Use Virtual pin 4 hotwater temperature
#define T_hot_water V4
// Use Virtual pin 5 for boiler temperature display
#define BOILER_TEMP_PIN V5
// Use Virtual pin 6 for boiler pressure display
#define BOILER_PRESSURE_PIN V6

//дисплей:
#define BLUE 0x001F
#define YELLOW 0xFFE0
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
#define OLED_SDA   D3   // GPIO0
#define OLED_SCL   D4   // GPIO0

TwoWire myWire;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &myWire, OLED_RESET);


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XX";
char pass[] = "XXX";

//Master OpenTherm Shield pins configuration
const int OT_IN_PIN = 4;  //4 for ESP8266 (D2), 21 for ESP32
const int OT_OUT_PIN = 5; //5 for ESP8266 (D1), 22 for ESP32

//Temperature sensor pin
const int ROOM_TEMP_SENSOR_PIN = 14; //14 for ESP8266 (D5), 18 for ESP32

//buttons pins
const int BUTTON1_PIN = 15; // Кнопка повышения температуры
const int BUTTON2_PIN = 13; // Кнопка понижения температуры

float sp = 20, //set point
t = 0, //current temperature
t_last = 0, //prior temperature
ierr = 0, //integral error
dt = 0, //time between measurements
op = 0; //PID controller output
unsigned long ts = 0, new_ts = 0; //timestamp
float result2 = 0;
float result4 = 0;
float result5 = 0;
float result6 = 0;
float old_sp = sp;
bool sp_changed = false;

int button1State = LOW;
int button2State = LOW;
int lastButton1State = LOW;
int lastButton2State = LOW;
void buttonCheck();

void ICACHE_RAM_ATTR handleButton1Interrupt() {
    lastButton1State = button1State;
    button1State = digitalRead(BUTTON1_PIN);
    buttonCheck();
}
void ICACHE_RAM_ATTR handleButton2Interrupt() {
    lastButton2State = button2State;
    button2State = digitalRead(BUTTON2_PIN);
    buttonCheck();
}


OneWire oneWire(ROOM_TEMP_SENSOR_PIN);
DallasTemperature sensors(&oneWire);
OpenTherm ot(OT_IN_PIN, OT_OUT_PIN);
BlynkTimer timer;

void ICACHE_RAM_ATTR handleInterrupt() {
    ot.handleInterrupt();
}

float getTemp() {
  return sensors.getTempCByIndex(0);
}

float pid(float sp, float pv, float pv_last, float& ierr, float dt) {   
  float KP = 10;
  float KI = 0.02; 
  // upper and lower bounds on heater level
  float ophi = 80;
  float oplo = 10;
  // calculate the error
  float error = sp - pv;
  // calculate the integral error
  ierr = ierr + KI * error * dt; 
  // calculate the measurement derivative
  float dpv = (pv - pv_last) / dt;
  // calculate the PID output
  float P = KP * error; //proportional contribution
  float I = ierr; //integral contribution 
  float op = P + I;
  // implement anti-reset windup
  if ((op < oplo) || (op > ophi)) {
    I = I - KI * error * dt;
    // clip output
    op = max(oplo, min(ophi, op));
  }
  ierr = I;
  Serial.println("sp="+String(sp) + " pv=" + String(pv) + " dt=" + String(dt) + " op=" + String(op) + " P=" + String(P) + " I=" + String(I));
  return op;
}

void checkDisplay() {
  if (sp != old_sp) {
  old_sp = sp;
  sp_changed = true;
} else {
  sp_changed = false;
}
}

void buttonCheck()
{
 // Read the state of the buttons
  int reading1 = digitalRead(BUTTON1_PIN);
  int reading2 = digitalRead(BUTTON2_PIN);

  // If the button1 state has changed, update the variable and send a message to Blynk
  if (reading1 != lastButton1State) {
    delay(50); // debounce
    button1State = reading1;
    if (button1State == HIGH) {
      sp--;
      Blynk.virtualWrite(SETPOINT_PIN, sp);
        Serial.print("SETPOINT value is: ");
        Serial.println(sp); 
    }
  }

  // If the button2 state has changed, update the variable and send a message to Blynk
  if (reading2 != lastButton2State) {
    delay(50); // debounce
    button2State = reading2;
    if (button2State == HIGH) {
      sp++;
      Blynk.virtualWrite(SETPOINT_PIN, sp);
      Serial.print("SETPOINT value is: ");
      Serial.println(sp); 
    }
  }

  // Update last button state
  lastButton1State = reading1;
  lastButton2State = reading2;
}

// This function calculates temperature and sends data to Blynk app every second.
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void updateData()
{
  //Set/Get Boiler Status
  bool enableCentralHeating = true;
  bool enableHotWater = true;
  bool enableCooling = false;
  unsigned long response = ot.setBoilerStatus(enableCentralHeating, enableHotWater, enableCooling);
  OpenThermResponseStatus responseStatus = ot.getLastResponseStatus();
  if (responseStatus != OpenThermResponseStatus::SUCCESS) {
    Serial.println("Error: Invalid boiler response " + String(response, HEX));
  }   
 
  t = sensors.getTempCByIndex(0);
  new_ts = millis();
  dt = (new_ts - ts) / 1000.0;
  ts = new_ts;
  if (responseStatus == OpenThermResponseStatus::SUCCESS) {
    op = pid(sp, t, t_last, ierr, dt);
    //Set Boiler Temperature   
    ot.setBoilerTemperature(op);
  }
  t_last = t;
  sensors.requestTemperatures(); //async temperature request
 
  Blynk.virtualWrite(ROOM_TEMP_PIN, t);
  Blynk.virtualWrite(SETPOINT_PIN, sp);
  Serial.println("Current temperature is " + String(t) + " degrees C");

}

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(SETPOINT_PIN)
{
  sp = param.asFloat(); // assigning incoming value from pin V1 to a variable 
  Serial.print("V1 Slider value is: ");
  Serial.println(sp); 
}

// This function tells Arduino what to do if there is a Widget
// which is requesting data for Virtual Pin (1)
BLYNK_READ(SETPOINT_PIN)
{
  // This command writes setpoint to Virtual Pin (1)
  Blynk.virtualWrite(SETPOINT_PIN, sp);
}

void updateDisplay() {
  if (sp_changed) {
  // clear display
  display.clearDisplay();
 
  // display new setpoint value
  display.setTextSize(2);
  display.setCursor(40, 0);
  display.print("SetT: ");
  display.setTextSize(3);
  display.setCursor(45, 25);
  int roundsp = round(sp);
  display.print(roundsp);
  display.display();
  sp_changed = false;
 
} else {
  // display current temperature
  display.clearDisplay();
  display.setTextSize(1, 2); // размер текста
  display.setCursor(0, 0);
  display.println("t");
  display.setCursor(85, 0);
  int roundT = round(t);
  display.println(roundT);
  display.setCursor(120, 0);
  display.println("C");
  display.setCursor(0, 22);
  display.println("SetT");
  display.setCursor(85, 22);
  int roundsp = round(sp);
  display.println(roundsp);
  display.setCursor(120, 22);
  display.println("C");
  display.setCursor(0, 48);
  display.println("Mod");
  display.setCursor(85, 48);
  int roundresult2 = round(result2);
  display.println(roundresult2);
  display.setCursor(120, 48);
  display.println("%");
  display.display();
}
}

void setup()
{
  //Debug console
  Serial.begin(9600);
 
  Blynk.begin(auth, ssid, pass, "blynk.tk", 8080);
  ot.begin(handleInterrupt);

  //Write initial setpoint 
  Blynk.virtualWrite(SETPOINT_PIN, sp);

  //управление кнопками с прерыванием
  pinMode(BUTTON1_PIN, INPUT_PULLUP);
  pinMode(BUTTON2_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(BUTTON1_PIN), handleButton1Interrupt, CHANGE);
  attachInterrupt(digitalPinToInterrupt(BUTTON2_PIN), handleButton2Interrupt, CHANGE);

  //Init DS18B20 sensor
  sensors.begin();
  sensors.requestTemperatures();
  sensors.setWaitForConversion(false); //switch to async mode
  t, t_last = sensors.getTempCByIndex(0);
  ts = millis();

  //дисплей:
  myWire.begin(OLED_SDA, OLED_SCL);
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
  display.setTextSize(1, 2); // Размер шрифта
  display.setTextColor(SSD1306_WHITE); // Цвет белый
  display.display();
  delay(1000);
  display.clearDisplay();

  // Setup a function to be called every second
  timer.setInterval(1000L, updateData);
  timer.setInterval(1000L, updateData2);
  timer.setInterval(1000L, updateData3);
  timer.setInterval(1000L, updateData4);
  timer.setInterval(1000L, updateData5);
  timer.setInterval(1000L, updateData6);
}

void loop()
{
  Blynk.run();
  buttonCheck();
  checkDisplay();
  updateDisplay();
  timer.run();
}
 

Ildarmustafin86

Active member
По pro отзывы почитайте у этого продавца. Там предлагают перепаять стабилизатор
 
Сверху Снизу