Sleep code - Teensy 3.2

Status
Not open for further replies.

AIREL46

Member
I am using Teensy 3.2 and I need to program sleep code to save battery power.
I tried to use avr/sleep.h but it is not compatible with it.
Thanks to help me.
Best regards.
AIREL46
 
Snooze Teensy 3.2

Bonjour,
Merci de ta réponse qui correspond effectivement à mon besoin.
J'ai lu le fichier README, c'est pas très simple à comprendre.
Je voudrai trouver un exemple qui s'adapte à mon cas.
Mon programme consiste en la capture périodique (30 secondes) de 2 températures.
Le Teensy est alimenté par une batterie LI-ION.
Le déroulement du programme prend environ 2s, il reste donc 28s pour passer en "Snooze".
Donc, quel exemple choisir ?
AIREL46
 
First of all, with respect to the majority of users here, we should keep that conversation in English.

Everything depends on how your application will wake up. I think that in your case, the LPTMR is probably the simplest way to go. So you would declare a snoozeTimer driver, attach it to a snoozeBlock and configure it with setTimer(30000) to trigger a wake up every 30 seconds. In the loop() you would write your code to capture the temperatures before sending the Teensy back to sleep with deepSleep(). No need for an example, your use case seems so simple, you might go immediately live.
 
Sorry for french language and thank you for your answer.
I did write a small programme without my code to capture the temperatures (test.ino) but I meet new problem after checking with the Arduino IDE, I have un error message:
"SnoozeTimer" does not name a type

Best regards.
 

Attachments

  • test.ino
    370 bytes · Views: 123
Make sure that you have the latest Teensyduino 1.4.2 version installed, which includes the version 6.3.1 of the Snooze library. Then, you can compile your sketch without the error you mentioned, but it will give another error for your deepSleep() line. Replace it by Snooze.deepSleep(config) and it will work.

Code:
#include <Snooze.h>


const int led_pin_v = 13;//Led verte
// Load timer driver
SnoozeTimer timer;


// install timer driver to a SnoozeBlock
SnoozeBlock config(timer);
 
void setup()
{
  
  Serial.begin(9600);
  pinMode(led_pin_v, OUTPUT);
  timer.setTimer(30000);
    
}
 
void loop()
{
  digitalWrite(led_pin_v, HIGH);
  Snooze.deepSleep(config);
  digitalWrite(led_pin_v, LOW);
}
The compile result looks then like

Code:
Using library Snooze at version 6.3.1 in folder: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/Snooze 
Sketch uses 13336 bytes (5%) of program storage space. Maximum is 262144 bytes.
Global variables use 5044 bytes (7%) of dynamic memory, leaving 60492 bytes for local variables. Maximum is 65536 bytes.
 
Sleep mode - Teensy

After updating Snooze and copy your program, It is now OK.
The result is good: 46 mA in normal operation and 1.5 mA in sleep mode.
Thanks a lot for your help.
AIREL46
 
Sleep mode and serial monitor

The sleep mode operates properly but interrupts the console monitor.
The USB serial connexion operates with the /dev/ttyACM0 port.
Without the sleep mode this port is identified with lsusb command.
With the sleep mode this port is not identified with lsusb command.
The Teensy 3.2 works with Ubuntu 16.04 LTS.
Thank you to help me.
Airel46
 

Attachments

  • test.ino
    485 bytes · Views: 127
That's normal and intended behavior. The internal USB engine in the Teensy is disabled (as are most the internal peripherals) when it goes to sleep.

I also do not talk when I sleep... ;)
 
Sleep mode and serial monitor

OK, I understand that during sleep mode (28 secondes) the Teensy does not do anything.
But I do not understand that during normal mode (2 secondes) the teensy can not manage serial communication ?
 
Ah... you didn't write explicitly that the USB connection would also not be reactivated after the Teensy waking up. Normally it should come online when it is reactivated.

Try to add a Serial.begin(9600); after Snooze.deepSleep(config);

If that does not help, you'll probably have to add the usb_serial driver to your snooze config.
 
Sleep mode and serial monitor

Sorry because my English is not very good !

Exactly, the USB connection is not be reactivated after the Teensy waking up.
The question is how to reactivate the USB connection after the Teensy waking up?
 
Read the documentation of the Snooze library on GitHub. There is even a specific example with USB serial communication which shows how to add the SnoozeUSBSerial driver to your snooze configuration.
 
Sorry because my English is not very good !

