OLED Bitmap Anzeige durch String von HTTP Request

Hallo zusammen,

leider verzweifele ich gerade so ein wenig. Ich möchte einen HTTP Request machen, ich erhalte einen einfachen String als Response der so aussehen würde:

"0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0x00, 0x01, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, 0x03, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, 0x03, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0x00, 0x01, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00"

Prinzipiell die selbe Bitmap wie normalerweise als const unsigned char test_bitmap [] PROGMEM definiert. Leider habe ich es mit keiner Methode bisher geschafft aus dem obigen String eine vernünftige Bitmap zu bauen. Ich habe bereits verstanden, das ich im Zweifel in einer einfachen Schleife die kommaseparierte liste durchlaufen kann und den Hex Wert in einen Binär Wert schreiben kann. Leider führt das aber nicht zum gewünschten Ergebnis.

Ziel ist später dann die Bitmap mit der Methode "display.drawBitmap" (Adafruit_SSD1306) anzeigen zu lassen. Hat jemand schon einmal so etwas gemacht und lauffähig bekommen?

Mein aktueller Versuch:

String s = "0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,...."
unsigned int str_len = s.length()+1;
  char charArray[str_len];
  s.toCharArray(charArray, str_len);
  
  uint8_t byteArray[1024];
  int i=0;
  
  // split charArray at each ',' and convert to uint8_t
  char *p = strtok(charArray, ",");
  while(p != NULL) {
    byteArray[i++] = strtoul(p, NULL, 16);
    p = strtok(NULL, ",");
  }
  

führt zu einem crash

Panic C:\Users\frede\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_main.cpp:103 __yield

Viele Grüße,
Freddy

Mal sehe ich Leerzeichen, mal keine, was nun?

Bist Du sicher, da kommt "0x00"?

Ich habe mir die Variante mit Leerzeichen gewählt und das Sternchen aus dem Bibliotheksbeispiel:

String s = "0x00, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x03, 0xE0, 0xF3, 0xE0, 0xFE, 0xF8, 0x7E, 0xFF, 0x33, 0x9F, 0x1F, 0xFC, 0x0D, 0x70, 0x1B, 0xA0, 0x3F, 0xE0, 0x3F, 0xF0, 0x7C, 0xF0, 0x70, 0x70, 0x00, 0x30";

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16

Das paßt in 16 * 16 / 8 = 32 Byte:

uint8_t logo_bmp[32];

Eine Hilfsfunktion wandelt einen Hex-Buchstaben in eine Zahl:

uint8_t h2z(char z)
{
  uint8_t r = 255;
  if (z >= 'a')
  {
    r = z - 'a' + 10;
  }
  else if (z >= 'A')
  {
    r = z - 'A' + 10;
  }
  else if (z >= '0')
  {
    r = z - '0';
  }
  return r;
}

Dann noch die Wandlung vom String-Objekt in ein Bytefeld mit Grafikbits:

  for (byte j = 0; j < sizeof(logo_bmp); j++) {
    byte k = j * 6;
    if ( (k + 3) < s.length() ) {
      logo_bmp[j] = h2z(s[k + 2]) * 0x10 + h2z(s[k + 3]);
    }
  }

Getestet habe ich mit einem ESP32.

Alternativ könnte man auch std::stoi aus #include <string> verwenden.

Danke für deine Antwort! @agmue
Dein Beispiel läuft soweit. Wie ich vorgehe, ich hab ein Bild in Größe 128x64 Pixel (die Größe kann das OLED darstellen) und konvertiere es mit folgendem Tool: image2cpp

Dementsprechend wollte ich meinen vollständigen String nehmen, ob mir oder ohne Komma ist ja erstmal nicht ausschlaggebend :wink:

Also müsste ich doch mein Array auf die Größe 1024 erhöhen (128*64/8) dann Crasht mein Arduino allerdings immer.

Vielleicht hast du hier ja auch nochmal einen Tipp!

Welcher?

Gruß Tommy

@Tommy56 hab es mit einem esp8266 wemos d1 Mini sowie mit einem esp32 NodeMCU ausprobiert.

128 * 64/8 = 128 * 8 = 1024
Damit hat der ESP8266 kein Problem, wenn der Typ byte ist.

