This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MATLAB and DLP LightCrafter load static image

Hi guys,

I'm currently having a hard time sending a bmp image from MATLAB to the LCr. I can load the internal patterns without a problem, but I haven't had success in sending a custom image, yet. Any hints are welcome!

This is my code:

tcpObject = tcpip('192.168.1.100',21845)

fopen(tcpObject) 

fwrite(tcpObject,uint8(hex2dec(['02';'01';'01';'00';'01';'00';'00';'05'])));%switch display mode to static

%create simple image

im = zeros( 30,30);

im (3:8, 3:8) = 1;

imwrite( im, 'im.bmp' );

imFile = fopen( 'im.bmp' );

imData = fread( imFile, inf, 'uchar' );

fclose( imFile ); 

lenData = length( imData );

lenDataMSB = floor( lenData / 256 )

lenDataLSB = mod( lenData, 256 )

%send header

header = uint8(hex2dec(['02';'01';'05';'00'; dec2hex( lenDataLSB, 2 ); dec2hex( lenDataMSB, 2 )]));%static image

fwrite(tcpObject,header);

%send data

data = uint8(imData);

%limit packet size

MAX_SIZE = 512;

buffer = data;

while (~isnan(buffer))

    if( length(buffer) > MAX_SIZE )

        currentPacket = buffer( 1 : MAX_SIZE);

        buffer = buffer( MAX_SIZE + 1 : end );

    else

        currentPacket = buffer( 1 : end);

        buffer = NaN;

    end

    fwrite(tcpObject,currentPacket);

    disp('wrote some data')

end

%send checksum

checksum = mod( sum(header) + sum(data), 256 );

fwrite(tcpObject,checksum);

fclose( tcpObject );



  • Hi Jan,

    I have received your question and will provide you an answer by thursday.

    Regards,

    Divya

  • Hi Jan,

    Welcome to DLP&MEMS fourm.

    For the display a static image. It is important to note the resolution info of the image. It should be always be 608 x 684 size.

    Change your code as following - it should work.

    tcpObject = tcpip('192.168.1.100',21845)

    fopen(tcpObject) 

    fwrite(tcpObject,uint8(hex2dec(['02';'01';'01';'00';'01';'00';'00';'05'])));%switch display mode to static

    %create simple image

    im = zeros( 30,30);

    im = zeros( 684, 608);

    im (3:8, 3:8) = 1;

    imwrite( im, 'im.bmp' );

    imFile = fopen( 'im.bmp' );

    imData = fread( imFile, inf, 'uchar' );

    fclose( imFile ); 

    lenData = length( imData );

    lenDataMSB = floor( lenData / 256 )

    lenDataLSB = mod( lenData, 256 )

    %send header

    header = uint8(hex2dec(['02';'01';'05';'00'; dec2hex( lenDataLSB, 2 ); dec2hex( lenDataMSB, 2 )]));%static image

    fwrite(tcpObject,header);

    %send data

    data = uint8(imData);

    %limit packet size

    MAX_SIZE = 512;

    buffer = data;

    while (~isnan(buffer))

        if( length(buffer) > MAX_SIZE )

            currentPacket = buffer( 1 : MAX_SIZE);

            buffer = buffer( MAX_SIZE + 1 : end );

        else

            currentPacket = buffer( 1 : end);

            buffer = NaN;

        end

        fwrite(tcpObject,currentPacket);

        disp('wrote some data')

    end

    %send checksum

    checksum = mod( sum(header) + sum(data), 256 );

    fwrite(tcpObject,checksum);

    fclose( tcpObject );

    Regards,

    Sanjeev

     

  • Hi Sanjeev,

    thanks for your feedback. I managed to send a bmp image to the LCr now!

    I created a matlab framework for communicating with the LCr and uploaded it to GitHub.com, for the case anyone else is interested:

    TI-DLP-LightCrafter

    Best regards

    Jan

  • Hi Jan,

    Good to know.

    You may want to create another thread with the topic something like "MATLAB code to control LightCrafter(TM)" and provide the linke.

    We encourage forum users to continue providing utilities which will help others.

    Regards,
    Sanjeev