Go Down

Topic: [HELP] OLED (Read 143 times) previous topic - next topic

doubleve

Hello, I am novice I ask for your help in order to display the data on a Mini 0.96 "I2C IIC Serial 128X64 OLED LCD Display Module, I have not found help on the French forum.

thank you.

I would like something in this style.

_____________
|                      | 
|IN   : X °C       |
|OUT :X °C       |
|FAN : ON/OFF  |
|____________|

Code: [Select]
#include <OneWire.h>
#include <DallasTemperature.h>


//Sondes Dallas
#define ONE_WIRE_BUS_1 2
#define ONE_WIRE_BUS_2 4

OneWire oneWire_TEMP_IN(ONE_WIRE_BUS_1);
OneWire oneWire_TEMP_OUT(ONE_WIRE_BUS_2);

DallasTemperature sensor_TEMP_IN(&oneWire_TEMP_IN);
DallasTemperature sensor_TEMP_OUT(&oneWire_TEMP_OUT);


//Relais

int relPin3 = 8;                        //Broche relais
int relPin3Val;


void setup() {
  Serial.begin(9600);

  Serial.println("Controle des sondes de Temperatures Dallas");
  sensor_TEMP_IN.begin();
  sensor_TEMP_OUT.begin();

  pinMode(relPin3, OUTPUT);      // Etat du relais
}

void loop() {

  Serial.print("Acquisitions des temperatures...");
  sensor_TEMP_IN.requestTemperatures();
  sensor_TEMP_OUT.requestTemperatures();

  float temperature1 = sensor_TEMP_IN.getTempCByIndex(0);
  Serial.print("INT: ");
  Serial.print(sensor_TEMP_IN.getTempCByIndex(0));
  Serial.print("C");

  float temperature2 = sensor_TEMP_OUT.getTempCByIndex(0);

  Serial.print("EXT:   ");
  Serial.print(sensor_TEMP_OUT.getTempCByIndex(0));
  Serial.print("C");




  if (temperature1 + 2 >= temperature2)
  {

    relPin3Val = HIGH;

    Serial.println("Relais ON  ");
  }
  else {
    relPin3Val =  LOW;
    Serial.println(" Relais OFF.");
  }

  {
    digitalWrite(relPin3, relPin3Val);
  }
}

MAS3

Hi W.


You told us about you having trouble.
And you told us about what you want.
And you've shown your code, which doesn't seem to do any communication to whatever display.

But you did not tell us what your problems are.
So there's nothing to help you with.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

doubleve

I think I have managed to get what I am looking for.
If I could have your opinion to optimize code



Code: [Select]
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_GFX.h>
#include <ESP_Adafruit_SSD1306.h>

//Sondes Dallas
#define ONE_WIRE_BUS_1 D3
#define ONE_WIRE_BUS_2 D4

OneWire oneWire_TEMP_IN(ONE_WIRE_BUS_1);
OneWire oneWire_TEMP_OUT(ONE_WIRE_BUS_2);

DallasTemperature sensor_TEMP_IN(&oneWire_TEMP_IN);
DallasTemperature sensor_TEMP_OUT(&oneWire_TEMP_OUT);


//Relais

int relPin3 = D8;                        //Broche relais
int relPin3Val;

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

//Mapeamento de pinos do NodeMCU
#define ledPinD1    5  //GPIO_5 (OLED - SCL)
#define ledPinD2    4  //GPIO_4 (OLED - SDA)


void setup() {
  Serial.begin(9600);

  Serial.println("Controle des sondes de Temperatures Dallas");
  sensor_TEMP_IN.begin();
  sensor_TEMP_OUT.begin();

  pinMode(relPin3, OUTPUT);      // Etat du relais

  display.begin(SSD1306_SWITCHCAPVCC, 0x78 >> 1);
  display.clearDisplay();


}

void loop() {

  Serial.print("Acquisitions des temperatures...");
  sensor_TEMP_IN.requestTemperatures();
  sensor_TEMP_OUT.requestTemperatures();

  float temperature1 = sensor_TEMP_IN.getTempCByIndex(0);
  Serial.print("INT: ");
  Serial.print(sensor_TEMP_IN.getTempCByIndex(0));
  Serial.print("C");

  float temperature2 = sensor_TEMP_OUT.getTempCByIndex(0);

  Serial.print("EXT:   ");
  Serial.print(sensor_TEMP_OUT.getTempCByIndex(0));
  Serial.print("C");




  if (temperature1 + 2 >= temperature2)
  {

    relPin3Val = HIGH;

    Serial.println("Relais ON  ");
  }
  else {
    relPin3Val =  LOW;
    Serial.println(" Relais OFF.");
  }

  {
    digitalWrite(relPin3, relPin3Val);
  }
  // display text
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.print("INT: ");
  display.println(temperature1);
  display.print("EXT: ");
  display.println(temperature2);
  display.print("Fan: ");

  if (relPin3Val == LOW) {
    display.println("OFF");

  } else {

    display.println("ON");
   
  }
  display.display();
    millis();
  display.clearDisplay();
}

Go Up