Jump to content
ELFORUM - Forumul electronistilor

ESP8266 cu OLED1,3" - SH1106


Guest

Recommended Posts

Salut!

Sunt incepator in programarea lui ESP8266. Dar se pare ca nu este la fel de simplu ca la Arduino

Intampin o mica problema cu un cod simplu. Am cautat pe internet exemple cu ESP8266 si OLED cu controller SH1106.

Am gasit librarii, am testat exemplele, si am incercat sa fac un numarator simplu:

/*
   Test
   Numarator
   ESP8266 > OLED 1,3" - SH1106
*/
// For a connection via I2C using Wire include
#include <Wire.h>  // Only needed for Arduino 1.6.5 and earlier
#include "SH1106Wire.h" // legacy include: `#include "SH1106.h"`

SH1106Wire display(0x3c, D2, D1);

void Counter(void) {
  int i = 0;

  if ( i < 10 ) {
    i++;
    delay(500);
  }
  if ( i >= 10 ) {
    i = 0;
  }
  display.drawString(48, 16, String(i));

}

void setup() {
  // Initialising the UI will init the display too.
  display.init();

  display.flipScreenVertically();
  display.setFont(ArialMT_Plain_24);
  display.setTextAlignment(TEXT_ALIGN_LEFT);

 display.clear();
}

void loop() {
  Counter();
  display.display();
}

Rezultatul este ca nu contorizeaza, nu numara. Apare doar cifra "1" si atat.

 

Multumesc!

 

 

 

Link to comment
  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

 // write the buffer to the display
  display.display();

Imi cer scuze, nu am introdus si unele comentarii importante.

Fara aceasta linie 

display.display();

, nu se afiseaza nimic.

Edited by Guest
Link to comment

...

  if ( i >= 10 ) {
    i = 0;
  }
  display.drawString(48, 16, String(i));
// write the buffer to the display
  display.display();
}

Daca il folosesc asa, numara dar se suprapun cifrele.

Edited by Guest
Link to comment
Acum 2 minute, Thunderer2018 a spus:

 

Pune 


int i = 0;

inainte de Void loop().

Am vazut asta, si l-am pus la inceput

SH1106Wire display(0x3c, D2, D1);

int i = 0;

void count(void) {
  if ( i < 10 ) {

Deci numara, dar se suprapun numerele.

Link to comment

Am modificat codul:

void count(void) {
  display.clear();
  if ( i < 10 ) {
    i++;
    delay(500);
  }
  if ( i >= 10 ) {
    i = 0;
  }
  display.drawString(48, 16, String(i));
  display.display();
}
    ...
    void loop() {
  count();
}

Afiseaza ok.

Multumesc!

Si era atat de simplu :(

Link to comment

Am mai adus o modificare la cod.

Aprinderea LED-ului cand count = 10:

/*
   Test
   Numarator
   ESP8266 > OLED 1,3" - SH1106
*/
// For a connection via I2C using Wire include
#include <Wire.h>  // Only needed for Arduino 1.6.5 and earlier
#include "SH1106Wire.h" // legacy include: `#include "SH1106.h"`

SH1106Wire display(0x3c, D2, D1);

int i = 0;

void count(void) {
  display.clear();
  digitalWrite(LED_BUILTIN, HIGH);
  if ( i < 10 ) {
    i++;
    delay(500);
  }
  if ( i >= 10 ) {
    digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
    delay(120);
    i = 0;
  }
  display.drawString(48, 16, String(i));
  // write the buffer to the display
  display.display();
  
}

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  // Initialising the UI will init the display too.
  display.init();

  display.flipScreenVertically();
  display.setFont(ArialMT_Plain_24);
  display.setTextAlignment(TEXT_ALIGN_LEFT);

 display.clear();
}

void loop() {
  count();
}

 

Link to comment

Da, dar astfel stergi tot ecranul. Nu e practic daca mai afisezi si altele pe ecran (exemplu: text static sau alte variabile care se schimba la alta rata decat countet()).

 

Nu cunosc acea biblioteca pentru SH1106, nu ai posibilitatea sa stergi doar zona de text variabil? 

Link to comment

Am modificat libraria asta (+SSD1306) pt. PIC si din ce-mi amintesc nu exista posibilitatea de-a sterge zone... exista in schimb o functie setPixel()....

Daca o sa citesti putin despre modul de organizare a matricii display-ului ai s-o poti folosi pt. o stergere "zonala"....

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines