itbrainpower.net
THE ALPHABET PROJECT - professional Arduino, BeagleBone & Raspberry PI shields



Read our last post: Modems and RaspberryPI 5. RaspberryPI OS [Debian 12 bookworm] notes.. Order u-GSM modems.

SAMD21G xyz-mIoT low power tips and tricks page 2 [optimize sleep current down to 35-37uA]



 

 

Basic patch the hardware for low power



If your xyz-mIoT shield have the P/N with "-LPR" suffix (Eg.: "XYZMIOT209#M95FA-UFL-0000000-LPR") skip this one and go to SAMD21G optimized low power software section.

If you are not sure about board PN, just identify if your board is populated with components marked as: "Remove those components from PCB" in Image 2. If both diodes are NOT populated, your xyz-mIoT shield meet the low power criteria and you may like to go directly to SAMD21G optimized low power software section.

Using a soldering iron with proper thin tip, remove the protection diodes highlighted in image bellow [on image marked as: "Remove those components from PCB"]. Set solder iron temperature around 320C. Add soldering flux to designated PCB areas before applying the soldering iron to PCB. A pincers with fine tips will be quite helpful.

This operation will be reflected in 200-250uA spared current consumption in SAMD21G SLEEP mode.

Other operations showed in Image 2 are related only to xyz-mIoT with modem and will be reflected in consumption decrease only in RUN mode with modem enabled. I recommend NOT to inactivate the LEDs before you finish your project development phase! ;)


Image 2. Basic hardware patches for low power.
xyz-mIoT shield SAMD21G hardware patches required for low power


Measuring the current using SAMD21 RTCC SLEEP ALARM - standard RTCC sleep software we obtained following values:
a. RUN mode, no UARTS enabled: ~9.67mA
b. RUN mode, both UARTS enabled but idle: ~11.00mA
c. SLEEP mode, no UARTS enabled / both UARTS enabled: 457uA / 1125uA

You may like to compare with initial current values measured here.

 

 

 

Optimized SAMD21G low power mode software with RTCC and one INPUT interrupt wake up.


