Can you Edit this Library?

I am relatively new to arduino. I found a useful library and would like to have 1 thing added. It is a low power library for the arduino. however it only has definitions of sleep time up to 8 seconds. I have read that it is possible but I am not up to speed to do this myself. I can open it to read it and see where it is but haven't a way to save it in the correct format. I would like someone to add a definition of SLEEP_25S. (25 seconds) I know you can download apps to do this but I am using someone else's computer and have been asked not to add anything else.

thanks if you can.

Low_Power-1.4.0.zip (9.11 KB)

Open the .h and .cpp files with an editor such as Notepad++ (not the IDE), make the changes and save them with the same names. Making a copy of them first would be sensible.

(deleted)

Or just write a simple function in your program that calls sleep for 1 second 25 times.

You then have a general purpose routine that you can use to sleep for however many seconds you like such as;

sleepsecs(25);

sleepsecs(120);

etc.

I don't see any need to alter the library at all. Best not to make your programs dependent on specific changes to libraries if you can avoid it.

It actually is possible to edit libraries using the Arduino IDE. You just need to add two or three files to the root of the library folder:

  • An .ino file with the same name as the library. This is just a dummy file that tricks the Arduino IDE into thinking the library is a sketch so it will open the library. I like to use it to store a "to-do" list.
  • A file named .development. This is required because without it the Arduino IDE does not let you save to a library folder. Note that this feature was added in one of the 1.6.x IDE versions so if you're using an old IDE version you might need to move the library out of the libraries folder to edit it.
  • A library.properties file if the library does not already have one. The file format is specified here. You can just copy one from another library.

Thanks guys, Think I will start with UKHeliBob's suggestion as it seems the simplest.

as for writing a simple code and about modifying the library. All that I have to do is add a line SLEEP25S, done. To me the library is hard enough to work with as is, and writing additional stuff in the sketch itself would be confusing. All I need is there, except the 25 second part, and all that is required in the loop of the sketch is

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);//only I need 25s

and it runs at about .07mA when sleeping saving a huge amount of battery life.

I'm no where near the point of writing code to be flipping bits to turn off ADC and BOD in the chip. This works fine and it's simple.

I discovered last night that the uno won't power the adafruit sound board. so I am planning on using the battery directly to the sound board and use a signal from the uno through a resisistor to turn on a transistor as a switch to power it up.

I discovered every time I turn on the board the speakers go "CLICK CLICK" didn't notice it when I just ran the sound board off the 5v of the arduino while testing the sketch. but the clicks are unacceptable.

is there a way I can buffer (for lack of a better word) or block/suppress the click till the board boots up? If I recall Adafruit says it takes about 10 ms.

It would be helpful to other forum users if you provided the details of the changes you made, in case anyone else wants to do something similar.

I'll be happy to as I think others might find it pretty useful too if you are using batteries. you can't take full advantage of power down as you can using a RTC because it's using the WDT but it's a huge improvement from 28mA to .07mA 50 seconds out of every minute that it isn't doing anything. the actual library was in the first post if you want to give it a look. If I can edit the .h and .cpp file as ULHeliBob suggested I'll post them as well.

any ideas of how to get rid of the speaker pop when the board gets powered up?

this is one of the best youtube tutorials on how to make a bare ATMegea 328P-PU with 5 components in 5 minutes and where I discovered to sleep mode library. it's worth checking out if you make battery powered stuff.

ok, saved the originals. opened the .h and .cpp in word pad (not++ don't know what the ++ is for)

modified/ changed the 8 second slot to 25 the first time and 24 the second time. on both files, all the other increments were in 2's. so I tried 24.

opened sketch and verified. it said "8s was not declared in this scope"

changed it to 24s, 24s did not turn orange like the original 8 was but did not return an error, it also did not wait 24 seconds when I up loaded it, it kept the original 8 seconds.

(deleted)

You only changed the name of a variable. Do you really expect that to work? Are there no other sleep libraries that you could use?

Fredric58:
as for writing a simple code and about modifying the library. All that I have to do is add a line SLEEP25S, done.

Why do you think it is that simple?

I'm no where near the point of writing code to be flipping bits to turn off ADC and BOD in the chip. This works fine and it's simple.

Then you are not yet at the level of being able to modify a power reduction library. Power reduction is done using hardware features of the chip, and the hardware has very specific limitations on what it can do. In particular, it's not just that it can sleep for a maximum of 8 seconds, but that there are only a few specific lengths of time that can be chosen. 8 seconds is that largest of those lengths, but that doesn't mean you can choose any amount of time below 8 seconds. There's no 7 second sleep time either. The reason for these limitations is that a more feature-filled set of hardware would require more complicated circuitry, and therefore more power.

This, and many other features of the chip, are explained in extensive detail in the ATmega328P datasheet. To understand the LowPower library you will want to pay particular attention to Section 14 Power Management and Sleep Modes, and also 15.8 Watchdog Timer.

The code I use is to give a non-standard sleep period is to add this function to a program;

void sleepSecs(unsigned int NumberSleeps)
{
  unsigned int i;

  for (i = 1; i <= NumberSleeps; i++)
  {
    LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);    //sleep 1 second
  }

}

