Problem z wyświetlaczem lcd 128 x 64

wrobel111
Posts: 62
Joined: Tue Jun 05, 2018 6:13 pm

Post

Witam, mam problem z wyświetlaniem bitmap na wyświetlaczu. Wyświetlanie danych liczbowych działa, lecz gdy dodam linijkę

Code: Select all

u8g2.drawBitmap( 15, 32, 4, 32, hause);
program kompiluje się i wgrywa ale następuje restart esp. Na klonie arduino uno grafiki wyświetlały się bez problemów.

Wklejam cały kod programu:

Code: Select all

/**
 * Supla.org NodeMCU WiFi minimal example
 * Author: Programistyk - Kamil Kaminski <[email protected]>
 * 
 * This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE
 */

// Biblioteki
#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
// We define our own ethernet layer
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

static const unsigned char PROGMEM hause[] = {
    0x00, 0x01, 0x80, 0x00, 
    0x00, 0x03, 0x80, 0x00, 
    0x00, 0x06, 0x60, 0x00, 
    0x00, 0x0c, 0x31, 0xc0, 
    0x00, 0x18, 0x13, 0x40, 
    0x00, 0x10, 0x0d, 0x40, 
    0x00, 0x60, 0x0c, 0x40, 
    0x00, 0x40, 0x03, 0x40, 
    0x01, 0xc0, 0x03, 0x40, 
    0x01, 0x00, 0x00, 0x80, 
    0x03, 0x00, 0x00, 0xe0, 
    0x06, 0x00, 0x00, 0x20, 
    0x0c, 0x00, 0x00, 0x30, 
    0x18, 0x00, 0x00, 0x18, 
    0x38, 0x00, 0x00, 0x0c, 
    0x70, 0x00, 0x00, 0x1e, 
    0xd0, 0x00, 0x00, 0x0b, 
    0x18, 0x0e, 0xf0, 0x18, 
    0x10, 0x0a, 0x90, 0x08, 
    0x10, 0x18, 0x18, 0x08, 
    0x10, 0x08, 0x10, 0x18, 
    0x18, 0x08, 0x10, 0x08, 
    0x10, 0x18, 0x18, 0x08, 
    0x10, 0x08, 0x10, 0x18, 
    0x10, 0x10, 0x10, 0x08, 
    0x18, 0x08, 0x10, 0x10, 
    0x10, 0x18, 0x18, 0x08, 
    0x10, 0x08, 0x10, 0x18, 
    0x10, 0x18, 0x10, 0x08, 
    0x18, 0x08, 0x10, 0x18, 
    0x11, 0x18, 0x19, 0x10, 
    0x1f, 0xff, 0xff, 0xf8
};

// Zmienne globalne
float tempC = 0.0;
int pressure = 0;
float hum = 0.0;

char temp_string[5]; //empty char array to hold the converted temp float 
char hum_string[5];  //empty char array to hold the converted humidity float 
char pressure_string[5];  //empty char array to hold the converted humidity float 


WiFiClient client;

Adafruit_BME280 bme;

// U8g2 Contructor
U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 14, /* data=*/ 13, /* CS=*/ 15, /* reset=*/ U8X8_PIN_NONE);

// Setup Supla connection
const char* ssid     = "xxx";
const char* password = "yyy";

// BMP280 Sensor read implementation
void get_temperature_and_humidity(int channelNumber, double *temp, double *humidity) {
  
    *temp = bme.readTemperature();
    tempC = *temp;
    *humidity = bme.readHumidity();
    hum = *humidity;
    pressure = bme.readPressure()/100;
    
    Serial.print("Temp : ");
    Serial.print(*temp);
   
    Serial.print("   Wilgotność : ");
    Serial.print(*humidity);

    Serial.print("   Ciśnienie : ");
    Serial.println(pressure);

    if ( isnan(*temp) || isnan(*humidity) ) {
      *temp = -275;
      *humidity = -1;
       }
} //void

void setup() {
  Serial.begin(115200);
  delay(10);
  u8g2.begin();

  if(!bme.begin(0x76))
  {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1)
    {
        yield();
        delay(200);
    }
  }
  
  // Set temperature callback
  SuplaDevice.setTemperatureHumidityCallback(&get_temperature_and_humidity);
  

  
  // Replace the falowing GUID
  char GUID[SUPLA_GUID_SIZE] = {xxxxxxx};
  // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid

  // Ethernet MAC address
  uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

  /*
   * Having your device already registered at cloud.supla.org,
   * you want to change CHANNEL sequence or remove any of them,
   * then you must also remove the device itself from cloud.supla.org.
   * Otherwise you will get "Channel conflict!" error.
   */
    
  // CHANNEL0 - RELAY
  //SuplaDevice.addRelay(D0);           // 44 - Pin number where the relay is connected      
                                      // Call SuplaDevice.addRelay(44, true) with an extra "true" parameter 
                                      // to enable "port value inversion"
                                      // where HIGH == LOW, and LOW == HIGH 
  // CHANNEL1 - DIMMER 
  //SuplaDevice.addDimmer();
  
  // CHANNEL2 - RGB
  //SuplaDevice.addRgbController();
  
  // CHANNEL3 - DIMMER
  //SuplaDevice.addDimmer();

  
 
  // CHANNEL1 - RELAY
 // SuplaDevice.addRelay(45, true);           // 45 - Pin number where the relay is connected   

  // CHANNEL3 - TWO RELAYS (Roller shutter operation)
  //SuplaDevice.addRollerShutterRelays(46,     // 46 - Pin number where the 1st relay is connected   
  //                                     47, true);    // 47 - Pin number where the 2nd relay is connected  

  // CHANNEL4 - Opening sensor (Normal Open)
  //SuplaDevice.addSensorNO(A0); // A0 - Pin number where the sensor is connected
                               // Call SuplaDevice.addSensorNO(A0, true) with an extra "true" parameter
                               // to enable the internal pull-up resistor


  // CHANNEL5 - Opening sensor (Normal Open)
  //SuplaDevice.addSensorNO(A1); // A1 - Pin number where the sensor is connected


  // CHANNEL6 - DHT22 Sensor
  // SuplaDevice.addDHT11();
  // SuplaDevice.addAM2302();
  SuplaDevice.addDHT22();
  
  //SuplaDevice.addDS18B20Thermometer();
  

  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    mac,               // Ethernet MAC address
                    "svr1.supla.org",  // SUPLA server address
                    xxx,                 // Location ID 
                    "xxx");               // Location Password

  u8g2.firstPage();  
  do {
    draw_Str_1();
  } while( u8g2.nextPage() );

  delay(2000);

}

