Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 32 of 32

Thread: Bitmap with Teensy3.5

  1. #26
    Member
    Join Date
    Jul 2018
    Location
    El Paso, TX
    Posts
    56
    Whenever it is convenient for you. I will certain keep working on the details myself as I said - big learning curve here using all the new components hardware and software. Thanks again for your assistance.

  2. #27
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    868
    @johnwatterson. I haven't been able to run this through an array hooked up to the Octows2811 adaptor but it should be a step in the right direction. It put the entire BMP pixel info into three buffers of bytes, one each for RGB. it then puts this data together and send to leds as a 24bit colour value. It includes some code to print some of the image info to the serial monitor so that image size can be checked. Not sure if it will sort all the issues, but it should be a step closer
    Code:
    #include <SD.h>
    #include <OctoWS2811.h>
    
    //----------set the three below------//
    const int ledsPerStrip = 72;
    #define imageHeight 48
    #define imageWidth 72
    
    DMAMEM int displayMemory[ledsPerStrip*6];
    int drawingMemory[ledsPerStrip*6];
    const int config = WS2811_GRB | WS2811_800kHz;
    OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
    #define RED    0xFF0000
    const int chipSelect = BUILTIN_SDCARD;
    
    
    //buffer to hold pixel data. remains size of pixel number//
    const int ARRAY_SIZE = imageHeight*imageWidth;
    const int byteBuffSize = ARRAY_SIZE*3;
    byte pixelBUFFER[byteBuffSize];
    byte ArrayB[ARRAY_SIZE];
    byte ArrayR[ARRAY_SIZE];
    byte ArrayG[ARRAY_SIZE];
    
    /////////////////////
    void setup(void) {
      Serial.begin(9600);
      leds.begin();
      leds.show();
    
    // if you dont get all leds lighting then going off, check your wiring
    
    Serial.println("init");
    delay(500);
    Serial.print("Initializing SD cardů");
    
    if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    while(1);
    }
    Serial.println("SD OK!");
    }
    //////////////////////////////////
    void loop() {
    
      bmpDraw("test.bmp");  
      delay(1000);
    
    //do a colour wipe to set all leds to red
      for (int i=0; i < leds.numPixels(); i++) {
        leds.setPixel(i, RED);
        leds.show();
        delay(5);
      }
    
    }
    //////////////////////////////////////////////
    int32_t readNbytesInt(File *p_file, int position, byte nBytes)
    {
        if (nBytes > 4)
            return 0;
    
        p_file->seek(position);
    
        int32_t weight = 1;
        int32_t result = 0;
        for (; nBytes; nBytes--)
        {
            result += weight * p_file->read();
            weight <<= 8;
        }
        return result;
    }
    
    
    void bmpDraw( char* fileName)
    {
    // Open file
        File bmpImage = SD.open(fileName, FILE_READ);
        
        int32_t dataStartingOffset = readNbytesInt(&bmpImage, 0x0A, 4);
    
        // Change their types to int32_t (4byte)
        int32_t width = readNbytesInt(&bmpImage, 0x12, 4); //0x12 - dec18
        int32_t height = readNbytesInt(&bmpImage, 0x16, 4); //0x16 - dec22
        int32_t ImgSize = readNbytesInt(&bmpImage, 0x22,4); //-dec34
        
        Serial.println(width);
        Serial.println(height);
        Serial.println(ImgSize);
    
        int16_t pixelsize = readNbytesInt(&bmpImage, 0x1C, 2);
    
        if (pixelsize != 24)
        {
            Serial.println("Image is not 24 bpp");
            while (1);
        }
    
        bmpImage.seek(dataStartingOffset);//skip bitmap header
    
        byte R, G, B;
    
     for(int i=0;i<ARRAY_SIZE;i++){
                ArrayB[i] = bmpImage.read();
                ArrayG[i] = bmpImage.read();
                ArrayR[i] = bmpImage.read();
     }          
        bmpImage.close();
        Serial.println("done writing to Buffer");
        
      int ledCount =0;
        for(int i=0; i<width*height;i++){
          leds.setPixel(ledCount,Color(ArrayB[i],ArrayG[i],ArrayR[i]));
            ledCount = ledCount+1;
        }   
        leds.show();
    }
    
    //------- HELPER FUNCTION------//
    // Create a 24 bit color value from R,G,B ////these strips are BGR, but you might need to change this
    unsigned int Color(byte g, byte r, byte b)
    {
      //Take the lowest 8 bits of each value and append them end to end
    return( ((unsigned int)g & 0x1F )<<16 | ((unsigned int)r & 0x1F)<<8 | (unsigned int)b & 0x1F);
      }
    //end of helper function

  3. #28
    Member
    Join Date
    Jul 2018
    Location
    El Paso, TX
    Posts
    56
    Great - I love your spirit of helping out a beginning programmer. Believe me this support is just what I needed to encourage me to explore the new hardware and software that people around the world are using these days. Reaching out to help others is the basis of living a life with meaning. I appreciate your generosity. Will try this code in an hour or two. Thanks.

  4. #29
    Member
    Join Date
    Jul 2018
    Location
    El Paso, TX
    Posts
    56
    Great all the leds are lit.
    Where do I put my bitmap file name or do I create a varible filename = "RONION.bmp";
    I thought it went in place of bpmDraw("test.bmp") but got a teensy error without explanation.

  5. #30
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    868
    Hi, yes you should just replace the filename in bpmDraw("test.bmp"). I did this with three files to test it and did not receive an error. What is the verbose output for the Teensy error? it may be my use of converting a string constant to 'char*'. Does the error stop the programme from working?

  6. #31
    Member
    Join Date
    Jul 2018
    Location
    El Paso, TX
    Posts
    56
    Started over -looks like the program is working. Thank you so much. Unfortunately the colors are way off. Does not look much like the real bit map. I will work on it and post a couple of pictures so you can see the details. Thanks again - have a nice weekend.

  7. #32
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    868
    the colours are probably off due to my reusing the colour helper function from a previous project where the R G and B were in a different order. Try a couple of changes.

    1. change the line "leds.setPixel(ledCount,Color(ArrayB[i],ArrayG[i],ArrayR[i]));" to be in RGB order "ArrayR[i],ArrayG[i],ArrayB[i]));" and in the helper function at the bottom of the sketch change the order of compiling the 24bit colour value to RGB in both lines.
    "unsigned int Color(byte g, byte r, byte b)" goes to r,g,b and
    "return( ((unsigned int)g & 0x1F )<<16 | ((unsigned int)r & 0x1F)<<8 | (unsigned int)b & 0x1F);" goes to rgb

    thats probably the best starting point

    to check the colour setup of your leds you can run the BasicTest sketch in the examples menu under OctoWS2811.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •