# The Things Node : new low power library development

**URL:** <https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521>\
**Category:** End Devices (Nodes)\
**Created:** [February 11, 2018, 4:38pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521 "2018-02-11T16:38:17Z")\
**Posts on this page:** 20\
**Page:** 6

<div class="post-metadata">

**Author:** ![BoRRoZ](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/borroz/32/44234_2.png) [@BoRRoZ](https://www.thethingsnetwork.org/forum/u/BoRRoZ)\
**Post date:** [February 26, 2018, 8:37am UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/120 "2018-02-26T08:37:24Z")

</div>

Charles, I suggest maybe to contact Phang, because his node with the RN2483 interrupt works flawless… _but probably not easy to implement without a separate wire_

I checked yesterday for a few minutes, did the current meassurement and thought everything worked fine 🙄

- timing after waking up… reinitialize uart connection / delay ?

---

<div class="post-metadata">

**Author:** ![HanspeterH](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/hanspeterh/32/35697_2.png) [@HanspeterH](https://www.thethingsnetwork.org/forum/u/HanspeterH)\
**Post date:** [February 26, 2018, 9:41am UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/121 "2018-02-26T09:41:43Z")

</div>

> [@BoRRoZ](#):
>
> where do you watch that data… Cayenne or the TTN console ?

I look at the data in the console (app, data) there I get  
10:28:392014  
payload:0100010200000300000402014B056700E00665007B0771FFFA000603FEaccelerometer\_7.x:-0.006accelerometer\_7.y:0.006accelerometer\_7.z:1.022analog\_in\_4:3.31digital\_in\_1:1digital\_in\_2:0digital\_in\_3:0luminosity\_6:123temperature\_5:22.4

In Cayenne also… there I get  
 ![grafik](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/0/0d7188e06135364faad5a7473f2e03fcc408c9d3.png)

and in node red where I also log it to a file  
{ “accelerometer\_7”: { “x”: -0.006, “y”: 0.006, “z”: 1.022 }, “analog\_in\_4”: 3.31, “digital\_in\_1”: 1, “digital\_in\_2”: 0, “digital\_in\_3”: 0, “luminosity\_6”: 123, “temperature\_5”: 22.4 }  
and in the log written bei node red:  
{“accelerometer\_7”:{“x”:-0.006,“y”:0.006,“z”:1.022},“analog\_in\_4”:3.31,“digital\_in\_1”:1,“digital\_in\_2”:0,“digital\_in\_3”:0,“luminosity\_6”:123,“temperature\_5”:22.4}

its, everywhere the same data I see…right now the node is behaving normally, except the doigital 3 value always zero.

---

<div class="post-metadata">

**Author:** ![Charles](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/charles/32/45146_2.png) [@Charles](https://www.thethingsnetwork.org/forum/u/Charles)\
**Post date:** [February 26, 2018, 11:40am UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/122 "2018-02-26T11:40:56Z")

</div>

> [@BoRRoZ](#):
>
> Charles, I suggest maybe to contact Phang, because his node with the RN2483 interrupt works flawless… but probably not easy to implement without a separate wire
> 
> timing after waking up… reinitialize uart connection / delay ?

@BoRRoZ Phang use an ATmega 328p that do not have USB, so it’s less tricky, I can just try to disable USB totally (but you need to reset the node to upload sketch). Anyway for low power I will try to disable totally USB, and may be activate it back only for example if button is pressed longer than 2s, I need to add some features depending on button press 😉

---

<div class="post-metadata">

**Author:** ![rocketscream](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/rocketscream/32/45934_2.png) [@rocketscream](https://www.thethingsnetwork.org/forum/u/rocketscream)\
**Post date:** [February 26, 2018, 12:01pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/123 "2018-02-26T12:01:17Z")

</div>

Rob and Charles, take a look at my guidelines [here](http://www.rocketscream.com/blog/forums/topic/adafruit-feather-32u4-). The 32U4 external interrupt itself is already on the RX pin, so no need extra wires.

---

<div class="post-metadata">

**Author:** ![Charles](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/charles/32/45146_2.png) [@Charles](https://www.thethingsnetwork.org/forum/u/Charles)\
**Post date:** [February 26, 2018, 3:21pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/124 "2018-02-26T15:21:34Z")

</div>

@rocketscream  
Interesting looking at the Arduino source code so see `detach()` emtpy !!

anyway `attach()` do all the trick even powering back on UVREGE so something like that should do the trick

```auto
void TheThingsNode::deepSleep(void)
{
  // We want to be awake by LoRa module ?
  if (this->pttn) {
    // watchdog Not needed, avoid wake every 8S
    WDT_stop(); 

    // Set LoRa module sleep mode
    this->pttn->sleep(this->intervalMs);
    // This one is not optionnal, remove it
    // and say bye bye to RN2483 or RN2903 sleep mode
    delay(50);

    // Module need to wake us with interrupt
    attachInterrupt(TTN_LORA_SERIAL_RX_INT, TTN_SERIAL_LORA_FN, FALLING);

    // switch all interrupts off while messing with their settings  
    cli();  
    bitSet(EIFR,INTF2); // clear any pending interrupts for serial RX pin (INT2 D0)
    sei();

  } else {
    // watchdog needed for wakeup
    WDT_start(); 
  }

  ADCSRA &= ~_BV(ADEN);
  MCUCR |= (1 << JTD);
  USBCON |= (1 << FRZCLK); // Disable USB clock 
  PLLCSR &= ~_BV(PLLE); // Disable USB PLL
  USBCON &= ~_BV(USBE); // Disable USB
  UHWCON &= ~_BV(UVREGE); // Disable USB Regulator
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_mode(); //Sweet dreams!

  //wake up, after ISR we arrive here ->
  sleep_disable();
  power_all_enable();
  USBDevice.attach(); 
  ADCSRA |= (1 << ADEN);
}

```

The file to look at in Arduino IDE is this one

> <https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/USBCore.cpp>

---

<div class="post-metadata">

**Author:** ![Charles](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/charles/32/45146_2.png) [@Charles](https://www.thethingsnetwork.org/forum/u/Charles)\
**Post date:** [February 28, 2018, 10:02pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/125 "2018-02-28T22:02:53Z")

</div>

Hi there,

Major update, just to let you know I’ve pushed a bug fix (almost it seems) version with optimized Low Power (disable USB regulator) mode.  
Sounds like working fine on my side, please note that for now, only sketch [BatteryMonitorLPP](https://github.com/ch2i/arduino-node-lib/blob/master/examples/BatteryMonitorLPP/BatteryMonitorLPP.ino) is so optimized.  
So If it’s okay on your side, I will include these optimization on the others examples and do a pull request

Please note that for advanced Ultra Low Power techniques, all unneeded peripherals are disable during sleep mode, including USB Management. This means you won’t be able to upload anymore if the node is sleeping and when wake up, Lora transmission is approx 3s (including receive windows) this means that you have 3 seconds windows to upload, so unless you’re lucky, it’s almost impossible to sync Arduino compilation and upload.  
But to avoid this, you can press the node button for more than 2s, then the led will yellow blink quickly for 60s, letting you time to upload

@BoRRoZ, I’m interested in some sleep mode measurement of this sketch 😉

---

<div class="post-metadata">

**Author:** ![Charles](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/charles/32/45146_2.png) [@Charles](https://www.thethingsnetwork.org/forum/u/Charles)\
**Post date:** [February 28, 2018, 11:10pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/128 "2018-02-28T23:10:57Z")

</div>

wooooow love it 😉  
thanks for your help, and I love your scope…

---

<div class="post-metadata">

**Author:** ![BoRRoZ](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/borroz/32/44234_2.png) [@BoRRoZ](https://www.thethingsnetwork.org/forum/u/BoRRoZ)\
**Post date:** [March 1, 2018, 8:27am UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/129 "2018-03-01T08:27:00Z")

</div>

![x703](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/4/4de8646bfa50190d13cf82d73de7552d6105cde4.jpg)

TTN node with CH2I mod 😉

---

<div class="post-metadata">

**Author:** ![HanspeterH](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/hanspeterh/32/35697_2.png) [@HanspeterH](https://www.thethingsnetwork.org/forum/u/HanspeterH)\
**Post date:** [March 1, 2018, 11:51am UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/130 "2018-03-01T11:51:26Z")

</div>

> [@BoRRoZ](#):
>
> TTN node with CH2I mod 😉

I am running the newest LPP sketch also. Seems to work ok… also the yellow led blinking mode.  
But why a second button?? What is the CH21 mod?

---

<div class="post-metadata">

**Author:** ![Charles](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/charles/32/45146_2.png) [@Charles](https://www.thethingsnetwork.org/forum/u/Charles)\
**Post date:** [March 1, 2018, 11:52am UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/131 "2018-03-01T11:52:28Z")

</div>

Yeah, why did you add the reset button @BoRRoZ ?

---

<div class="post-metadata">

**Author:** ![BoRRoZ](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/borroz/32/44234_2.png) [@BoRRoZ](https://www.thethingsnetwork.org/forum/u/BoRRoZ)\
**Post date:** [March 1, 2018, 11:55am UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/132 "2018-03-01T11:55:26Z")

</div>

syncing after deepsleep

---

<div class="post-metadata">

**Author:** ![Charles](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/charles/32/45146_2.png) [@Charles](https://www.thethingsnetwork.org/forum/u/Charles)\
**Post date:** [March 1, 2018, 11:56am UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/133 "2018-03-01T11:56:30Z")

</div>

> [@BoRRoZ](#):
>
> syncing after deepsleep

You just need to press the original button for over 2s and the release it, you’ll have 60seconds (led blink yellow) then to sync 😉

---

<div class="post-metadata">

**Author:** ![BoRRoZ](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/borroz/32/44234_2.png) [@BoRRoZ](https://www.thethingsnetwork.org/forum/u/BoRRoZ)\
**Post date:** [March 1, 2018, 12:06pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/134 "2018-03-01T12:06:27Z")

</div>

and what if things are completely messed up during dev/playing ?  
I never want to open that thing again … so have to make an usb connector to the outside to

---

<div class="post-metadata">

**Author:** ![Charles](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/charles/32/45146_2.png) [@Charles](https://www.thethingsnetwork.org/forum/u/Charles)\
**Post date:** [March 1, 2018, 12:08pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/135 "2018-03-01T12:08:17Z")

</div>

During dev I use USB cable, and just uplug/plug it 😉  
But having a reset btn is also an option when you play a lot 😉

---

<div class="post-metadata">

**Author:** ![Charles](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/charles/32/45146_2.png) [@Charles](https://www.thethingsnetwork.org/forum/u/Charles)\
**Post date:** [March 1, 2018, 1:11pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/136 "2018-03-01T13:11:31Z")

</div>

I’ve just pushed the updated version with the original cayenneLPP sketch (the one with sensors activated) and updated the documentation also.  
Here is the Pull Request [#15](https://github.com/TheThingsNetwork/arduino-node-lib/pull/15)  
@johan, it’s now up to you 😉

---

<div class="post-metadata">

**Author:** ![CurlyWurly](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/curlywurly/32/38668_2.png) [@CurlyWurly](https://www.thethingsnetwork.org/forum/u/CurlyWurly)\
**Post date:** [March 1, 2018, 2:18pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/137 "2018-03-01T14:18:49Z")

</div>

Why didn’t you add a reed switch?  
(use a strong magnet to reset)

---

<div class="post-metadata">

**Author:** ![HanspeterH](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/hanspeterh/32/35697_2.png) [@HanspeterH](https://www.thethingsnetwork.org/forum/u/HanspeterH)\
**Post date:** [March 1, 2018, 2:25pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/138 "2018-03-01T14:25:41Z")

</div>

@Charles I am not sure if the code of the cayenne Ultra LPP has problems.  
channel 3 is always zero, I do not know how long the node has to be kept moving until this is triggered. But more important my ttn node is stuck on the blue light after having worked ok for some events but suddenly no more message from the node and blue light forever. Only disconnecting batteries resets the node…  
Measured battery voltage is 3.7V. Also again strange temperature value of 25.1 degreeC in reality 22.5 outside the ttn box… maybee the ttn node heats up inside…?

---

<div class="post-metadata">

**Author:** ![BoRRoZ](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/borroz/32/44234_2.png) [@BoRRoZ](https://www.thethingsnetwork.org/forum/u/BoRRoZ)\
**Post date:** [March 1, 2018, 2:45pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/139 "2018-03-01T14:45:41Z")

</div>

good idea, but that would void my warranty 😇

---

<div class="post-metadata">

**Author:** ![Charles](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/charles/32/45146_2.png) [@Charles](https://www.thethingsnetwork.org/forum/u/Charles)\
**Post date:** [March 1, 2018, 2:53pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/140 "2018-03-01T14:53:52Z")

</div>

> [@HanspeterH](#):
>
> @Charles I am not sure if the code of the cayenne Ultra LPP has problems.  
> channel 3 is always zero, I do not know how long the node has to be kept moving until this is triggered. But more important my ttn node is stuck on the blue light after having worked ok for some events but suddenly no more message from the node and blue light forever. Only disconnecting batteries resets the node…  
> Measured battery voltage is 3.7V. Also again strange temperature value of 25.1 degreeC in reality 22.5 outside the ttn box… maybee the ttn node heats up inside…?

Fixed blue led is a bug, I’m investigated on it, I saw it also and only way is to reset, I light the LED just before calling send, so I suspect lora module not responding or whaever, but it happened to me when moving the module so with motion detection  
Just reproduced again, moving again just after a send and blocked

---

<div class="post-metadata">

**Author:** ![HanspeterH](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/hanspeterh/32/35697_2.png) [@HanspeterH](https://www.thethingsnetwork.org/forum/u/HanspeterH)\
**Post date:** [March 1, 2018, 3:00pm UTC](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521/141 "2018-03-01T15:00:46Z")

</div>

> [@Charles](#):
>
> Just reproduced again

I can reproduce it by just shaking it several times left right and back until it happens…

[Previous page](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521.md?page=5)

[Next page](https://www.thethingsnetwork.org/forum/t/the-things-node-new-low-power-library-development/12521.md?page=7)