Exactly, the USB connection is not be reactivated after the Teensy waking up.
The question is how to reactivate the USB connection after the Teensy waking up?
Yes look at the deepSleep_usb_serial example sketch. Also it takes sometimes a couple of seconds for the Teensy and your computer to establish usb communications again so rapid sleeping and waking just won't work.

Another option is to get Uart <-> USB converter, the Uart is available pretty much after waking if you already have it configured before hand.
 
Hi there! First of all, thank you very much for your activities!
This post has been interesting to me since I need a reliable way to put my teensy3.2 to sleep.
I used Ariels code (thx!) and updated it a little bit:

#include <Snooze.h>


const int led_pin_v = 13;//Led verte
// Load timer driver
//SnoozeTimer timer;
SnoozeDigital digital;
SnoozeUSBSerial usb;

// install timer driver to a SnoozeBlock
//SnoozeBlock config(timer);
SnoozeBlock config(usb, digital);

float j;

void setup()
{

Serial.begin(9600);
pinMode(led_pin_v, OUTPUT);
//timer.setTimer(30000);
digital.pinMode(7, INPUT_PULLUP, RISING);//pin, mode, type
}

void loop()
{

j=1+j;
Serial.print("j= ");
Serial.println(j);

digitalWrite(13, HIGH);
delay (20);
digitalWrite(13,LOW);
delay (20);

if (j>200)
{
delay(1000);
digitalWrite(led_pin_v, LOW);
delay(1000);
Serial.println("Bonne nuit SCAO");
Snooze.deepSleep( config );
delay(10000);
Serial.begin(9600);
Serial.println("Bonjour SCAO");
digitalWrite(led_pin_v, HIGH);
j=0;

}
}

It does:
1. count j to 200
2. go deepsleep
3. wake up on digital PIN 7
4. count again to 2000 (the LED is blinking the way it is supposed to:=))

BUT the serial monitor is strange:
1. Does not show Bonne nuit SCAO
2. Does not show Bonjour SCAO
3. After wake up does not show the counting any more

Per your suggestion I already gave it some seconds after waking up, I put an additional Serial.begin in there, added SnoozeUSBSerial usb. Any other ideas?

Your suggestions are greatly appreciated!

jani
 
Can you try the "deepSleep_usb_serial" example and make sure your "USB_Type:" in Arduino is "Serial".
 
It actually works, thanks!

I melted the example down to what I (teensy3.2, Button on PIN7) really need:

/***************************************
This shows the use of the Snooze USB Serial driver when using deepSleep.
The USB Serial driver does not wake the processor it only aids in using the USB
Serial in sleeping appilcations.
****************************************/
#include <Snooze.h>
// Load drivers
SnoozeDigital digital;
SnoozeUSBSerial usb;
/***********************************************************
Install drivers, timer to wake and USB Serial Driver to
fix printing to serial monitor after sleeping.
***********************************************************/
SnoozeBlock config_teensy32(usb, digital);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
while (!Serial);
delay(100);
Serial.println("Starting...");
delay(100);
/********************************************************
Define digital pins for waking the teensy up. This
combines pinMode and attachInterrupt in one function.
********************************************************/
digital.pinMode(7, INPUT_PULLUP, RISING);//pin, mode, type
}
void loop() {
/********************************************************
feed the sleep function its wakeup parameters. Then go
to deepSleep.
********************************************************/
Snooze.deepSleep( config_teensy32 );
// wait for serial monitor
elapsedMillis time = 0;
while (!Serial && time < 1000) {
Serial.write(0x00);// print out a bunch of NULLS to serial monitor
digitalWriteFast(LED_BUILTIN, HIGH);
delay(30);
digitalWriteFast(LED_BUILTIN, LOW);
delay(30);
}
// normal delay for Arduino Serial Monitor
delay(200);
Serial.println("Hi");
delay(1000);
}

Does that seem right to u?



The previous script worked finally fine, IF I manually restart the serial monitor after the first time pressing the button. Than after the second press the counting started again. Do you know

1. how I can avoid having to restart the monitor manually
2. why do I have to press the button twice?

Again, thx for your super quick help!
 
Can you please put your code between code brackets in this forum, it makes reading your code much easier. Just to be sure you are using the Arduino Serial Monitor and what OS?

I don't know why you have to push the button twice, you haven't shown or explained how your button is wired to the teensy but I can say that the digital wakeup has been tested many many times to work.
 
Status
Not open for further replies.
Back
Top