void loop() {
  SuplaDevice.iterate();
  u8g2.firstPage();  
  do {
    draw_Str_2();
  } while( u8g2.nextPage() );
}

// Supla.org ethernet layer
    int supla_arduino_tcp_read(void *buf, int count) {
        _supla_int_t size = client.available();
       
        if ( size > 0 ) {
            if ( size > count ) size = count;
            return client.read((uint8_t *)buf, size);
        };
    
        return -1;
    };
    
    int supla_arduino_tcp_write(void *buf, int count) {
        return client.write((const uint8_t *)buf, count);
    };
    
    bool supla_arduino_svr_connect(const char *server, int port) {
          return client.connect(server, 2015);
    }
    
    bool supla_arduino_svr_connected(void) {
          return client.connected();
    }
    
    void supla_arduino_svr_disconnect(void) {
         client.stop();
    }
    
    void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {

       // Serial.println("WiFi init");
        WiFi.begin(ssid, password);

        while (WiFi.status() != WL_CONNECTED) {
            delay(500);
        //    Serial.print(".");
        }

        //Serial.print("\nlocalIP: ");
        //Serial.println(WiFi.localIP());
        //Serial.print("subnetMask: ");
        //Serial.println(WiFi.subnetMask());
        //Serial.print("gatewayIP: ");
        //Serial.println(WiFi.gatewayIP());
    }

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
          SuplaDeviceCallbacks cb;
          
          cb.tcp_read = &supla_arduino_tcp_read;
          cb.tcp_write = &supla_arduino_tcp_write;
          cb.eth_setup = &supla_arduino_eth_setup;
          cb.svr_connected = &supla_arduino_svr_connected;
          cb.svr_connect = &supla_arduino_svr_connect;
          cb.svr_disconnect = &supla_arduino_svr_disconnect;
          cb.get_temperature = NULL;
          cb.get_temperature_and_humidity = NULL;
          cb.get_rgbw_value = NULL;
          cb.set_rgbw_value = NULL;
          
          return cb;
}

void draw_Str_1(void){
         
    u8g2.drawFrame(0,20,128,17);            //  ramka ZEWNĘTRZNA (start x, start y, szerokość, wysokość)
    u8g2.drawFrame(2,22,124,13);            // górna WEWNĘTRZNA (start x, start y, szerokość, wysokość)
     
    u8g2.setFont(u8g2_font_helvB08_tr);              // rozmiar i krój czcionki 9 px
    u8g2.drawStr(9, 32, "STACJA POGODOWA");       // położenie i tekst do wyswietlenia
    u8g2.drawStr(1, 60, "MATEUSZ WROBEL 2018");       // położenie i tekst do wyswietlenia
     
    }

void draw_Str_2(void) {
      // tu zamieszczamy polecenia graficzne do wyświetlenia całego ekranu
    drawText();
    u8g2.drawVLine(50, 32, 31);               // linia pionowa (odległość od lewej strony, odległość od góry, długość linii pionowej)
    
    }

void drawText(void) {
     
    u8g2.setFont(u8g2_font_maniac_tn);
    u8g2.drawStr(25, 30, "22:42");
     
    u8g2.setFont(u8g2_font_6x12_tf);
    dtostrf(tempC, 3, 1, temp_string);
    u8g2.drawStr(55, 40, temp_string);
    u8g2.drawStr(79, 40, "°C"); //°
    
    
    dtostrf(pressure, 3, 0, pressure_string); 
    u8g2.drawStr(55, 51, pressure_string);
    u8g2.drawStr(81, 51, "hPa");
    
    dtostrf(hum, 3, 1, hum_string);
    u8g2.drawStr(55, 62, hum_string);
    u8g2.drawStr(81, 62, "%");

     
    //u8g.drawBitmapP( 15, 32, 4, 32, sun_regular);
    //u8g.drawBitmapP( 15, 32, 4, 32, clouds);
    //u8g.drawBitmapP( 15, 32, 4, 32, rain);
    
    u8g2.drawBitmap( 15, 32, 4, 32, hause);   
    }
Drugim problemem jest poprawne wyświetlanie znaku stopni Celsjusza. Oprócz "°" wyświetla się także jakieś A.
wyświetlacz.jpg
Za pomoc z góry dziękuje.
You do not have the required permissions to view the files attached to this post.

Return to “Pomoc”