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

Thread: Bitmap with Teensy3.5

  1. #26
    Member
    Join Date
    Jul 2018
    Location
    El Paso, TX
    Posts
    61
    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
    869
    @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
    61
    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
    61
    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
    869
    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
    61
    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
    869
    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.

  8. #33
    Member
    Join Date
    Jul 2018
    Location
    El Paso, TX
    Posts
    61
    OK, I read the data-sheet for WS2812B leds (GRB) that I am using and saw your comment at the bottom so thought that may be the main problem. Really just trial and error since I know what it suppose to look like. Turns out best is BGR. You did a nice job on this program. I appreciate it too. Now I need to play around with these images a little. Try to send you a picture in the next few days. Thanks again.

  9. #34
    Member
    Join Date
    Jul 2018
    Location
    El Paso, TX
    Posts
    61
    What is the best way to show you the images? On my phone now - maybe transfer to email and upload from there?

  10. #35
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,098
    Quote Originally Posted by johnwatterson View Post
    What is the best way to show you the images? On my phone now - maybe transfer to email and upload from there?
    yes, jpg/png images up to 1MB can be uploaded with insert image.

  11. #36
    Member
    Join Date
    Jul 2018
    Location
    El Paso, TX
    Posts
    61
    Studio shot of image on laptop and image on led panel.Click image for larger version. 

Name:	studio_picture1.jpg 
Views:	6 
Size:	107.8 KB 
ID:	15336

  12. #37
    Member
    Join Date
    Jul 2018
    Location
    El Paso, TX
    Posts
    61
    As you can see the colors are way off so I tried to get the blue in the corners. The red light test worked really good. What if I identify the primary and secondary colors separately in a table. Think that would work.One reason for using the bitmap images is that I can edit them in MS Paint or Photoshop.
    I see the Processing language has a lot of geo-shapes & details built - in to the language. Maybe that is a better direction for a novice like me? What do you think. I am working for months on this project but I need to make some little progress on my own or hire someone to work directly with me. Suggestions would be appreciated.

  13. #38
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    869
    I would use a BMP image that has four distinct colours, one in each corner, such as blue, red, green, yellow. So you have four rectangles of colour. This way you can also see if you zigzag maths to redistribute the pixel colour values is correct. At the moment it looks like every other line is off also.

  14. #39
    Member
    Join Date
    Jul 2018
    Location
    El Paso, TX
    Posts
    61
    Thanks, I try that tomorrow and show you the results.

Posting Permissions

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