genotix / low_power_ATMEGA328P

My lowest power sketch for the ATMEGA328P / Arduino Nano v3 ; about 200 nA @ Deep sleep
0 stars 1 forks source link

Loop code in start or end? #1

Open fyrus7 opened 3 years ago

fyrus7 commented 3 years ago

Where to place the loop code in my sketch? Is it just below loop start or the end of my sketch?

genotix commented 3 years ago

If you use the sketch that doesn’t reach the loop you will need to think of the execution of the setup() as your loop and use the EEPROM or an external memory to store a limited amount of variable data.

Met vriendelijke groet / Kind regards,

Eric Oud Ammerveld Phone: +31 10 495 19 55 Mobile: +31 6 55 86 25 44 E-mail: @.***

Op 11 sep. 2021 om 19:40 heeft fyrus7 @.***> het volgende geschreven:

 Where to place the loop code in my sketch? Is it just below loop start or the end of my sketch?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

[ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/genotix/low_power_ATMEGA328P/issues/1", "url": "https://github.com/genotix/low_power_ATMEGA328P/issues/1", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

fyrus7 commented 3 years ago

It has all the setup() & loop() ie a complete sketch for a project

genotix commented 3 years ago

Sure, but the loop will never be reached so you will need to move your code to the setup and understand that it will only run the setup -once-, on waking.

You can add a while(1) in the setup but the device will only go into low power when it is in put in an interruptable deep sleep.

Met vriendelijke groet / Kind regards,

Eric Oud Ammerveld Phone: +31 10 495 19 55 Mobile: +31 6 55 86 25 44 E-mail: @.***

Op 12 sep. 2021 om 04:03 heeft fyrus7 @.***> het volgende geschreven:

 It has all the setup() & loop() ie a complete sketch for a project

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

[ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/genotix/low_power_ATMEGA328P/issues/1#issuecomment-917533765", "url": "https://github.com/genotix/low_power_ATMEGA328P/issues/1#issuecomment-917533765", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

fyrus7 commented 3 years ago

is it something like this?

include "LowPower.h"

include <avr/sleep.h>

include <avr/power.h>

define debugmode false

define testmode false // You can use the plotter in test mode

MY HEADER CODE HERE

include "tools.h"

include "cpu.h"

void setup() {

disable_wdt(); disable_adc();

if ( debugmode ) { Serial.println(F("Booting...")); } else { disable_uart(); // Disable internal serial logic }

led_onoff(500,1); led_onoff(100,2);

}

MY SETUP CODE HERE

void loop() {

inputs_lowpower();

if ( testmode ) { cpu_sleep_dummy(); unset_interrupt_dummy(); } else { sleepNow(); }

MY LOOP CODE HERE

}

genotix commented 3 years ago

It’s best to start and explain what you want to achieve and provide me with URL’s instead of me going through a Git repo.

After 3 years this code has also sunk down on me and I may even do things different now.

Met vriendelijke groet / Kind regards,

Eric Oud Ammerveld Phone: +31 10 495 19 55 Mobile: +31 6 55 86 25 44 E-mail: @.***

Op 12 sep. 2021 om 06:41 heeft fyrus7 @.***> het volgende geschreven:

 Take a look on my repo, thats where i want to implement the code

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

[ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/genotix/low_power_ATMEGA328P/issues/1#issuecomment-917550904", "url": "https://github.com/genotix/low_power_ATMEGA328P/issues/1#issuecomment-917550904", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

fyrus7 commented 3 years ago

My sketch is on my git, only one project