Which you can then use as you like;

sleepsecs(1);
sleepsecs(5);
sleepsecs(25);

If its for your own use, then maybe possibly its worth the effort to modify the library for a particular time period, but if you want to share your program with others then you would need to dicument and describe the custom changes to the low power library.

As has been pointed out you cannot directly sleep for 25 seconds, so wherever you do it you will need to do multiple calls to LowPower.powerDown() or a similar function in the library.

thanks, I woke up this morning at 4:00am and realized the WDT only has an 8 sec max length time. I already knew that but it just didn't register for some reason. I did however learn how to open and modify to some extent a library then return it to its original state and WHY some changes worked and others didn't, so something learned. thanks to UKHeliBob. yes, I am new to arduino and it is quite challenging but not impossible. yes I can use another library and have one as well. it is for use with a RTC. I can use it to accomplish what the WDT was doing (sleeping) for 8 seconds or longer if I want. I can also use the library to turn anything on or off at a given time. Both are relatively simple tasks by themselves. Blending the 2 is my challenge as I want the 328 to power down for 16 hours, then run a timed loop for 8 hours then power down again. I know this stuff is complicated. But I have accomplish all parts of what I want to accomplish separately. In one form or several. so it's back to the drawing board.

srnet, i'll check that out, Thanks

Fredric58:
thanks, I woke up this morning at 4:00am and realized the WDT only has an 8 sec max length time. I already knew that but it just didn't register for some reason. I did however learn how to open and modify to some extent a library then return it to its original state and WHY some changes worked and others didn't, so something learned. thanks to UKHeliBob. yes, I am new to arduino and it is quite challenging but not impossible. yes I can use another library and have one as well. it is for use with a RTC. I can use it to accomplish what the WDT was doing (sleeping) for 8 seconds or longer if I want. I can also use the library to turn anything on or off at a given time. Both are relatively simple tasks by themselves. Blending the 2 is my challenge as I want the 328 to power down for 16 hours, then run a timed loop for 8 hours then power down again. I know this stuff is complicated. But I have accomplish all parts of what I want to accomplish separately. In one form or several. so it's back to the drawing board.

srnet, i'll check that out, Thanks

The WDT is not a lot of use if you want accurate delays, you need to use a RTC for that.

yes sir you are correct. the WDT allowed me to simulate operation to test the other components wherein I made several discoveries. some good some bad.

as stated I have a RTC and can use it to do as many seconds as I like. It is DS3231 and it's said to be a fairly reliable component. The results of the power down mode using it for the interrupt are incredible. I had planned to put the chip into a serious power down mode with the RTC and then just use the WDT for the loop when it was awake, till I remembered it's only 8 seconds max unless you loop it and is said to drift quite a bit. which in this instance isn't that big of a deal.

so now I have learned to put the chip to sleep with the RTC interrupt and with a match HH & mm & ss interrupt, wake it up, go blinky blinky till whenever then back to sleep.

I can also do it with seconds, like blinky blinky for 5 seconds go to sleep for 30 seconds. over and over and over.
what I am trying to learn is. go blinky blinky for 5 seconds go to sleep for 30 (repeat) but only between 7pm and 4am. because it is going to be asleep between 4am and 7pm.

would you say I was on the right track if my idea was to wake it up at 7 with an hh mm ss interrupt, once awake I'm thinking I could use an "elapsed time" reset seconds to 0, count to 25, blink blink back to sleep mode (repeat) check hh mm ss along the way- interrupt, sleep the rest of the day?

which leads to a question looking ahead. since there are delays in the loop and nothing can happen during a delay what would happen if the match hh mm ss occurred during the delay? would it be missed? and is that where or why to use mills instead of delay comes in??

thank you for all assistance.

Fredric58:
which leads to a question looking ahead. since there are delays in the loop and nothing can happen during a delay what would happen if the match hh mm ss occurred during the delay? would it be missed? and is that where or why to use mills instead of delay comes in??

That is where converting to epoch time and using > or >= instead of = to detect a match, could be an advantage.