Announcement

Collapse
No announcement yet.

Display Images via Serial

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Display Images via Serial

    Hi All,

    I'm using a Gen4-uLCD-24DT to display some images. I have a programme working with no issues in WS4 on the screen with images from the SD card. However, I want to use the screen as a slave to an ESP32.

    I've followed the "Serial Arduino Displaying Images from the uSD Card FAT16" guide, loaded the images onto the SD card, using WS4, done and SPE load on the 24DT and connected it up to the ESP32. The ESP32 'seems' to communicate fine with the screen, resets the screen, changes background colour and displays the text from the demo but NOT the images (which are on the SD card), no matter what I try. I'm not getting an error back to say the card hasn't been mounted and the checked content is on there. Also double checked the image names and handles and all appear correct? It’s probably something obvious I'm missing but can’t figure out what. Has anyone had issues with that demo, is the demo code right? Noted it was for the Picaso processor but I added in the Diablo library's in to my Arduino code.

    Thought about testing with the Serial Commander tool to see if I could access the images that way but can’t find a command sequence other than one for the Picaso processor which didnt work...(it did acknowledge mounting the SD card though) but couldn’t seem to pull the images back.

    Any advice help would be really appreciated

    Richard


    Arduino Code:

    Code:
    //Arduino Uno (host controller) + uLCD-32PTU (serial slave device) Basic Demo
    //4D Systems: http://www.4dsystems.com.au
    //December 13, 2013
    
    //Demonstrates how to display images on a 4D display module using an Arduino host
    //You need to configure the display module as a serial slave
    //For more information, see the documentation for this sketch:
    //4D-AN-P5005 Serial Displaying Images using an Arduino Host
    //http://www.4dsystems.com.au/appnotes/
    
    //This demo is based on the BiGDemo in Workshop
    //File --> Samples --> Picaso Serial --> Arduino <open README.txt for instructions on installing the library>
    //See the BigDemo sketch for a demonstration of all the SPE functions
    //All functions are defined in the PICASO Serial Command Set Reference Manual
    //http://www.4dsystems.com.au/downloads/Software/4D-Workshop4-IDE/Docs/Serial/PICASO-SPE-COMMAND-SET-REV1.13.pdf
    
    #include "Diablo_Serial_4DLib.h"
    #include "Diablo_Const4D.h"
    
    //Setup communication - 1.Hardware serial OR 2.Software serial
    
    //1. Hardware Serial - choose a serial port
    //---------------------------------------------------------
    //Serial0 cannot be used for the display since it will be used for logging messages
    //#define DisplaySerial Serial1
    //#define DisplaySerial Serial2
    //#define DisplaySerial Serial3
    //---------------------------------------------------------
    
    //2. Software Serial - set the desired pins
    //----------------------------------------------------------------------
    #include <SoftwareSerial.h>
    SoftwareSerial DisplaySerial(16,17) ; // pin 10 = TX of display, pin 11 = RX
    //SoftwareSerial is not yet supported by the Arduino Due
    //----------------------------------------------------------------------
    
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    
    //enable message logging
    #define LOG_MESSAGES // <-- to disable message logging, comment out this line
    #ifdef LOG_MESSAGES
    #define HWLOGGING Serial
    #else
    #define HWLOGGING if (1) {} else Serial
    #endif
    
    //global variables
    int frame = 0;
    int disk;
    word hndl;
    int iUserimages1 = 0, iUserimages2 = 1, iImage1 = 2;
    
    void setup() {
    //For handling errors
    Display.Callback4D = mycallback ;
    
    //5 second timeout on all commands
    Display.TimeLimit4D = 5000 ;
    
    #ifdef LOG_MESSAGES
    HWLOGGING.begin(115200);
    HWLOGGING.println(F("\nDisplay Images using an Arduino Host Demo w/ Message Logging"));
    #endif
    
    //--------------------------------Optional reset routine-----------------------------------
    //Reset the Display using D4 of the Arduino (if using the new 4D Arduino Adaptor - Rev 2)
    //If using the old 4D Arduino Adaptor (Rev 1), change D4 to D2 below.
    //If using jumper wires, reverse the logic states below.
    //Refer to the accompanying application note for important information.
    pinMode(21, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
    digitalWrite(21, 0); // Reset the Display via D4
    delay(100);
    digitalWrite(21, 1); // unReset the Display via D4
    //-----------------------------------------END---------------------------------------------
    
    delay (5000); //let the display start up
    
    //start
    DisplaySerial.begin(9600) ;
    Display.gfx_ScreenMode(PORTRAIT);
    
    //uSD card mount routine
    Display.putstr("Mounting...\n"); //print a string
    if(!(Display.file_Mount()))
    {
    while(!(Display.file_Mount()))
    {
    Display.putstr("");
    HWLOGGING.println(F("\nDrive not mounted..."));
    delay(200);
    Display.gfx_Cls();
    delay(200);
    }
    }
    
    Display.gfx_BGcolour(WHITE) ; //change background color to white
    Display.gfx_Cls(); //clear the screen
    
    //load the graphics files
    hndl = Display.file_LoadImageControl("user_img.dat", "user_img.gci", 1) ;
    
    Display.img_Show(hndl,iImage1) ; //show the penguin
    Display.gfx_Set(TRANSPARENCY, ON); //turn on transparency
    Display.gfx_Set(TRANSPARENT_COLOUR, 0x3000); //make this color transparent
    
    Display.img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; //where frame is 0 to 4
    Display.img_Show(hndl,iUserimages1) ; //show the left eye
    
    Display.img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    Display.img_Show(hndl,iUserimages2) ; //show the right eye
    
    Display.txt_BGcolour(WHITE); //change text background colour to white (default is black)
    Display.txt_FGcolour(BLACK); //change text foreground colour to black (default is green)
    Display.txt_MoveCursor(23, 6); //move text cursor to and start printing at row 23, col 6
    }
    
    void loop() {
    static int n = 1; //counter
    
    frame = 0; //eyes open
    Display.img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // left eye
    Display.img_Show(hndl,iUserimages1) ;
    Display.img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // right eye
    Display.img_Show(hndl,iUserimages2) ;
    Display.putstr(" Robot is happy. \r");
    delay(2000);
    
    frame = 1; //eyes closed
    Display.img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // left eye
    Display.img_Show(hndl,iUserimages1) ;
    Display.img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // right eye
    Display.img_Show(hndl,iUserimages2) ;
    delay(100);
    
    frame = 2; //eyes sad
    Display.img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // left eye
    Display.img_Show(hndl,iUserimages1) ;
    Display.img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // right eye
    Display.img_Show(hndl,iUserimages2) ;
    Display.putstr(" Robot is sad. \r");
    delay(2000);
    
    frame = 1; //eyes closed
    Display.img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // left eye
    Display.img_Show(hndl,iUserimages1) ;
    Display.img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // right eye
    Display.img_Show(hndl,iUserimages2) ;
    delay(100);
    
    frame = 3; //eyes surprised
    Display.img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // left eye
    Display.img_Show(hndl,iUserimages1) ;
    Display.img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // right eye
    Display.img_Show(hndl,iUserimages2) ;
    Display.putstr("Robot is surprised.\r");
    delay(2000);
    
    frame = 1; //eyes closed
    Display.img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // left eye
    Display.img_Show(hndl,iUserimages1) ;
    Display.img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // right eye
    Display.img_Show(hndl,iUserimages2) ;
    delay(100);
    
    frame = 4; //eyes angry
    Display.img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // left eye
    Display.img_Show(hndl,iUserimages1) ;
    Display.img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // right eye
    Display.img_Show(hndl,iUserimages2) ;
    Display.putstr(" Robot is angry. \r");
    delay(2000);
    
    frame = 1; //eyes closed
    Display.img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // left eye
    Display.img_Show(hndl,iUserimages1) ;
    Display.img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // right eye
    Display.img_Show(hndl,iUserimages2) ;
    delay(100);
    
    #ifdef LOG_MESSAGES
    HWLOGGING.print(F("\nCount = "));
    HWLOGGING.print(n);
    #endif
    n++;
    }
    
    //Error-handling routine
    //this will execute when a communication error occurs
    void mycallback(int ErrCode, unsigned char Errorbyte)
    {
    #ifdef LOG_MESSAGES
    const char *Error4DText[] = {
    "OK\0", "Timeout\0", "NAK\0", "Length\0", "Invalid\0" }
    ;
    HWLOGGING.print(F("Serial 4D Library reports an error: ")) ;
    HWLOGGING.print(Error4DText[ErrCode]) ;
    HWLOGGING.print(F("\n"));
    
    if (ErrCode == Err4D_NAK)
    {
    HWLOGGING.print(F("returned data = ")) ;
    HWLOGGING.print(Errorbyte) ;
    }
    else
    HWLOGGING.println(F("")) ;
    
    HWLOGGING.println(F("Program cannot proceed further. Please reset the display.")) ;
    while(1) ; // you can return here, or you can loop
    
    #else
    // Pin 13 has an LED connected on most Arduino boards. Just give it a name
    int led = 13;
    pinMode(led, OUTPUT);
    while(1)
    {
    digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
    delay(200); // wait for 200 ms
    digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
    delay(200); // wait for 200 ms
    }
    #endif
    }

    WS4 Code

    Code:
    #platform "Gen4-uLCD-24DT"
    #inherit "4DGL_16bitColours.fnc"
    #inherit "VisualConst.inc"
    #inherit "user_imgSmallConst.inc"
    
    var frame := 0;
    
    func main()
    
    gfx_Set(SCREEN_MODE,PORTRAIT) ;
    putstr("Mounting...\n");
    if (!(file_Mount()))
    while(!(file_Mount()))
    putstr("Drive not mounted...");
    pause(200);
    gfx_Cls();
    pause(200);
    wend
    endif
    
    gfx_BGcolour(WHITE);
    gfx_Cls();
    
    hndl := file_LoadImageControl("user_img.dat", "user_img.gci", 1);
    
    img_Show(hndl,iImage1) ;
    gfx_Set(TRANSPARENCY, ON);
    gfx_Set(TRANSPARENT_COLOUR, 0x3000); //make the penguin eyes background colour transparent
    
    img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages1) ;
    
    img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages2) ;
    
    
    repeat
    
    frame:=0; //eyes open
    img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages1) ;
    
    img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages2) ;
    pause(2000);
    
    
    frame:=1; //eyes closed
    img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages1) ;
    
    img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages2) ;
    pause(100);
    
    
    frame:=2; //eyes sad
    img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages1) ;
    
    img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages2) ;
    pause(2000);
    
    frame:=1; //eyes closed
    img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages1) ;
    
    img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages2) ;
    pause(100);
    
    frame:=3; //eyes surprised
    img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages1) ;
    
    img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages2) ;
    pause(2000);
    
    frame:=1; //eyes closed
    img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages1) ;
    
    img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages2) ;
    pause(100);
    
    frame:=4; //eyes angry
    img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages1) ;
    
    img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages2) ;
    pause(2000);
    
    frame:=1; //eyes closed
    img_SetWord(hndl, iUserimages1, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages1) ;
    
    img_SetWord(hndl, iUserimages2, IMAGE_INDEX, frame) ; // where frame is 0 to 4
    img_Show(hndl,iUserimages2) ;
    pause(100);
    
    forever
    
    endfunc
    orenza
    Junior Member
    Last edited by orenza; 14 January 2022, 01:09 AM.

  • #2
    Hi, Just to add to this I'm still at a loss where I'm going wrong... Tested the card with the uSD Tester tool which has confirmed that it can mount the card and see a .GFX file on there. Next tried the I “SPE Load” and Serial Commander applications, but struggling with the commands as the example given dont seem to match, I can run gfx_Cls and Media_init, both get work and get Ack back. How do I then read in the image and display it? In the examples given I don't have a Hword and Lword ref in my Diablo? Tried going with 0,0 as its the only image on there and the hex code in the file suggests its at that ref, then tried Media_Image to display it but I get nothing back? Would really appreciate anyone's advice on what teh commands should be and on the original issue above. Thanks all. - Richard

    Comment


    • #3
      Sorted this now Issue with the code.

      Comment

      Working...
      X