Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Mmiscool
#34669 Hello,

I was hoping that there might be some example code to display a monochrome bmp file to the i2c displays made by adafruit and alike.

If any one has done this it would be a very useful example.
User avatar
By reaper7
#34675 I say more ... I have a example showing color jpeg file from spiffs on monochrome oled ;)
please check my fork from MakotoKurauchi/JPEGDecoder on my github
https://github.com/reaper7/JPEGDecoder

(part of code for display file on oled from https://github.com/kodera2t/TinyBasicPlus_OLED_support)
Code: Select all#include <Arduino.h>
#include <FS.h>

#include <SPI.h>
#include <Wire.h>

#include <JPEGDecoder.h>

#include <Adafruit_GFX.h>
#include <ESP_SSD1306.h>

ESP_SSD1306 display(false);   //reset disable

#define SDAPIN  12
#define SCLPIN  14

void setup() {

  Serial.begin(115200);
  Serial.print("Initializing FS...");

  if (!SPIFFS.begin()) {
    Serial.println("failed!");
    return;
  }
  Serial.println("done.");

  Serial.print("Initializing OLED...");
  //configure i2c
  Wire.begin(SDAPIN, SCLPIN);          //sda, scl

  //configure OLED SSD1306 display
  display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false);
  display.clearDisplay();
  display.fillScreen(BLACK);
  //display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setTextWrap(false);
  display.display();

  display.setTextSize(2);
  display.setCursor(0, 0);
  display.print("START");
  display.display();

  Serial.println("done.");

  Serial.println("initialization done.");
}

void loop() {
 
  char str[100];
  char filename[] = "/test.jpg";
  uint8 *pImg;
  int x,y,bx,by;
  int val,valmax;
   
  // Decoding start
  JpegDec.decode(filename,0);

  // Image Information
  Serial.print("Width     :"); Serial.println(JpegDec.width);
  Serial.print("Height    :"); Serial.println(JpegDec.height);
  Serial.print("Components:"); Serial.println(JpegDec.comps);
  Serial.print("MCU / row :"); Serial.println(JpegDec.MCUSPerRow);
  Serial.print("MCU / col :"); Serial.println(JpegDec.MCUSPerCol);
  Serial.print("Scan type :"); Serial.println(JpegDec.scanType);
  Serial.print("MCU width :"); Serial.println(JpegDec.MCUWidth);
  Serial.print("MCU height:"); Serial.println(JpegDec.MCUHeight);
  Serial.println("");

/*
  // Output CSV
  sprintf(str,"#SIZE,%d,%d",JpegDec.width,JpegDec.height);
  Serial.println(str);
*/

  while(JpegDec.read()) {

    pImg = JpegDec.pImage;

    for(by=0; by<JpegDec.MCUHeight; by++) {
       
      for(bx=0; bx<JpegDec.MCUWidth; bx++) {
           
        x = JpegDec.MCUx * JpegDec.MCUWidth + bx;
        y = JpegDec.MCUy * JpegDec.MCUHeight + by;
               
        if(x<JpegDec.width && y<JpegDec.height) {

          if(JpegDec.comps == 1) {                    // Grayscale
                   
            //sprintf(str,"#RGB,%d,%d,%u", x, y, pImg[0]);
            //Serial.println(str);

          } else {                                    // RGB

            //sprintf(str,"#RGB,%d,%d,%u,%u,%u", x, y, pImg[0], pImg[1], pImg[2]);
            val=0.299*pImg[0]+0.587*pImg[1]+0.114*pImg[2];
            //sprintf(str,"#RGB,%d,%d,%d", x, y, val);
            if(val>valmax) {
              valmax=val;
            }
            val=val/55;
            if(x%4==0) {
              switch(val) {

                case 3:
                  display.drawPixel(3*x/4,y/2,WHITE);
                  display.drawPixel(3*x/4+1,y/2,WHITE);
                  display.drawPixel(3*x/4+2,y/2,WHITE);
                  break;
                case 2:
                  display.drawPixel(3*x/4,y/2,WHITE);
                  display.drawPixel(3*x/4+1,y/2,BLACK);
                  display.drawPixel(3*x/4+2,y/2,WHITE);
                  break;
                case 1:
                  display.drawPixel(3*x/4,y/2,BLACK);
                  display.drawPixel(3*x/4+1,y/2,WHITE);
                  display.drawPixel(3*x/4+2,y/2,BLACK);
                  break;
                case 0:
                  display.drawPixel(3*x/4,y/2,BLACK);
                  display.drawPixel(3*x/4+1,y/2,BLACK);
                  display.drawPixel(3*x/4+2,y/2,BLACK);
                  break;
                default:
                  display.drawPixel(3*x/4,y/2,WHITE);
                  display.drawPixel(3*x/4+1,y/2,WHITE);
                  display.drawPixel(3*x/4+2,y/2,WHITE);
                  break;                         
              }
            }
            //pic[x/2][y/2]=val;
            //Serial.println(str);
          }
        }
        pImg += JpegDec.comps ;
      }
    }
  }
  display.display();
       
  delay(5000);
}


oled_spiffs.jpg
You do not have the required permissions to view the files attached to this post.
Last edited by reaper7 on Sun Nov 22, 2015 11:55 am, edited 2 times in total.
User avatar
By Mmiscool
#34679 Just looked. Can not find the OLDED specific code.

JPEG s better thou. Awesome.