Go Down

Topic: Can you Edit this Library? (Read 353 times) previous topic - next topic

Fredric58

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.

UKHeliBob

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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

spycatcher2k

Or sleep for 8 seconds 4 times, then 1 second.
-=-
http://www.uk-pcb.co.uk - UK Based PCB Fab Company
I will code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

srnet

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.
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

pert

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.

Fredric58

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.

















srnet

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.
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

Fredric58

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.

https://www.youtube.com/watch?v=npc3uzEVvc0     

Fredric58

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.


spycatcher2k

Thats expected as the longest sleep time is 8 seconds.
-=-
http://www.uk-pcb.co.uk - UK Based PCB Fab Company
I will code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

aarg

#10
Dec 17, 2017, 11:05 pm Last Edit: Dec 17, 2017, 11:07 pm by aarg
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?
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

Jiggy-Ninja

#11
Dec 18, 2017, 03:22 am Last Edit: Dec 18, 2017, 03:23 am by Jiggy-Ninja
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?

Quote
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.
Hackaday: https://hackaday.io/MarkRD
Advanced C++ Techniques: https://forum.arduino.cc/index.php?topic=493075.0

srnet

#12
Dec 18, 2017, 09:17 am Last Edit: Dec 18, 2017, 09:23 am by srnet
The code I use is to give a non-standard sleep period is to add this function to a program;

Code: [Select]

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.
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

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

srnet

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.
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

Go Up