Da liegt der Fehler woanders. Zeige mal einen kompletten aktuellen Sketch.

Gruß Tommy

Hier mein vollständiger Sketch:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

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

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }
    
//  String s="0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0xff,0xff,0x00,0x01,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xff,0x80,0x03,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xff,0x80,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xc0,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xff,0x80,0x07,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xff,0x80,0x03,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0xff,0xff,0x00,0x01,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xfc,0x00,0x00,0x7f,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00";
  String s = "0x00, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x03, 0xE0, 0xF3, 0xE0, 0xFE, 0xF8, 0x7E, 0xFF, 0x33, 0x9F, 0x1F, 0xFC, 0x0D, 0x70, 0x1B, 0xA0, 0x3F, 0xE0, 0x3F, 0xF0, 0x7C, 0xF0, 0x70, 0x70, 0x00, 0x30";

  uint8_t logo_bmp[32];
   for (byte j = 0; j < sizeof(logo_bmp); j++) {
    byte k = j * 6;
    if ( (k + 3) < s.length() ) {
      logo_bmp[j] = h2z(s[k + 2]) * 0x10 + h2z(s[k + 3]);
    }
  }
  
  display.clearDisplay();
  display.drawBitmap(0, 0, logo_bmp, SCREEN_WIDTH, SCREEN_HEIGHT, WHITE);
  display.display();
}

uint8_t h2z(char z)
{
  uint8_t r = 255;
  if (z >= 'a')
  {
    r = z - 'a' + 10;
  }
  else if (z >= 'A')
  {
    r = z - 'A' + 10;
  }
  else if (z >= '0')
  {
    r = z - '0';
  }
  return r;
}

void loop() {
}

Ergebnis:

Nun, wenn ich es mit dem kommentierten String mache und die bitmap Größe von 32 auf 1024 ändere erhalte ich folgenden Fehler:

Reicht das aus, oder benötigst du weitere Infos?

wdt reset heißt: Da dauert etwas zu lange.
Lass mal den Exceptiondecoder drauf los.
Der Fehler ist ein Zeitfehler, kein Speicherfehler.

Warum soll das String sein? uint8_t genügt doch auch.

Gruß Tommy

Ja, die berüchtigte Endlosschleife als Laufzeitfehler.

j 0 bis 1023
k 0 bis 6141

Da genügt byte nicht mehr.

Getestet mit ESP32:

  for (int j = 0; j < sizeof(logo_bmp); j++) {
    int k = j * 6;
    if ( (k + 3) < s.length() ) {
      logo_bmp[j] = h2z(s[k + 2]) * 0x10 + h2z(s[k + 3]);
    }
  }

Beim Typ würde uint16_t genügen, meine Wahl auf einem UNO. Beim ESP32 tut es auch int, weil Standard.

Danke jetzt hat es geklappt!
Ich komme "leider" aus einer anderen Welt (Web Entwickler, also PHPler usw.) wo man nicht so stark auf den Speicher achten muss :smiley: Das fällt einem ja hier schnell auf die Füße. Warum mach ich überhaupt den Quatsch bzw. muss von extern die bitmap einlesen zum darstellen auf dem OLED. "Speicher" - er reicht nicht aus, wenn ich sehr viele unterschiedliche Grafiken darstellen möchte. Ich werde mich jetzt mal probiere, den Code so zu erweitern, dass ich technisch auch ein Array aus bitmaps einlesen kann (mit einem einzelnen Request), kommt hier direkt die nächste Hürde? Ich werde es euch auf jeden Fall Wissen lassen!

Wenn der Speicher für x verschiedene Bitmaps nicht ausreicht, dann reicht er natürlich auch nicht für ein Array aus x Bitmaps aus.

Außerdem kann man auch in PHP binäre Daten senden (und in C++ empfangen), wenn man ein paar Grundkenntnisse hat. Der Umweg über die Bytedarstellung in Hex ist also nicht notwendig.

Gruß Tommy

Sehr gut!

Ja, schon anders.

So wäre schon deutlich kürzer: String s = "00,C0,01,C0,01, ...";

Ändern die sich? Wenn nicht ginge auch EEPROM oder anderer Speicher.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.