Wake and Sleep via Arduino 101?

Discussion in 'UDOO X86' started by YellowGTM, Nov 9, 2017.

  1. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    Hello All,

    I'm trying to program my X86 Advanced Plus to wake and sleep via an interrupt using the Arduino 101 interface.

    I have successfully been able to power on/off, however the reliability is quite low. Sometimes it will power
    down, and sometimes not. The BIOS has the Curie Power enabled (BIOS v1.03):
    Curie Power Management <Enabled>
    Power On Intel Curie <Enabled>

    The following instructions were used:

    https://www.udoo.org/docs-x86/Ardui...aswell_Power_Management_From_Arduino_101.html
    [​IMG]

    Is there a method to put the x86 in a 'sleep' state and 'wake' using a similar set of instructions?

    For example, on my wireless keyboard there is a "Power Button" that works flawlessly. Upon waking,
    it will default to the Windows 10 login Screen
    [​IMG]
    Thank you in advance for any tips and assistance on this task!
     
  2. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    With regards to the Arduino method, is it the interrupt that is failing to do the 5 times pin 9 sequence in 100 ms or is it the Braswell failing to recognize this sequence?

    The Udoo X86 has a front panel header for on/off and reset buttons. You can use them to set the Udoo X86 to sleep. It has to be configured in your OS. The header is explained in the pdf user manual that you can download here https://www.udoo.org/docs-x86/Hardware_Reference/Resources.html
     
  3. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    is it the interrupt that is failing to do the 5 times pin 9 sequence in 100 ms or is it the Braswell failing to recognize this sequence?

    I cannot answer that definitively. The Serial Monitor is reading the Pin 2 input voltage from the button.

    I'm not sure if the Arduino is failing to send a clean and proper clock pulse to the Braswell, and/or the Braswell is not acting on the signal. How can I test each side of the equation?

    Thank you for the tip on the Front Header. Perhaps I can use the hardware pins
    as a work-around until the software side is fixed.
     
  4. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    It could also be that the interrupt is failing at all. You can add a visual check by using the build in led (pin 13) to switch on/off when the pin 9 power sequence is called.

    Be sure that you do not have serial send/read within the interrupt loop because that could slow down things.
    And also keep the function that is called by the interrupt as short as possible. It is now only setting a parameter. Keep it that way. See also the Arduino documentation for this interrupt usage.
     
  5. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    Okay, I'll give it a try. Thank you.

    I have Serial.print in the Main loop; I'll try removing that for starters, but I don't believe that will interfere with the function.

    The code was copied and started out as:
    Code:
    void power_interrupt(){
       power_pressed = true;
    }
    
    void loop(){
    if (power_pressed) {
        for(int i=0; i<5; i++) {
          digitalWrite(reset_pin, LOW);
          delay(pulse_time); /* Reset pin goes LOW for 8ms */
          digitalWrite(reset_pin, HIGH);
          delay(pulse_time); /* Reset pin goes HIGH for 8ms */
        }
        power_pressed = false;
      }
      delay(10);
     }
    
     
    Last edited: Nov 10, 2017
  6. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    The code now reads. Neither of these attempts are reliable:

    Code:
    void power_interrupt() {
     
      /* When the button (connected to the Pin 2) is pressed, the attached interrupt runs this routine */
    
      //Sleep mode values may need to change based on Serial Monitor values
      if((sleepMode >= 1.5) && (!executed)){
        power_pressed = true;
        executed = true;
      }
        else power_pressed = false;
     
      delay(100);
     
      //Sleep mode values may need to change based on Serial Monitor values
      if((sleepMode <= 1.5) && (executed)) {
     
        power_pressed = true;
        executed = false;
      }
        else power_pressed = false;
     
      delay(100);
     
    }
    
    void setup() {
     
      Serial.begin(57600);
      pinMode(sleepMode, INPUT);
      pinMode(reset_pin, OUTPUT);
      digitalWrite(reset_pin, HIGH);
    
      pinMode(input_pin, INPUT);
      attachInterrupt(digitalPinToInterrupt(input_pin), power_interrupt, RISING);
    }
    
    void loop() {
     
      sleepMode = analogRead(A0);
    
      if (power_pressed) {
        for(int i=0; i<5; i++) {
          digitalWrite(reset_pin, LOW);
          delay(pulse_time); /* Reset pin goes LOW for 8ms */
          digitalWrite(reset_pin, HIGH);
          delay(pulse_time); /* Reset pin goes HIGH for 8ms */
        }
        power_pressed = false;
      }
     
      Serial.print("Sleep Mode: ");
      Serial.print(sleepMode);
      Serial.print(',');
      Serial.print("Executed Flag: ");
      Serial.print(executed);
      Serial.print(',');
      Serial.print("Power Pressed: ");
      Serial.println(power_pressed);
    
     
      delay(10);
    }
    [the moderation edit was to move the code into the code box]
     
    Last edited by a moderator: Nov 10, 2017
  7. Laura

    Laura UDOOer

    Joined:
    Apr 22, 2016
    Messages:
    374
    Likes Received:
    156
    What resister are you using? 10K is a good value for pulldown.

    I have adapted the code to instead use the internal pullup resister, and it works very well (apart from when I initially forgot to set the input pullup and the board would power up and down whenever my hand was near it o_O). I'm stil adapting the code, and will share soon. I am adding code for debouncing the button.
     
    waltervl likes this.
  8. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    I'm using a 1K5 for pull-down; I'll try a 10K as that will only help with the trigger voltage sensing!
     
  9. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    I am adding code for debouncing the button.

    You can also add a small capacitor, close to the switch to help with the debounce. Try something like 10- 100 nF.
     
  10. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    The 10K resistor seems to work much better. I'll have to test it over a longer period of time to know for certain. Now that it's behaving like it should, I can
    try using a voltage input to Pin 2 as opposed to a push-button.

    On another note, my second x86 Advanced (not plus) will not update the BIOS
    from 1.02 to 1.03? The Command window shows that it updated successfully
    and I need to re-boot to complete. When I check the version number, it remains
    the same.

    I'll start another thread I suppose, but if anyone has seen this before, please
    let me know the fix!
     
  11. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    More updates as I continue to develop this code. Notice the change in the
    interrupt condition from "RISING" to "CHANGE". This is because I'm using
    a voltage source (positive ON, ground OFF) to trigger the Sleep Mode of the
    UDOO

    You can view the definitions for AttachInterrupt here:
    https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

    Code:
    int reset_pin = 9;    /* Triggers the power signal */
    int input_pin = 2;    /* Input Button connected. Set in pull down with a resistor */
    
    volatile boolean power_pressed = false;
    
    void power_interrupt() {
    
        power_pressed = true;
    }
    
    
    void setup() {
     
      pinMode(reset_pin, OUTPUT);
      digitalWrite(reset_pin, HIGH);
     
      pinMode(input_pin, INPUT);
      attachInterrupt(digitalPinToInterrupt(input_pin), power_interrupt, CHANGE);
    }
    
    void loop() {
    
     
      if (power_pressed) {
        for(int i=0; i<5; i++) {
          digitalWrite(reset_pin, LOW);
          delay(8); /* Reset pin goes LOW for 8ms */
          digitalWrite(reset_pin, HIGH);
          delay(8); /* Reset pin goes HIGH for 8ms */
        }
        power_pressed = false;
       
      }
     
      delay(10);
    }
    
     
  12. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    None of these examples work correctly. :mad:

    I can only get the module to turn off once, and turn on once, then nothing happens.
    I have to shutdown and reboot just to get one cycle.

    Is there a method to cycle sleep mode continuously using a voltage signal
    as opposed to a button?

    BIOS 1.03

    Thank you again for any tips
     
  13. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    This is a video of what I'm experiencing.
     
  14. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    This also happens with the hardware switch on the board (next to the IR sensor).
    You can press the button twice to cycle off/on, but then it stops working. This is obviously an issue
    with the Braswell/Intel.

    Now I have just read that the Curie is no longer supported by Intel and the x86 may no longer exist.

    Great. Time to redevelop and I just started designing...:mad:
     
  15. Laura

    Laura UDOOer

    Joined:
    Apr 22, 2016
    Messages:
    374
    Likes Received:
    156
    That is odd.

    Does the power indicator on the board cycle between orange and green?

    Could you please enter the firmware settings, and check on the first settings page that it is version 1.03.

    I will install your sketch tomorrow, and check what might be causing the issue.
     
  16. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    Thank you Laura!

    The LED does change from Green to Orange when sleeping.

    BIOS VERSION - 1.03
    PROJECT NAME - UDOO x86
    RELEASE DATE - 08/04/2017

    SETTINGS:
    Power Fail Resume Type_______<Always ON>
    WIFI on M.2______________ <Enabled>
    Bluetooth on M.2__________ <Enabled>
    Instant Off_______________ <Enabled>
    Power On Intel Curie_______ <Enabled>
    Curie Power Management _ <Enabled>
    Curie Reset on poweron ___<Enabled> (also tried Disabled)
    Infrared Support____________<Disabled>
    Wake on PME_____________<Disabled> (also tried Enabled)
    Wake on RTC from S5______<Disabled>
     
  17. Laura

    Laura UDOOer

    Joined:
    Apr 22, 2016
    Messages:
    374
    Likes Received:
    156
    The default configuration in Windows 10 is for the power button to put the system to sleep. For some reason, Windows 10 is having an issue putting the system back to sleep a second time. The issue does not occur in Fedora, and most likely other Linux systems.

    For now, I suggest changing the power configuration in Windows, for the button to turn the system off. In the control panel, choose Hardware and Sound, and there will be an option for changing the default behaviour of the power buttons.

    @YellowGTM Regarding your configuration, may I ask why you are using a voltage divider and 12V source, instead of the 3V3 source pin which would not need a divider?
     
  18. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    Thank you so much for the quick support! I'll try the settings and update the
    thread with my results.

    The reason for the voltage divider is because this project will be going into a
    car. I will eventually update the divider circuit to have a regulator and EMI/
    transient filtering as the vehicle voltage is higher and will fluctuate.
     
  19. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    It appears the settings for Power and Sleep were both at "Sleep" all of this time.

    Is there anything else I can try, or is this a firmware issue?
    Thanks.
     
  20. YellowGTM

    YellowGTM Member

    Joined:
    Sep 21, 2017
    Messages:
    56
    Likes Received:
    3
    FYI:
    The sleep button on my wireless keyboard works perfectly via USB dongle.

    It appears the issue is on the Arduino 101 side?
     

Share This Page