Notifications
Clear all

Implementing a safe unlock application

60 Posts
6 Users
6 Likes
2,524 Views
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  
  • Yes, but this doc isn’t about the Atmel328 family, it is for the samd21 boards….

😕 😕 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6662
 

@papymouzot Sorry, forgot. Use the IDE board manager to select a board, then use the library manager to search for low power libraries that are compatible with the board. If the developers were lazy and didn't specify to the lib mgr you will get false hits but a quick look at the docs will sort that out. I am also interested in ultra low power, but I am not locked into any specific type of board, whatever offers the lowest power consumption that also has the other features I need will do. Good luck.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  

Hello,

I have spent more time on this and I still have issues… My code works fine without sleep mode and still uses 10mA on a 3.3v lifepo4 cell which is far too much. When I try to implement deep sleep mode I am getting very strange behavior. Keys are missed and I could not find a pattern which can help me debug the code… 

 

i have also tried some code I found on gammon.au and it doesn’t work either… 

😥😥😥

 

I ordered a few other boards to give them a try. Pro mini 5v 16 MHz, 3.3v 8 MHz, esp32, esp8266 and samd21.. they all cost next to nothing and I will find a use for them anyway. At least for these « new » boards some new power saving libraries exist !! 

I will keep you posted of course. 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6662
 

@papymouzot Let's try to come at the problem from a different direction. What is the capacity of your battery in maH. For example I have a chewing gum sized LiPo battery that has 600maH. If you wanted that battery to last 2 years then the constant draw would have to be about 68.5ua per hour. In hibernation mode that battery will last 27 years.

HOWEVER this may not be a usable mode as data is not retained.

The next best is Deep Sleep and it uses 4x the power so will only last about 6.75 yrs. Is that good enough? We then need to account for battery aging and without looking it up let's say the battery is fully depleted after 3 yrs, is that good enough?

I have a piece of photography gear that has NO on/off switch, the coin battery (CR2032) is changed every 2 years if needed or not.

 

You might want to start with the code from this source, many of us here used them for our basic education re MCP's. Try This

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1608
 

Hi @papymouzot 

Re: When I try to implement deep sleep mode I am getting very strange behavior.

The following are only suggestions to consider. This can be a tricky problem to diagnose with full access to test gear and a full understanding of the system in front of you, none of which are available to me. Hence these suggestions, though well meaning, are based solely on the quoted words above, and could be considering completely the wrong problem.

I haven't looked at libraries or processor or board you are using, but in general, when processors are put into a sleep/hiberanate mode, it takes an appreciable time for them to wake up. Careful study of the data sheet should help. Care has to be taken to ensure that all of the critical actions and timings of the 'wake up ' process are met.

Note, some processors have two or more sleep/hibernate options, with a trade that the deeper sleep options use less power, but switch off more functionality, so take longer to wake up, and may be more disruptive. If there are any options, start with the 'lightest sleep' one, to see if the 'strange behaviour' is reduced or eliminated.

In addition, you usually have to be careful to understand the effect of putting the processor into that sleep/hibernate mode. Remember, it saves power by disconnecting power from large parts of the processor, often including the GPIO pins, clocks and so on.

Thus when wake up occurs, in some ways it is like booting up the processor, except it will not go through the initialisation code, so that if there are in steps in the boot up code that are needed to setup the system, and those parts have been powered down by the sleep/hibernate command, then they may not be in the expected states. Clearly, this means a detailed analysis of both the processor and the external circuitry, in particular looking for latches, registers and so on, which may not be in the required state.

.........

And if you can't resolve the problem, maybe consider changing the rules of the game. The processor is only needed for the short time whilst a person is operating the keypad and activating the mechanical release mechanism, if they enter the right code. So (as I suggested previously), have a small 'supervisory power' circuit, which is activated by a particular button press by the user, which boots and powers up the processor for just a short period, say about 1 minute, maybe less. There is no reason for the circuit to draw power when no one is trying to enter the code.

...........

Good luck with your project ... best wishes, Dave


   
ReplyQuote
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  

   
ReplyQuote
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  

   
ReplyQuote
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  
Test jig 1

Here is my tiny test jig with a small test keypad, a 5V buzzer, led and relay.

On the top right the Battery I was thinking about using. 3.2-3.3V


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6662
 

@papymouzot I don't see where you tried the randomnerdscode. Give it a try, gammon is tricky.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  

Hi Ron,

I could not find deep sleep tutorials for Mega328P based Arduino pcb's on this web site.

I however have seen on their web site some tutorials and code which I am eager to try for the ESP32 and ESP8266 based boards about sleeping modes. I have already ordered a couple of these boards to give it a try. It takes time to receive them though... 😜 In the meantime I try to slowly improve my programming skills/knowledge by browsing through the examples they give, I quite like random nerd tutorials  !!!! Nice and clear..