1/*
2  SAMD21G optimized SLEEP software w. Serial and Serial1 activated for xyz-mIoT by itbrainpower.net shields.
3  version 0831c / 2020.02.29
4  
5  RTCC [w. wake at each 30secs - see reloadRTCC() function] and D7 as interrupt on LOW level detection wake up!
6  
7  Serial and Serial1 load/unload procedures for low power mode!
8  Crystal 32.768kHz precision oscillator [XOSC32K] was mentained for SLEEP.
9
10  WARNING: 
11 - use RTCC library from https://itbrainpower.net/downloads#xyz-mIoT
12 - disconnect USB from shield. Else, even not enabled, the consumption will be highier w. minimum 400uA 
13 - debug messages are provided via Serial1 --> connect 3.3V UART - USB adapter to xyz-mIoT shield RX0, TX1 and GND pads!!
14 
15  Dependencies: 
16 - SAMD21G RTCC library from https://itbrainpower.net/downloads#xyz-mIoT
17 - xyz-mIoT LowPower library from https://itbrainpower.net/downloads#xyz-mIoT
18
19
20  SLEEP consumption ~ 34-37uA powered bw. 3.3-4.1V* via LiPO pads* [Vbat and GND]. This should cover scenarios as powering from:
21  - LiPO, LiION rechargeable batteries [charging mechanism is mentained]
22  - Lithium primary batteries
23  
24  itbrainpower.net invests significant time in design phase of our IoT products and in associated software and support resources.
25  Support us by purchasing our IOT modems, IOT shields and sensors from here https://itbrainpower.net/order 
26  
27  Enjoy!
28 
29  Dragos Iosub, Bucharest 2020.
30  https://itbrainpower.net 
31 
32 */
33
34#include <xyz-mIoT_LowPower.h>
35
36#include <RTCZero.h> 
37
38RTCZero rtc;
39
40#define contactIN   7        //digital port used for wake up (...and having embedded weak pullup resistor, see docs) 
41
42#define RTCINT      1
43#define GPIOINT     2
44
45/* Change these values to set the current initial time */
46const byte seconds = 0;
47const byte minutes = 00;
48const byte hours = 17;
49
50/* Change these values to set the current initial date */
51const byte day = 17;
52const byte month = 11;
53const byte year = 15;
54
55int interruptMode = 0;
56
57
58void setup()
59{
60  delay(5000);          //do not remove this, else you may not be able to program the shield!!!!!
61  
62  interruptMode = 0;
63
64  xyzmIoTLowPower.begin();  
65  
66  xyzmIoTLowPower.ledBLINK(500,1);
67  
68  //SerialUSB.begin(115200);
69  xyzmIoTLowPower.loadSerial();     //modem UART
70  xyzmIoTLowPower.loadSerial1();    //external UART
71  
72  Serial1.println("test LPR");
73
74  rtc.begin();
75
76  rtc.attachInterrupt(RTCCalarmEvent);  
77  
78  initWakePin();    
79  xyzHibernate();
80}
81
82void loop()
83{
84  //SerialUSB.begin(115200);
85  xyzmIoTLowPower.loadSerial();     //modem UART
86  xyzmIoTLowPower.loadSerial1();    //external UART
87
88  switch(interruptMode)
89  {
90     case(RTCINT):
91        Serial1.println("RTC interrupt");
92        
93        xyzmIoTLowPower.ledBLINK(500,1);
94     break;
95     case(GPIOINT):
96        Serial1.println("GPIO interrupt");
97        
98        xyzmIoTLowPower.ledBLINK(100,2);    
99     break;
100     default:       //never here
101     break;
102  }
103
104  delay(2000);
105
106  xyzmIoTLowPower.ledBLINK(100,4);    
107  
108  xyzHibernate();  
109}
110
111
112void reloadRTCC()
113{
114  rtc.setTime(hours, minutes, seconds);
115  rtc.setDate(day, month, year);
116
117  rtc.setAlarmTime(17, 00, 30);
118  rtc.enableAlarm(rtc.MATCH_HHMMSS);
119}
120
121
122void RTCCalarmEvent()       //this is RTCC interrupt routine
123{
124  interruptMode = RTCINT;
125}
126
127void initWakePin()
128{
129  pinMode(contactIN, INPUT);                //default, D7 have a weak pullup embedded (10Mohms) - read xyz-mIoT documentation
130  attachInterrupt(contactIN, digitalINalarmEvent, LOW);
131}
132
133
134void digitalINalarmEvent()     //this is GPIO interrupt routine
135{
136  interruptMode = GPIOINT;
137}
138
139
140void xyzHibernate(void)
141{
142  interruptMode = 0;
143  reloadRTCC();
144  xyzmIoTLowPower.xyzSleep();
145}
146


Download above code (right click and save as) from: optimized_SAMD21G_SLEEP_RTCC_IN_INTERRUPT_0831c.

Download and install "xyz-mIoT LowPower library" class, from: xyz-mIoT download page.
Download and install SAMD21G RTCC library inside "xyz-mIoT shields RTCC and WDT Arduino classes" package, from: xyz-mIoT download page.

Compile the code, upload it to xyz-mIoT and remove USB cable. Now you will be able to measure the current consumptions. RTCC wake is set at each 30secs. Also, by placing D7 to LOW level, SAMD21G will WAKE. Yellow LED will blink once/twice when SAMD21G will enter ACTIVE mode and will blink 4 times before enter SLEEP mode.

Our measurement results for optimized SLEEP code
a. RUN mode, both UARTS enabled: 10.23mA
b. SLEEP mode: 35uA

Up-here results was obtained for all xyz-mIoT shields [with modems and modem-less] but w/o sensors [having "-0000000" PN suffix] after applying the hardware patch. Same results for low power optimized xyz-mIoT boards ["-0000000-LPR" suffix]

HINTS:
- Shield USB must be not connected! Even if is not activated in software, USB will contribute with minimum 400uA at total shield consumption!
- Serial1 it is used as debug port. To visualize debug messages, just connect one 3.3V compliant USB-UART adapter to RX0 and TX1 pins.

 

 

 

This article is under update!

 

 

 

TUTORIAL PROVIDED WITHOUT ANY WARRANTY!!! USE IT AT YOUR OWN RISK!!!!

 

 

 




 

 

 

Original how to written by Dragos Iosub & itbrainpower.net team

 

 

 

 

document version 0.911 / 2020-04-03 © R&D Software Solutions srl