Announcement

Collapse
No announcement yet.

uLCD-320-PMD2 - String display

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

  • uLCD-320-PMD2 - String display

    Hello everyone! Woo! My first post. I purchased this screen, uLCD320PMD2, and i have been able to figure out Squares, lines, circles, and initializing. The one things which has eluded me some quite some time now is the String function. No matter what i do i just cant figure it out. So i decided to post. Hopefully someone can help sort me out. I am using a PIC16f690 uC. The screen works great, however, once i send the string command it assumes i am trying to start up the demo application on the screen which i don't understand since the letter 'd' is no where in the message. but help me out. I have posted the function below.

    Code:
    HTML Code:
    void LCD_STRING(int col, int row, int font, int16 colors, char str[]) {
      output_high(led2);//Task begins
    
          putc('s');
          putc(col);
          putc(row);
          putc(font);
          putc(make8(colors, 1));
          putc(make8(colors, 0));
    
    
    printf(str);    //  Sometimes this will simply display garbage symbols
    //sprintf(str);  //This will always send to demo mode
    
    
          putc(0x00);
     
      while(response != OLED_ACK) { if(kbhit ()) response = getc(); } //Wait for Ack
      output_low(led2);//Task complete
      delay_ms(10);  //Wait for it...
    }
    The way i am calling up the function is like this:
    LCD_STRING(1, 1, 0, 0xF0F0, &"Hello world");

    Thanks for taking the time! Ill try to post some pictures later if someone feels it would help.

  • #2
    Hello CidVilas,
    I think the problem is the way you send formated text to display. Keep in mind you cannot send any carriage return when sending text. Note that printf function send a "\n" (carriage return) after execution. Also try to send a pointer to the function parameter and send each character one by one.

    Here is a simple piece of code to do right:

    void LCD_DrawText(char column, char row, char font_size, char *mytext, int color)
    {
    printByte(0x73); // s (Formated text)

    // Adjust to center of the screen (26 Columns at font size 0)
    int newCol = 13 - (strlen(mytext)/2);
    //printByte(newCol); // column
    printByte(column); // column

    printByte(row); // row
    printByte(font_size); // font size (0 = 5x7 font, 1 = 8x8 font, 2 = 8x12 font)

    // Color
    printByte(color >> 8); // MSB
    printByte(color & 0xFF); // LSB

    for (int i=0 ; i<strlen(mytext) ; i++)
    {
    printByte(mytext[i]); // character to write
    }
    printByte(0x00); // string terminator (always 0x00)

    LCD_GetResponse();

    }

    Note that i have a custom function called printByte that only send a byte (8bits, one char) without any carriage return. Works fine for me on AVR and should be ok on PIC 16F too.

    Let me known if you got another issue.
    Happy coding!

    Regards,
    Oscar G.

    Oscar G.
    4D Systems Software Engineering
    http://www.bricogeek.com

    Comment


    • #3


      Wow thanks Oscar. I modified the code and ill try it when i get home. I am at school now. And thanks for the tutorial on your website about making a mini-oscilloscope. It was a very fun project, although i used pic.
      Thanks again for the rapid response. Ill post an update when i try this out.

      Comment


      • #4
        Hi CidVilas,

        My C is quite rusty - I usually program the PICs in Assembler.

        I don't think the Printf sends a "\n" unless it is in the format specifier (am I wrong?). What about using the %s specifier in the printf function, which indicates a null-terminated character array?

        Or as a test try replacing it with printf("TEST1 TEST2 TEST3");

        Howard
        _______________
        Best Regards,
        Howard

        Comment


        • #5


          4Dsysfan: thank you for the info. when i used printf("test1 test2 ... "); I managed to successfully display the text. However i still haven't managed to send the string through the function. Very strange.

          Oscar: Whether i scan through using a for loop or printf(); i only strange characters displayed on screen which do not resemble any character i am familiar with.

          Thank you for the help so far, i feel we are getting closer.

          Comment


          • #6


            Heres something new. So i managed to get something to pass through. i simply made the functions parameter a pointer and sent a charater array instead of attempting to use a string by using quotes.This works:char *a = "Hello world!";
            LCD_STRING(5, 3, 0, 0xFFFF, a
            );

            This gives me an error saying "Attempt to create a pointer to a constant"
            LCD_STRING(5, 3, 0, 0xFFFF, "Hello World
            "
            );

            and this doesnt give me an error but it does give me garbage on screen:
            LCD_STRING(5, 3, 0, 0xFFFF, &
            "Hello World");

            Hope someone knows the difference and can help me out. Thanks again

            Comment


            • #7


              Hi CidVilas,

              I think when you are declaring the string in the function it is actually allocating and creating a string constant.

              Did printf("%s",str); not work?

              In your function definition, what about:
              void LCD_STRING(int col, int row, int font, int16 colors, char *str) {
              then try
              LCD_STRING(5, 3, 0, 0xFFFF, "Hello World");

              I don't think &"Hello World" would work, since that would be the address of the address of the string constant????

              Again, sorry my C is so rusty, it's been like 10 years. Most of my work has been in assembler.......

              Howard
              _______________
              Best Regards,
              Howard

              Comment


              • #8


                Actually printf("%s", str); worked beautifully. Maybe im not understanding how this works correctly, but from all my trials it seems that the compiler wont allow direct string use but instead only constants.

                It will work when i declare a string contstant such as below:
                HTML Code:
                char *str = "Hello world!";
                LCD_STRING(5, 3, 0, 0xFFFF, str);
                
                but it wont work when i directly insert the string into the function:
                LCD_STRING(5, 3, 0, 0xFFFF, "Hello World!");
                It works fine but then it makes me think about how i will handle outputting values from variables within the program. Such as coordinates or voltage readings.

                Comment


                • #9


                  Hi CidVilas,
                  I usualy use defines for text on my proyects, also allways passing pointers to functions too.
                  You function paramter for text string must be char *mytext. then, define some text at the top of your code like #define MAIN_TEXT = "This is my text". Then pass it to function from the define. This work for fine for me.

                  This is a good idea to make defines for text for code escalability because you have all your texts joined at the top of your code. More easy to modify even to translate to other language (like spanish! hehe).

                  Algo for the colors, try to make a simple function that convert your 0xFFFF to something more useful. I use a custom function that requieres 3 parms (reg, green, blue) but i pass 0-255 values and returns a 16bits integer. With that i can draw using custom functions, but the color parameter goes with GetRGB(255, 255, 255). This is more easy to draw correct color insteed of 0x... Also if you draw some images, you do not need to convert values each time. Try to make your own or if you need this function just tell me and i paste here for you.

                  Try it and let me known.

                  Regards,
                  Oscar G.

                  P.D: Yeah, making a mini LCD osciloscope is so fun!
                  Oscar G.
                  4D Systems Software Engineering
                  http://www.bricogeek.com

                  Comment


                  • #10


                    Oscar, thanks for the help. Using Define is working good. The only thing i have been worried about is making the function display dynamic strings, such as having it output the voltage reading from a sensor on screen. This way i can use the screen as a debug tool as well. Just as example.
                    I would like to be able to print out numbers and values read from serial input.

                    And, yes please to the functions. I read your website and noticed you mentioned that you plan on releasing the functions you wrote for the uLCD using Arduino. No pressure but it would help out a lot as a reference tool.

                    Thanks again Oscar. Your a savior!

                    Comment


                    • #11


                      (char *) mystring;
                      float myvoltage;

                      mystring = "This is string 1";
                      LCD_STRING(5, 3, 0, 0xFFFF, mystring);

                      ....Go do something.....

                      mystring = "This is string 2";
                      LCD_STRING(5, 3, 0, 0xFFFF, mystring);

                      .....Go do something else......

                      myvoltage = 10.5;
                      sprintf(mystring, "Voltage = %f", myvoltage);
                      LCD_STRING(5, 3, 0, 0xFFFF, mystring);

                      I am assuming that
                      void LCD_STRING(int col, int row, int font, int16 colors, char *str) {
                      did not work? Again, I am REEEEEEALLLY rusty at this.....
                      _______________
                      Best Regards,
                      Howard

                      Comment


                      • #12


                        Since you are using (I assume) a PIC compiler, see this link.....

                        https://www.ccsinfo.com/forum/viewtopic.php?t=28755&sid=51a7b1262b4382ab5f2934b6118df7a7
                        _______________
                        Best Regards,
                        Howard

                        Comment


                        • #13


                          Thank you 4DSysfan. Ill try this out as soon as i get a chance and let you know. From looking at it i think it just may work perfectly. Thanks again!


                          myvoltage = 10.5;
                          sprintf(mystring, "Voltage = %f", myvoltage);
                          LCD_STRING(5, 3, 0, 0xFFFF, mystring);

                          Comment


                          • #14


                            Helo CidVilas
                            The proper method is to use a va_start function, as a ANSI C like compiler to send custom text to a function that manage the screen, but unfortunately it do not compile and it's not fully supported on Arduino hardware.

                            Also, the method indicated by 4DSysFan should work perfectly (using sprintf and then send to text drawing function with a text pointer).

                            And well, i will release some Arduino library to drive 4D Screens as soon as i have some free time to polish the code

                            Regards,
                            Oscar
                            Oscar G.
                            4D Systems Software Engineering
                            http://www.bricogeek.com

                            Comment

                            Working...
                            X