edit: I would have loved however to find what my mistakes are on the 328P Arduino board, I find it strange to be "obliged" to use a wifi board when I don't need a wifi module at all, I wished to have a simple unit which would do the job with very, very low power consumption.

Charles

 

This post was modified 2 years ago by Papymouzot

   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6662
 

@papymouzot If your criteria is no wifi and low power, why not switch to the RP2040 either as a Raspberry PICO or any of the arduino variants however most of them will include WiFi.

Why are you hung up on the Mega, that is a board that is used when more pins than an UNO has are needed.

To get really low power you generally need to code at a much lower level then normal.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6662
 

@papymouzot I am concerned you may not have seen an earlier reply of mine so I am linking it here https://forum.dronebotworkshop.com/postid/32489/

NOTE there is a LINK at the end inside the text 'Try This' I suspect you didn't notice that either. Here is that link in long form https://randomnerdtutorials.com/esp32-deep-sleep-arduino-ide-wake-up-sources/      The ESP32 is a better board to use than the arduino boards for this kind of application for a number of reasons.

I would compare the boards the nerds documented with the newest esp32-s3 and the Raspberry PICO and other RP2040 boards to see which board matches or exceeds the calculations done for a given battery pack.

Good luck.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  

Thank you Ron,  I will definitely look at the links you just mentioned. I probably missed them first. Thanks a lot for your help, ideas and advice.

 

I am not stuck with the Mega328P, I just happened to have bumped in the Arduino Uno first some time ago when I was wondering how I could repair/replace the electronics to open/close my safe as it would be a huge amount of work doubled with a big expense to replace it.

I thought that for the limited requirements I had, the 328P would do the job just fine. 

Indeed, on the paper the Arduino Nano or Pro Micro seemed perfect for the job. Enough Inputs/Outputs,  simple to use, Development environment easy to use, very affordable….  Too much mA to use it without deep sleep mode however…

I feel that I know far too little about these products for the moment to build a rock solid application based on this cpu. I am still at the « Hello World ! » stage !!!

I don’t mind trying other products to do the job quickly but I am not knowledgeable at all about all the ones you mentioned, and I already feel that I am going in too many directions at the same time 😜😜😜  The ESP32 already seem to be an overkill for what I wish to do, ie:I dont need wifi or Bluetooth for my little « safe » lock/unlock app. I will give the ESP a try and use it if it does the job fine. I am however a bit stubborn and may keep trying to make my app work on the 328P, just for the sake of it. 

charles

 

 


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 

@papymouzot - Although mastering sleep modes as a learning experience is/would be on my lists to do, I wonder if it is the best solution to your project.  It is my understanding, you'll have to have something to wake it...

  1. a pin is triggered by an external action - button press
  2. a periodic waking, seeing if any action is required, going back to sleep. 

The first requires an extra button press (which you said you didn't want).  The second requires battery usage and if not awake when you press a button, it won't respond.  So you have to wake often or be patient to happen to hit one of its awake periods.

Or... have you figured a way for any button press on your keypad to wake the board?  If this is the case, will it be able to both wake the board AND know what button was pressed to be used as part of the combination sequence?  Usually the MPU will need to be away to decode and know which button was pressed.

The point being... even once you get a board that you can program sleep modes, I don't think that will be the end of your problems, you'll need to figure out. 

And remember... a major consumer of electricity is the voltage regulator powering your MPU even while it is asleep.  I know there are serious differences in power usage of various regulators.  Some are only 80% efficient and will be draining your battery more than the MPU.  I don't know which are the most efficient.  A hardware guy will have to chime in for that.  

Which brings me to a question...

If you end up having to have a button press to wake it (#1 above) what is your aversion to having a momentary button press to simply power-on the MPU as I recommended earlier?  Is it simply aesthetics / ergonomics to have that extra button press or is their a practical or security reason, that I may not understand?

Having one extra momentary contact power button next to your keypad doesn't sound like a faux pas considering it will extend the life of even a single battery to YEARS and you don't mess with any complex/buggy sleep mode handling, voltage regulator efficiencies.  And your software code uses only 2 lines of code to power on and go directly to your combination sequence code that I assume you already have working.

Using even your Atmega and one extra momentary switch / relay, this becomes a two hour project, instead of a (now) 2 week project and really... I don't think you've even scratched the surface of how long it will take you to master a sleep mode design without that little ugly extra button.

VBR,

Inq

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 
Posted by: @zander

Why are you hung up on the Mega, that is a board that is used when more pins than an UNO has are needed.

He's not using "THE" Arduino Mega 2560... He's using an ATMega328... that is the most basic chip used in the Uno, Mini, Nano... etc.  @papymouzot may not know that THE Mega means something completely different to us.  See his O.P. - It says he's using a Nano.

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Ron reacted
ReplyQuote
Page 3 / 4