Pages: [1]   Go Down
Author Topic: [leonardo] sleeping mode and serial  (Read 1108 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I try to save power on my leonardo. For that, I use the sleep mode.

Following code is working well:

Code:
#include <avr/sleep.h>

void wakeupFunction(){
}

void toSleep(){
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); 
  sleep_enable();
  attachInterrupt(0,wakeupFunction,LOW); //wakeupbutton : pin 3 on leonardo!!!
  sleep_mode();
  detachInterrupt(0);
  sleep_disable(); //fully awake now
}

void setup()

  Serial.begin(9600); // Debugging only
  pinMode(3, INPUT);
}

void loop()
{
  Serial.println("loop()");
  digitalWrite(13,HIGH) ;
  delay(1000);
  digitalWrite(13,LOW) ;
  toSleep();
}

I am happy, i can light my room with the little on board led.  But!

I am on windows 7, and after uploading this useful sketch, port COM is not usable. Board is detected by windows, port COM exists, but arduino 1.0.2 says that "port com is already in use" or "port com is not reachable". And I have to burn the bootloader to rescue my leonardo.

What the duck with serial on leonardo in sleep mode ?

Phil
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 210
Posts: 13029
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


USB slave devices are not allowed to go to sleep without permission from the host controller.  As you've discovered, sleeping without permission causes problems.


Put a delay in setup; I suggest five seconds.  When you want to work with your Leonardo...

• Ensure the Leonardo is not connected to the computer
• Start the Arduino IDE
• Load and compile an empty sketch
• Connect the Leonardo to the computer and execute Upload

You will have to experiment with the timing to get it right.  You may have to hold the RESET button on the Leonardo while connecting it to the computer then release RESET when you are ready to upload the empty sketch.  What you want to do is much easier for boards with the USB interface and processor separated.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!

This is the way I choose to wait for a miracle. Indeed I wait for an ebay nano arduino.

I wonder if leonardo is good choice for beginners...

Phil
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Last question:
In sleep mode (SLEEP_MODE_PWR_DOWN), leonardo eats 9mA.
How can I use a real power saving mode?

Phil
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 210
Posts: 13029
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


You probably have to turn off power to the USB pad.  Instructions are in the datasheet.  There may be an AVR Libc function to turn it off.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Phil,

did you solved the issue? I got the same problem you described on an Arduino Micro (same MCU as Leonardo, atmega32U4): after wake up the COM connection via USB is not working anymore.

To upload a new sketch I have to press and hold the reset button on Arduino, click upload on the Arduino IDE and release the reset button only after the "Uploading..." message appears in the message area if the IDE. No need to burn the bootloader again, at least for me.

I suspect that the Serial object needs to be reinitialized after wake up, but I can't figure out how to do that. I tried to call  Serial.begin(9600) after wake up, wait for Serial become "true", but that did not solve the problem.

Alessandro
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

I have the same issue: after using set_sleep_mode(SLEEP_MODE_PWR_DOWN) and sleep_cpu() the board does not respond to USB traffic any more. However, it is alive since I can see LED blinking as I programmed it to do according to sleep periods and watchdog wake-ups.

I read that an USB device that wants to sleep should somehow inform USB host that it goes to sleep. How to do that? Is there a way to wake up USB from this situation?

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I realize that this is an old thread but it is correct topic and several people raised the issue of correctly restarting the arduino after sleep. . I am using a ProMicro. On resume from sleep, is there a way to reinitialize the serial communications via the USB connector?

Appreciate any comments.
Logged

Pages: [1]   Go Up
Jump to: