No announcement yet.

Sleep mode (uLCD-32PT + Arduino MKR)

  • Filter
  • Time
  • Show
Clear All
new posts

  • Sleep mode (uLCD-32PT + Arduino MKR)


    We are developing a device with uLCD-32PT display and Arduino MKR-based board with multiple environmental sensors attached. We need to use some kind of sleep mode with the display, because the device is battery powered and current consumption is a big issue.

    We're using Workshop 4 Visi-genie Pro -version, with magic code triggering a timer to turn screen off after inactivity time (no touch detected). This works perfectly with backlight setting: a timer calls a function which changes the "screen saver" form with a full screen black button and set the contrast to 0. In this mode pressing the button sets the contrast back on (1) and opens the main form. Unfortunately the power saving is not enough with this, and we are having troubles with enabling sleep mode.

    By changing the contrast setting to sleep mode the display behaves mainly the same, but sometimes after waking up the display updates only one string at a time, approximately one string object/second. The Arduino has been set to send data to main form (13 string objects) in two seconds interval (non-blocking timer). Also every form change in the display reports a message to host, and the Arduino checks the correct form before sending anything. There are no blocking delays in the main loop of the Arduino, only millis() timers to collect data and send prints to display etc.

    Maybe the display goes to sleep during data transfer, and there's some kind of a buffer/ACK/NACK problem? Is it possible to put the display into sleep only if no data is going out or coming in? Seems like time to time the devices get out of sync during the sleep, because the next time after wake up from sleep everything might work just perfectly and the strings update fine and dandy.

  • #2

    Welcome to the forum.

    Yes, it does sound like it is out of sync when returning from sleep.

    Could you please let me know the method in how sleep is started and woken

    Best regards



    • #3
      Hi Paul,

      As said, we are using Visi-Genie (Pro), and the sleep mode is activated by magic codes:

      MagicTouch: touch detection to reset sleep timer after detected touches (prevent sleep if somebody is actually using the screen)
      sys_SetTimer(TIMER0, sleepTime);    // Reset sleep timer
      MagicCode0 (global): variables and sleep function to call
      var sleepTime := 60000; // Time in milliseconds (60 sec) after the display goes to sleep, if there is no touch event
      var sleepstate := 1; // Variable returns sys_sleep remaining time (init as 1 to enable re-sleep in main loop)
      // Timer Event handler
      func sleepFunction()
      ActivateForm(2);  // Open the screen saver: Form2
      sleepstate := sys_Sleep(65535); // Sleep for 65535 secs = 18h 12min 15sec (if no touch events)
      MagicCode2 (pre main): timer setting
      sys_SetTimerEvent(TIMER0, sleepFunction); // calls sleep func when TIMER0 goes to 0
      sys_SetTimer(TIMER0, sleepTime); // starts countdown in TIMER0 starting from the sleepTime value at global scope;
      MagicCode1 (main loop), only to put the display back to sleep if sys_sleep ends, and no touch detected
      if(sleepstate == 0) // After waking up from sleep
      sleepstate := 1;
      sys_SetTimer(TIMER0, sleepTime); // Reset sleep timer

      During the sleep mode, touching the screen wakes it up. As the screensaver Form2 with a full screen Userbutton is activated in the sleepFunction, we have tested both activating Form0 straight from the button Event or enabling Magic Event, so that other stuff could also be done (pause etc.) before returning to main Form0. No help there.

      MagicEvent0: optionally to call after returning from sleep
      func MagicEvent0(var newval)
      // pause(200);      // Just testing if the screen needs some time to wake up - not helping
      The display works well after initial device startup, it prints the incoming data as it comes. But after entering sleep for the first time and waking back up the connection seems somehow broken, as the object strings appear one at a time in one second intervals to the Form0. All the strings are being sent in 2sec intervals from the Arduino host, and it contains quite simple numerical data (floats and integers with a couple of decimals) and short strings (time/date etc.). Both the display and host are using the same baud rate (tested 9600-200000, now 115200) in a harware serial port.

      Edit: Changing the forms back and forth is being done as it prevents accidental button pushes and makes it possible to report active form to host. No display update is needed in sleep mode, and different forms have different objects to update. The host does this recognition.

      Last edited by dohf; 31 July 2020, 10:42 PM.


      • #4
        Thanks for the extra information.

        I can't see any obvious reason why it would become out of sync but I will do some testing based on the code snippets you have provided and see if I can get it out of sync on awaking from sleep.

        Best regards