Full Arduino Mini LoraWAN below 1uA Sleep Mode

Working on that. Need to do some measurements to get it right but for now it’s close to where I want it.
When I find the optimum I will post it here.

how did you squeeze the code?
mine needs: Sketch uses 30676 bytes (99%) of program storage space. Maximum is 30720 bytes. only as LoRa node.
my BME280 routine (could be shrinked by some text) needs: Sketch uses 11244 byte.
so that does not fit into the proMini
used libs for LoRa: lmic.h , hal/hal.h , SPI.h
used libs for BME: Adafruit_Sensor.h , Adafruit_BME280.h

probably you could share your code?
thanks

2 Likes

@ursm
First of all I change the default bootloader to optiboot one, this save me 1.5K of code allowing sketch of 32256 size. I also programmed it with 250K upload which is much faster and reliable at 8MHz. See my post about this
Then I avoid importing any library, I just grab the minimal code from Lib that I integrate into my own lib after optimisation.
Also remove some debug print, and set LMIC to no debug with

#define LMIC_DEBUG_LEVEL 0

as example with SI7021 + TSL2561 sensors (both in the same sketch sending to TTN) with no debug I’ve got

Sketch uses 26376 bytes (81%) of program storage space. Maximum is 32256 bytes.
Global variables use 1297 bytes (63%) of dynamic memory, leaving 751 bytes for local variables. Maximum is 2048 bytes.

Same with my debug activated

Sketch uses 30450 bytes (94%) of program storage space. Maximum is 32256 bytes.
Global variables use 1303 bytes (63%) of dynamic memory, leaving 745 bytes for local variables. Maximum is 2048 bytes.

Amazing with CCS811 and my debug activated with also SI7021 and TSL2561

Sketch uses 30976 bytes (96%) of program storage space. Maximum is 32256 bytes.
Global variables use 1303 bytes (63%) of dynamic memory, leaving 745 bytes for local variables. Maximum is 2048 bytes.

I’m sorry, for now the code is not open source, it’s a compilation of 2 years (not full time) of research and optimisation and used for private customers. I intend to add BME280 on my lib, I’m pretty sure I can add it with some opt. I think I’ll use this one https://github.com/finitespace/BME280 as starting point.

I think I’ll be able to share the I2C stuff of the library. Let me think about that.

1 Like

mine needs: Sketch uses 30676 bytes (99%) of program storage space. Maximum is 30720 bytes. only as LoRa node.

Thats too much, i would guess you use the wrong version of the lmic here. Delete the one you use and go grab the one from here: https://github.com/matthijskooijman/arduino-lmic

lmic.h, hal.h, SPI.h and LowPower.h + working code for OTAA (without the tricks from Charles) is 20358 Bytes for me. If i would use special bootloader, optimize the lmic (debug level), i could go even lower.

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”);

That saves quite a few bytes of code. Or even better if you’re interested in the OnEvent event just print it and dont make it human readable with debug output in every case from the switch.

Also check you’re libraries, remove anything that isn’t needed or write you’re own dedicated libraries by stripping down a standard library like @Charles pointed out For example when you only use the I2C to communicate with the BME280, why have a library with a large chuck of SPI code in it. .

@Charles : Today I rebuild the antenna and made some measurements on it while constructing so the influance of the PCB is used in the building process.
I left 2 cm of the coax shield on the connector side and used heatschrink to make it more stiff.

Below you find the graphs SWR, Returnloss and smit chart.

The return-loss is very acceptable.

2 Likes

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

1 Like

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

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)

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

@lex_ph2lb thanks for antenna reference, nice graph and interesting

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

[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.

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

With some debug activated, as you can see, still fit :wink:

3 Likes

Remove the bootloader entirely and get a cheap ISP AVR programmer from eBay, you’ll be able to use the full 32KB of progmem.

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

1 Like

@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.

You can get it there on PCBs.io, tested and working :wink:
github repo of the adapter with build files, schematics and bootloaders

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

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

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

3 Likes

@ursm
Updated the github repo for the ICSP programmer with some pictures, but looks like this

In the meantime, I’ve just received V1.1 of MiniLora PCB, classic and groove, need some testing

4 Likes

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

5 Likes

with matthijskooijman/arduino-lmic, the BME280 (Glenn Tyler) 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) which library needs at least 8kB

Next will be running it on battery (clips just arrived) and measuring current.

5 Likes

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

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

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 :wink:

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