# Full Arduino Mini LoraWAN below 1uA Sleep Mode

**URL:** <https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059>\
**Category:** End Devices (Nodes)\
**Created:** [June 22, 2017, 3:45pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059 "2017-06-22T15:45:10Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![lex\_ph2lb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/lex_ph2lb/32/44998_2.png) [@lex\_ph2lb](https://www.thethingsnetwork.org/forum/u/lex_ph2lb)\
**Post date:** [July 23, 2017, 12:10pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/41 "2017-07-23T12:10:25Z")

</div>

> [@Charles](#):
>
> For voltage divider (I don’t like them because of consomption and I don’t have place to control voltage measurement with controlled FET to reduce consomption).  
> But, I have a trick for you, you can measure VCC (voltage applied on VCC pin of ATMega) from software, that’s what I do with my ULPNode Library (you may need to adapt code) but it works like a charm, I’m doing 8 samples and Using ADC in Low Power Mode to avoid noise.

Took a minute to wrap up this code in a example and it works out of the box. Many thanks for sharing. 👍

---

<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:** [July 23, 2017, 9:07pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/42 "2017-07-23T21:07:18Z")

</div>

> [@lex\_ph2lb](#):
>
> You allready got great advice from @Casper and @Charles.
> 
> My 2 cents to this topic : as @Caspar sugested using the Mathijs version of LMIC is a good start. Next, remove all the debug stuff you find in the examples. And what you want to debug, just use simple output (for example : “S” for start. “T” for transmit, “ET” for event timeout etc).  
> For example in the LMIC example you see code like this :
> 
> Seriel.PrintLn(“EV\_TXCOMPLETE (includes waiting for RX windows)”);
> 
> Why not change it to :
> 
> Seriel.PrintLn(“ETXC”);

Yeah forgot this one, in default example I changed debug output to use flash memory.

```auto
Serial.PrintLn("EV_TXCOMPLETE (includes waiting for RX windows)");

```

this is not using Flash space but RAM (if not let me know, something changed) so it won’t optimize flash in any way, you need to use F() macro as follow to place string in flash. But @lex_ph2lb advice if correct, to reduce size, reduce print strings lenght (as far as they stored in flash)

```auto
Serial.PrintLn( F("EV_TXCOMPLETE (includes waiting for RX windows)") );

```

@lex_ph2lb thanks for antenna reference, nice graph and interesting

---

<div class="post-metadata">

**Author:** ![lex\_ph2lb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/lex_ph2lb/32/44998_2.png) [@lex\_ph2lb](https://www.thethingsnetwork.org/forum/u/lex_ph2lb)\
**Post date:** [July 24, 2017, 7:44am UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/43 "2017-07-24T07:44:10Z")

</div>

> [@Charles](#):
>
> . But @lex_ph2lb advice if correct, to reduce size, reduce print strings lenght (as far as they stored in flash)

Oeps indeed, forgot to mention the F() macro. 😓

[quote=“Charles, post:42, topic:8059”]  
@lex_ph2lb thanks for antenna reference, nice graph and interesting  
[/quote] You’re welcome. This week I want to setup some field trails to test it against a stock antenna. But for now it looks really good.

---

<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:** [July 24, 2017, 1:51pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/44 "2017-07-24T13:51:21Z")

</div>

Guys

Just to let you know I’ve integrated for testing some tweaked BME280 code in my library. I need to take time to test but, as reference, it fit with TSL2561 code sensor even on Mini without Optiboot Bootloader  
With no debug leaving space  
 ![](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/8/8d9d0d381a4ae342fe46e362b2330cedb875b586.png)

With some debug activated, as you can see, still fit 😉  
 ![](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/8/85d7d483542bfc40bc90a971d94f4e9cf3d8cd4a.png)

---

<div class="post-metadata">

**Author:** ![Gig](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/g/b782af/32.png) [@Gig](https://www.thethingsnetwork.org/forum/u/Gig)\
**Post date:** [July 24, 2017, 3:27pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/45 "2017-07-24T15:27:22Z")

</div>

Remove the bootloader entirely and get a cheap [ISP AVR programmer from eBay](http://www.ebay.com/itm/USBTiny-USBtinyISP-AVR-ISP-programmer-for-Arduino-bootloader-Meag2560-uno-r3-/400368767664?epid=875054691&hash=item5d37d692b0:g:jwMAAOSw-CpYAEeQ), you’ll be able to use the full 32KB of progmem.

---

<div class="post-metadata">

**Author:** ![lex\_ph2lb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/lex_ph2lb/32/44998_2.png) [@lex\_ph2lb](https://www.thethingsnetwork.org/forum/u/lex_ph2lb)\
**Post date:** [July 24, 2017, 3:32pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/46 "2017-07-24T15:32:19Z")

</div>

Time for a new antenne experiment. Now with the SMA chassis part and a single wire mounted in the SMA connector pin.

![](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/a/a7cf22836511f052ac3f5a1b7c6bc1ccff6b5a33.jpg)

![](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/8/8416851d090152dd869e1d1390457ab4d66df88d.jpg)

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

![](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/a/a6f3134f0b87f9a23dd5c408b75b962c9353dab9.png)

![](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/a/ad8df5d8c35ff4301020fd2f5a7db40786893964.png)

![](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/9/964d8523275a065d7194e85b0c5c6a4a76df0236.png)

---

<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:** [July 24, 2017, 3:36pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/47 "2017-07-24T15:36:51Z")

</div>

@Gig  
For sure, but don’t forget that ICSP connector is not present on the board, so you need to wire the ICSP once the Mini is soldered on the board PCB, so, big pain in perspective.

That’s why I’m flashing with Optiboot my Arduino Mini once received with this custom ICSP/FTDI programmer shield and PogoPins.

![](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/b/b6d355fa60f485274133f85426f94f65f01385ba.png)

You can get it [there](https://PCBs.io/share/rm2v2) on [PCBs.io](http://PCBs.io), tested and working 😉  
github repo of the [adapter](https://github.com/hallard/Pro-Mini-ICSP-FTDI) with build files, schematics and bootloaders

---

<div class="post-metadata">

**Author:** ![ursm](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ursm/32/46475_2.png) [@ursm](https://www.thethingsnetwork.org/forum/u/ursm)\
**Post date:** [July 24, 2017, 4:29pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/48 "2017-07-24T16:29:12Z")

</div>

> [@Charles](#):
>
> custom ICSP/FTDI programmer shield and PogoPins.

nice work.  
could you please tell us what PogoPins you used (link?) and it would be nice seeing a picture of an _assembled board_  
thanks

---

<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:** [July 24, 2017, 4:47pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/49 "2017-07-24T16:47:22Z")

</div>

I’m using Pogo Pin P75-E2 or P75-LM2  
Plenty of them on ebay 😉

> **[100pcs P75-LM2 1.02mm Length 16.5mm 100g Spring Test Probe Pogo Pin 6 Blade Tip...](https://www.ebay.com/itm/151785406425)**
>
> Note: The color of the item may vary slightly due to photography and your own computer
> Feature:
> The spring Test Probe Receptacle is used for insert test probe, so, it let you easy to replace the test probe when it has problem after the life time...

> **[100pcs P75-E2 (1.3mm Conical Head) Spring Test Probe Pogo Pin 1.0mm Thimble...](https://www.ebay.com/itm/122300245981)**
>
> 100pcs P75-E2 (1.3mm Conical Head) Spring Test Probe Pogo Pin 1.0mm Thimble | Business & Industrial, Test, Measurement & Inspection, Leads & Probes | eBay!

I’ll take a picture, I’m at the office right now 😉

---

<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:** [July 25, 2017, 8:26am UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/50 "2017-07-25T08:26:15Z")

</div>

> [@ursm](#):
>
> nice work.  
> could you please tell us what PogoPins you used (link?) and it would be nice seeing a picture of an assembled board  
> thanks

@ursm  
Updated the [github](https://github.com/hallard/Pro-Mini-ICSP-FTDI) repo for the ICSP programmer with some pictures, but looks like this

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

In the meantime, I’ve just received V1.1 of MiniLora PCB, classic and groove, need some testing  
 ![](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/8/8dcf333f1f3a1b11e358011799c8928daa420242.jpg)

---

<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:** [July 25, 2017, 9:15am UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/51 "2017-07-25T09:15:13Z")

</div>

Just to let you know I’ve just released the Mini-LoRa files (Schematics, boards, pictures,…) on github.  
Check this out [here](https://github.com/hallard/Mini-LoRa)  
If you like, don’t hesitate to star 😀

---

<div class="post-metadata">

**Author:** ![ursm](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ursm/32/46475_2.png) [@ursm](https://www.thethingsnetwork.org/forum/u/ursm)\
**Post date:** [July 25, 2017, 7:36pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/52 "2017-07-25T19:36:03Z")

</div>

with matthijskooijman/arduino-lmic, the BME280 ([Glenn Tyler](https://www.github.com/finitespace/BME280)) and Voltage measurement published above (thanks @Charles) and low power sleep I’m at 29126 bytes (94%).  
It’s sad not able to add the Multichannel Gas Sensor ([MiCS-6814](http://wiki.seeed.cc/Grove-Multichannel_Gas_Sensor/)) which library needs at least 8kB  
 ![](https://www.thethingsnetwork.org/forum/uploads/default/original/2X/8/8e79f70bf0d49e88a7fbe1888572eae9dd13b914.jpg)  
Next will be running it on battery (clips just arrived) and measuring current.

---

<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:** [July 26, 2017, 1:13pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/53 "2017-07-26T13:13:28Z")

</div>

For information, adding BME280 code to my lib increased 700 bytes (including sending BME280 payload to TTN). Of course I already got I2C sharing reading/writing register functions for other I2C devices, so I’m cheating a little.

without BME280

```auto
Sketch uses 29822 bytes (97%) of program storage space. Maximum is 30720 bytes.
Global variables use 1339 bytes (65%) of dynamic memory, leaving 709 bytes for local variables. Maximum is 2048 bytes.

```

with BME280

```auto
Sketch uses 30522 bytes (99%) of program storage space. Maximum is 30720 bytes.
Global variables use 1339 bytes (65%) of dynamic memory, leaving 709 bytes for local variables. Maximum is 2048 bytes.

```

8Kb for a sensor library is just amazing, just took a look onto it, using float calculation and math pow function are consuming. Library fitted with also lot of print, I’m pretty sure you can tweak it by a 2 factor, I could try but does not have this sensor to test  
A good sensor for Mini Lora grove version 😉

---

<div class="post-metadata">

**Author:** ![ursm](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ursm/32/46475_2.png) [@ursm](https://www.thethingsnetwork.org/forum/u/ursm)\
**Post date:** [July 26, 2017, 1:33pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/54 "2017-07-26T13:33:55Z")

</div>

8kB is with stripping all Serial.prints ☹  
squeezing the multisensor gas library is something for experts - not for me

---

<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:** [July 26, 2017, 4:06pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/55 "2017-07-26T16:06:10Z")

</div>

Your device sensor (very interesting) has an Arduino (ATMega168) on board with a firmware (updatable).  
When I compile the firmware, 32% of sketch size

```auto
Sketch uses 4612 bytes (32%) of program storage space. Maximum is 14336 bytes.
Global variables use 439 bytes (42%) of dynamic memory, leaving 585 bytes for local variables. Maximum is 1024 bytes.

```

- This mean a huge part of the library code should have been done on the sensor itself which makes sense from my point of view 😉
- Take care that firmware on the board is far from Low Power, no sleep mode used when sensor is doing nothing

---

<div class="post-metadata">

**Author:** ![ursm](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ursm/32/46475_2.png) [@ursm](https://www.thethingsnetwork.org/forum/u/ursm)\
**Post date:** [July 26, 2017, 4:17pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/56 "2017-07-26T16:17:57Z")

</div>

> [@Charles](#):
>
> Take care that firmware on the board is far from Low Power, no sleep mode used when sensor is doing nothing

it consumes 48mA forever 😉  
the command powerOff does not reduce current.

//-------------------------------------------------------------------------------------  
// get some data from the sensor  
\*include “Wire.h”  
\*include “MutichannelGasSensor.h”  
\*define SENSOR\_ADDR 0X04 // default to 0x04

void setup()  
{  
Serial.begin(115200);  
gas.begin(SENSOR\_ADDR);  
gas.powerOn();  
}

void loop()  
{  
delay(5000);  
float c;  
c = gas.measure\_NH3();  
Serial.print("NH3 is “);  
if(c\>=0) Serial.print(c);  
c = gas.measure\_CO();  
Serial.print(” CO is “);  
if(c\>=0) Serial.print(c);  
c = gas.measure\_NO2();  
Serial.print(” NO2 is ");  
if(c\>=0) Serial.println(c);  
}  
//-------------------------------------------------------------------------------  
Sketch uses 8246 bytes (26%) of program storage space. Maximum is 30720 bytes. ☹

---

<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:** [July 26, 2017, 4:31pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/57 "2017-07-26T16:31:58Z")

</div>

@ursm  
this size if for total sketch not only the library, since it contains float management and arduino core, it’s not only library.

Look this basic sketch

```auto
void setup() {    
  Serial.begin(115200);
}
void loop() {
  static float f = 1.0;
  Serial.print(f);
  delay(1000);
  f += 0.1;
}

```

and compilation

```auto
Sketch uses 3148 bytes (10%) of program storage space. Maximum is 30720 bytes.
Global variables use 200 bytes (9%) of dynamic memory, leaving 1848 bytes for local variables. Maximum is 2048 bytes.

```

3148 bytes used by Arduino core, so may be lib is more like 4K than 8K, but still too much for an I2C device

---

<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:** [July 26, 2017, 4:37pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/58 "2017-07-26T16:37:18Z")

</div>

And for fun, adding I2C library (wire), 4642 bytes, so definitively Gas lib should fit with some tweaking

```auto
#include <Wire.h>

void setup() {    
  Serial.begin(115200);
  Wire.begin();
  Wire.beginTransmission(0xff); 
  Wire.write(0x00);    
  Wire.write(0x01);           
  Wire.endTransmission(); 
}

void loop() {
  static float f = 1.0;

  Serial.print(f);
  delay(1000);
  f += 0.1;
}

```

```auto
Sketch uses 4642 bytes (15%) of program storage space. Maximum is 30720 bytes.
Global variables use 378 bytes (18%) of dynamic memory, leaving 1670 bytes for local variables. Maximum is 2048 bytes.

```

---

<div class="post-metadata">

**Author:** ![tkerby](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/tkerby/32/36978_2.png) [@tkerby](https://www.thethingsnetwork.org/forum/u/tkerby)\
**Post date:** [July 31, 2017, 11:57pm UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/59 "2017-07-31T23:57:28Z")

</div>

Do you have some examples of how you are entering and resuming from sleep in the LMIC library between measurements?

Doesn’t necessarily need to be with your cut down code but I’d be interested to see an example even with the base library. Thanks for all the great boards!

---

<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:** [August 1, 2017, 12:57am UTC](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059/60 "2017-08-01T00:57:35Z")

</div>

@tkerby

All is done in loop, with LMIC events callback and a global flag (timetosleep) to indicate the sleep mode needed.

I’m sleeping x time of watchdog 8s in loop, once max time is triggered, I set timetosleep to false and I send LMIC data and refreshing LMIC in loop  
on EV\_TXCOMPLETE event I set timetosleep to true, then, loop() go back sleeping until x time of 8S watchdog occurs.

Of course setup need to start lmic and join, on joined I fire a LMIC timer to send first packed 10ms later. then on packet sent (EV\_TXCOMPLETE ) loop will go to sleep

[Previous page](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059.md?page=2)

[Next page](https://www.thethingsnetwork.org/forum/t/full-arduino-mini-lorawan-below-1ua-sleep-mode/8059.md?page=4)
