No announcement yet.

Simple sensor display OLED-96-G2 for serial arduino

  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple sensor display OLED-96-G2 for serial arduino

    Just got my 96-g2 display working (on an arduino) with the example "hello world" code thanks to some great help from the forum moderator. I would now like to take information from a simple photo resistor and send the values to the screen. It seems I can't use Display.putstr to send the data to the screen. How should I proceed? Here is my edited code:


    // include 4D Systems Goldelox library for Arduino
    #include <Goldelox_Const4D.h>
    #include <Goldelox_Const4DSerial.h>
    #include <Goldelox_Serial_4DLib.h>
    #include <Goldelox_Types4D.h>

    #define DisplaySerial Serial // define display serial port0

    Goldelox_Serial_4DLib Display(&amp;DisplaySerial); // declare this serial port

    void setup(void)
    //Reset the display, assuming Display is connected to Arduino via 4D Arduino Adaptor Shield
    pinMode(2, OUTPUT); // D2 on Arduino resets the Display
    digitalWrite(2, HIGH); // Reset Display
    delay(100); // 100ms Reset pulse
    digitalWrite(2, LOW); // Disable Reset

    delay(3000); // Allow time for the display to initialize before communicating
    Display.TimeLimit4D = 5000 ; // 5 second timeout on all commands
    DisplaySerial.begin(9600) ; // initialize serial port and set Baud Rate to 9,600
    Display.gfx_Cls() ; // clear display
    // Below this comment is the first string to be serially sent to the display.
    Display.putstr("Light:\n\n") ; // send "Light:" string to display


    void loop() {
    int sensorValue = analogRead(A0);
    Display.putstr(sensorValue); //Having difficulty here!

    Thank you!


  • #2

    Ok so no replies yet... This makes me think that I either asked a super stupid question, or have not made my question clear.

    So here goes again,

    I'd like to send sensor information from an Arduino, and have it show up on the screen. I have reviewed the arduino library and couldn't find a function to use. Maybe someone could put me on the right track, to even asking the right question?

    I have done this successfully to a regular serial LCD screen with just a few lines of code, so I know it must be possible, and I'm just missing something.

    Great display, keep up the good work 4D



    • #3


      Display.putstr(sensorValue); //Having difficulty here!
      You have to convert sensorValue (which is an integer) to a string.

      Try using the string constructor - String( )

      for example:


      Hope this helps.


      • #4

        Helps a great deal!!

        I understand what you are saying, and makes total sense. However, when I change the command to:


        I get the following error:

        sketch_nov05a.ino: In function 'void loop()':
        sketch_nov05a:35: error: no matching function for call to 'Goldelox_Serial_4DLib:utstr(String)'
        /Users/jordancraig/Documents/Arduino/libraries/Goldelox_Serial_4DLib/Goldelox_Serial_4DLib.h:99: note: candidates are: void Goldelox_Serial_4DLib:utstr(char*)

        Have also tried:

        photoIn = String(analogRead(A0), DEC);

        Thanks again for your assistance



        • #5


          Try using a character array instead. Like,

          int sensorVal; char bufIntToChar[12]; //create a character array for storing the integer-to-string value to be printed

          sensorVal = analogRead(A0);
          itoa(sensorVal, bufIntToChar, 10); //convert an integer to a character array, decimal. For more info, go to
          Display.putstr("value: "); Display.putstr(bufIntToChar); //print value

          Attached is a working example.

          Hope this helps.

          Attached files (2.3 KB)


          • #6

            I absolutely cannot thank you enough!!!! I'm going to pour over this code and learn all about it. It was really great of you to take the time to help me.

            maybe someday I'll be able to return the favor somehow>..

            All the very best,



            • #7
              Hi 4ders',

              I was having a similar issue, the solution above solved it. I was wondering, Is this the optimal solution? It appears verbose. Why isn't a library function for serial command putnum(format,value); supported, when it is so commonly used?


              • #8
                Good question.

                When SPE was designed the internal 'putnum' function was looked at, but since it only supported 16 bit integers and the expected hosts could support floats and complicated formats it was decided to leave it up to the hosts to do the 'conversion'.

                I don't know if one extra statement (the itoa) qualifies as 'verbose', of course it would be neater as a function on the host, but was kept inline in the example for clarity.


                • #9
                  I'm interested in the demo code, but get 403 error when I try to download, broken link?

                  Attached files (2.3 KB) [/QUOTE]


                  • #10
                    Not sure what is wrong with the link, it was however from 2013, but I managed to find it (same file name at least), see if this works for you.

                    Attached Files