Project: heated cabinet for charging batteries

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#51 Post by chromo23 » 12 Sep 2022, 10:50

Here are some pictures of my project... hardwarewise it´s finished.
batt1.JPG
batt1.JPG (197.65 KiB) Viewed 428 times
bat2.JPG
bat2.JPG (164.72 KiB) Viewed 428 times
batt3.JPG
batt3.JPG (116.12 KiB) Viewed 428 times
batt4.JPG
batt4.JPG (106.46 KiB) Viewed 428 times
batt5.JPG
batt5.JPG (91.26 KiB) Viewed 428 times
battgif.gif
battgif.gif (1.26 MiB) Viewed 428 times
Last edited by chromo23 on 12 Sep 2022, 18:00, edited 1 time in total.

TD-er
Core team member
Posts: 6481
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Project: heated cabinet for charging batteries

#52 Post by TD-er » 12 Sep 2022, 11:02

Looks cool!
Is there also a smoke detector in it?
I always find it a bit scary to have something like a heater somewhere where dust and grass particles can easily cover the heater.

User avatar
Ath
Normal user
Posts: 1933
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Project: heated cabinet for charging batteries

#53 Post by Ath » 12 Sep 2022, 11:08

Cool! ;)
/Ton

User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#54 Post by chromo23 » 12 Sep 2022, 11:17

Softwarewise i unfortunately have a problem with the responsiveness of the switches and i hope somebody can help me solving it if it is possible.

The background:
I have one MCP23017 for the 16 button inputs and two PCA9685. One for the button-Leds and and one for the relays. (see attachment)

How it should work:
When a Button is pressed, the button-Led blinks for timeX. After that the button-Led as the corresponding relay turns on. (and after timeY the relay+led are turned off)

What’s the Problem:
After pressing 6-7 buttons i have 6-7 blinking leds and the ruleshandling seems to be overwhelmed with it because from this point on buttonpresses get lost very often (do not appear in the logs).
It seems, that runnning so many timers becomes a problem.

The code:
Here is my code. As you can see i use a pulse for blinking the led and therefore start the timer every second new. This improved the situation a lot because before i used a looptimer for every led. But it is still unsatisfactory.

Code: Select all

On mcp* Do
  Let,40,%eventpar% //for timer
  Let,41,%eventpar%-1 //for gpio
  Let,42,%eventpar%+16 //for blink
  LedXX.gpio,[var#41],1
 If %eventvalue1%=0
  Let,60,1
  TimerSet_ms,40,1500
 Else
  If [var#60]=1
  TimerSet,40,0
  Event,shortpress=%eventvalue1%,[var#40]
  Endif
 Endif
Endon 

On shortpress Do
 If %eventvalue1%=1 and [var#%eventvalue2%]=0 //start timer and blinking
  Let,%eventvalue2%,1   //status
  AsyncEvent,Timer=%eventvalue2%
  AsyncEvent,WaitLed=[var#41]
 Elseif %eventvalue1%=1 and [var#%eventvalue2%]=1 //if shortpressed again, turn off
  Let,%eventvalue2%,0  //status
  Let,40,%eventvalue2%+16
  Let,45,%eventvalue2%-1
  RelayXX.gpio,[var#45],0 
  LedXX.gpio,[var#45],0 
  TimerSet,%eventvalue2%,0
  TimerSet,[var#40],0
 Endif
Endon

On longpress Do
 Let,[var#40],1 //status
 RelayXX.gpio,[var#41],1 
 LedXX.gpio,[var#41],1
 TimerSet,[var#40],0
 TimerSet,[var#42],0
 Let,48,[var#41]+50
 TimerSet,[var#48],5
Endon


On Timer Do
  TimerSet,%eventvalue%,120 //delayed on
Endon

On WaitLed Do
  LedXX.pulse,%eventvalue%,1,500 
  TimerSet,[var#42],1
Endon

On rules#timer* Do
  If %eventvalue1%<17  //after timer is finished turn led and relay on
    Let,43,%eventvalue1%+16
    TimerSet,[var#43],0
    Let,[var#43],0
    Let,44,%eventvalue1%-1
    RelayXX.gpio,[var#44],1
    LedXX.gpio,[var#44],1
    Let,48,[var#44]+50
    TimerSet,[var#48],120 //after that time turn relay and led off
  Elseif %eventvalue1%<33 //blink
    Let,44,%eventvalue1%-17
    AsyncEvent,WaitLed=[var#44]
  Elseif %eventvalue1%=40
      Let,60,2
      event,longpress
  Elseif %eventvalue1%>49 And %eventvalue1%<67 //turn everything off after a while
    Let,47,%eventvalue1%-50
    RelayXX.gpio,[var#47],0
    LedXX.gpio,[var#47],0
    Let,49,[var#47]+1
    Let,[var#49],0     
The question:
What else can i do to improve the situation?
Is there a way to somehow prioritize the input, so that no input gets lost? (the precision of the timer is unimportant)
Is maybe ESPeasy not the right choice for handling 16inputs and 32 outputs via I2C?
Attachments
esp32k_DEV.png
esp32k_DEV.png (54.14 KiB) Viewed 422 times
Last edited by chromo23 on 12 Sep 2022, 17:38, edited 2 times in total.

User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#55 Post by chromo23 » 12 Sep 2022, 11:21

TD-er wrote: 12 Sep 2022, 11:02 Looks cool!
Is there also a smoke detector in it?
I always find it a bit scary to have something like a heater somewhere where dust and grass particles can easily cover the heater.
Ther will be of course.... an the room the cabinet will be located is a hall that is relatively clean and floor as walls are concrete..

User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#56 Post by chromo23 » 12 Sep 2022, 13:53

I had to change the code because async event do not work on every place on my code.
I also removed blinking via pulse because pulses can not be stopped by setting a pin via the *.gpio - command.
So it still works as it should but problem and therefore my question persists:
chromo23 wrote: 12 Sep 2022, 11:17 The question:
What else can i do to improve the situation?
Is there a way to somehow prioritize the input, so that no input gets lost? (the precision of the timer is unimportant)
Is maybe ESPeasy not the right choice for handling 16inputs and 32 outputs via I2C?

Code: Select all

On mcp* Do
  Let,40,%eventpar% //for timer
  Let,41,%eventpar%-1 //for gpio
  Let,42,%eventpar%+16 //for blink
 If %eventvalue1%=0
  LedXX.gpio,[var#41],1
  let,60,1
  TimerSet_ms,40,1500
 Else
  If [var#60]=1
  TimerSet,40,0
  Event,shortpress=%eventvalue1%,[var#40]
  Endif
 Endif
Endon 

On shortpress Do
 If %eventvalue1%=1 and [var#%eventvalue2%]=0 //start timer and blinking
  Let,%eventvalue2%,1   //status
  TimerSet,%eventvalue2%,10
  TimerSet,[var#42],1
 Elseif %eventvalue1%=1 and [var#%eventvalue2%]=1 //if shortpressed again, turn off
  Let,%eventvalue2%,0  //status
  Let,40,%eventvalue2%+16
  Let,45,%eventvalue2%-1
  RelayXX.gpio,[var#45],0 
  LedXX.gpio,[var#45],0 
  TimerSet,%eventvalue2%,0
  TimerSet,[var#40],0
 Endif
Endon

On longpress Do
 Let,[var#40],1 //status
 RelayXX.gpio,[var#41],1 
 LedXX.gpio,[var#41],1
 TimerSet,[var#40],0
 TimerSet,[var#42],0
 Let,48,[var#41]+50
 TimerSet,[var#48],5
Endon

On WaitLed Do
  TimerSet,%eventvalue%,1
Endon

On rules#timer* Do
  If %eventvalue1%<17  //after timer is finished turn led and relay on
    Let,43,%eventvalue1%+16
    TimerSet,[var#43],0
    Let,[var#43],0
    Let,44,%eventvalue1%-1
    RelayXX.gpio,[var#44],1
    LedXX.gpio,[var#44],1
    Let,48,[var#44]+50
    TimerSet,[var#48],10 //after that time turn relay and led off
  Elseif %eventvalue1%<33 //blink
    Let,%eventvalue1%,![var#%eventvalue1%]
    Let,46,%eventvalue%-17
    LedXX.gpio,[var#46],[var#%eventvalue1%]
    AsyncEvent,WaitLed=%eventvalue1%
  Elseif %eventvalue1%=40
      Let,60,2
      event,longpress
  Elseif %eventvalue1%>49 And %eventvalue1%<67 //turn everything off after a while
    Let,47,%eventvalue1%-50
    RelayXX.gpio,[var#47],0
    LedXX.gpio,[var#47],0
    Let,49,[var#47]+1
    Let,[var#49],0     
    
Edit:
It seem also to miss some other events:
in this code example the led blinks until the timer gets canceled by the timer that is in charge for the delay (10sec):

Code: Select all

 If %eventvalue1%<17  //after timer is finished turn led and relay on
    Let,43,%eventvalue1%+16
    TimerSet,[var#43],0  <----THIS TIMER SHOULD GET CANCELED
    Let,[var#43],0
    Let,44,%eventvalue1%-1
    RelayXX.gpio,[var#44],1
    LedXX.gpio,[var#44],1
    Let,48,[var#44]+50
    TimerSet,[var#48],10 //after that time turn relay and led off
I see in the logs that this is called but the led still blinks and didn´t get the call, the timer doesnt stop.. this happens with 4 out of 16 leds...
I thought everything only gets slow...but it seem also forgetful :D
Last edited by chromo23 on 12 Sep 2022, 15:05, edited 2 times in total.

User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#57 Post by chromo23 » 12 Sep 2022, 14:44

chromo23 wrote: 12 Sep 2022, 13:53 Edit:
It seem also to miss some other events:
in this code example the led blinks until the timer gets canceled by the timer that is in charge for the delay (10sec):
Ok..solved this by not calling the blink-timer with an asyncevent.
It seem that stopping a timer called this way is a hit and miss. :)
Back to square one :(
Since i cannot use an async for the blink-timer the whole thing becomes very early very unresponive again....

TD-er
Core team member
Posts: 6481
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Project: heated cabinet for charging batteries

#58 Post by TD-er » 12 Sep 2022, 21:32

event is blocking, so that it may cause unresponsiveness makes perfect sense.

The only way events may be missed is when they are not being sent. (or when they are duplicate of some events in the event queue)
And for blocking code it is not uncommon that events will be missed, like timer related events.

What are you trying to blink here?
And just as an idea, can you set some PWM on some internal GPIO pin and let the external GPIO just be the switch for such a blinking signal to flash a LED?

User avatar
Ath
Normal user
Posts: 1933
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Project: heated cabinet for charging batteries

#59 Post by Ath » 12 Sep 2022, 22:15

A few lines seem to be missing from the code examples you shared, so a bit hard to test, but also for 2 other reasons, I can't mimic the hardware setup, and the massive use of %vNNN% is rather confusing. This may take some time.

Are you trying to use 16 timers in your code? as the current limit on timers is still 8... not sure what that will result in.
/Ton

User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#60 Post by chromo23 » 12 Sep 2022, 22:17

TD-er wrote: 12 Sep 2022, 21:32 What are you trying to blink here?
See here: viewtopic.php?p=59748#p59748
TD-er wrote: 12 Sep 2022, 21:32 And just as an idea, can you set some PWM on some internal GPIO pin and let the external GPIO just be the switch for such a blinking signal to flash a LED?
I do not understand what you mean..or better i somehow know what you mean but i don’t know how i can implement that in my code...

User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#61 Post by chromo23 » 12 Sep 2022, 22:24

Ath wrote: 12 Sep 2022, 22:15 A few lines seem to be missing from the code examples you shared, so a bit hard to test, but also for 2 other reasons, I can't mimic the hardware setup, and the massive use of %vNNN% is rather confusing. This may take some time.
I wanted to simplify the code by letting things out. (it is less confusing if you use a colorhighligting and hinting script where you can easily see which variable is already in use :D )
here the complete code:

Code: Select all

On System#Boot Do
  RelayXX.gpio,all,0
  LedXX.gpio,all,0
  MCPModeRange,1,16,1
  MonitorRange,MCP,1,16
  GPIO,4,1
  TimerSet,99,1
Endon
 
On mcp* Do
  Let,40,%eventpar% //for timer
  Let,41,%eventpar%-1 //for gpio
  Let,42,%eventpar%+16 //for blink
 If %eventvalue1%=0
  LedXX.gpio,[var#41],1
  Let,60,1
  TimerSet_ms,40,1500
 Else
  If [var#60]=1
  TimerSet,40,0
  Event,shortpress=%eventvalue1%,[var#40]
  Endif
 Endif
Endon 

On shortpress Do
 If %eventvalue1%=1 and [var#%eventvalue2%]=0 //start timer and blinking
  Let,%eventvalue2%,1   //status
  If [var#70]=1
   LedXX.gpio,[var#41],0 
   TimerSet,%eventvalue2%,20
   LoopTimerSet,[var#42],2
  Else
    TimerSet_ms,%eventvalue2%,200
  Endif
 Elseif %eventvalue1%=1 and [var#%eventvalue2%]=1 //if shortpressed again, turn off
  Let,%eventvalue2%,0  //status
  Let,40,%eventvalue2%+16
  Let,45,%eventvalue2%-1
  RelayXX.gpio,[var#45],0 
  LedXX.pulse,[var#45],1,100
  //LedXX.gpio,[var#45],0 
  TimerSet,%eventvalue2%,0
  TimerSet,[var#40],0
 Endif
Endon

On longpress Do
 Let,[var#40],1 //status
 RelayXX.gpio,[var#41],1 
 LedXX.gpio,[var#41],1
 TimerSet,[var#40],0
 TimerSet,[var#42],0
 Let,48,[var#41]+50
 TimerSet,[var#48],20
Endon

On rules#timer* Do
  If %eventvalue1%<17  //after timer is finished turn led and relay on
    Let,43,%eventvalue1%+16
    TimerSet,[var#43],0
    //Let,[var#43],0
    Let,44,%eventvalue1%-1
    RelayXX.gpio,[var#44],1
    LedXX.gpio,[var#44],1
    Let,48,[var#44]+50
    TimerSet,[var#48],20 //after that time turn relay and led off
  Elseif %eventvalue1%<33 //blink
    Let,%eventvalue1%,![var#%eventvalue1%]
    Let,46,%eventvalue%-17
    LedXX.gpio,[var#46],[var#%eventvalue1%]
  Elseif %eventvalue1%=40
      Let,60,2
          LedXX.gpio,[var#44],0
      event,longpress
  Elseif %eventvalue1%>49 And %eventvalue1%<67 //turn everything off after a while
    Let,47,%eventvalue1%-50
    RelayXX.gpio,[var#47],0
    LedXX.gpio,[var#47],0
    Let,49,[var#47]+1
    Let,[var#49],0     
  //alarm------------------------
  Elseif %eventvalue1%=70 
   If [var#70]=0
    GPIO,33,1
   Endif
  Elseif %eventvalue1%=71
    If [var#70]=0
      AsyncEvent,LichtAus
    Endif
  Elseif %eventvalue1%=99
    SendToHTTP api.thingspeak.com,80,/update?api_key=XXXXXXXXXXXXXXX&field1=[sensor#Temperature]&field2=[sensor#Temperature2]&field3=[sensor#Temperature3]
    TimerSet,99,600
  Endif  
Endon

On AllRelaysevent Do
	GPIOToggle,4
Endon

On WinterSwitch#btnstate Do
   If %eventvalue% = 1
       Let,70,1
       If [DoorSwitch#btnstate]=1
        AsyncEvent,LichtAn
        7don
       Endif
    Else
      Let,70,0
      TimerSet,71,10
    Endif
  Endif
Endon

On DoorSwitch#btnstate Do
  If [var#70] = 1
    If %eventvalue% = 1
      TimerSet,70,10    
      AsyncEvent,LichtAn
      7don
    Else
      TimerSet,70,0
      GPIO,33,0
      AsyncEvent,LichtAus
      7doff
    Endif
  Else
    If %eventvalue% = 1
      TimerSet,70,0    
      GPIO,33,0
    Else
      TimerSet,70,10
    Endif
  Endif
Endon

On RedBtn#state Do
  GPIO,33,0
  TimerSet,71,300
  If [var#70]=0
    AsyncEvent,LichtAn
    TimerSet,71,10
  Endif
Endon

On sensor#Temperature Do
  7dtext,"[sensor#Temperature#F]#[sensor#Temperature2#F]#[sensor#Temperature3#F]" 
Endon

On LichtAn Do
   pwm,32,50,2000
Endon
On LichtAus Do
  pwm,32,0,1000
Endon
//webbased switches------------
On lightevent Do
  PWM,32,50,2000
Endon

On lightlong Do
  PWM,32,0,2000
Endon

On heaterrelayevent Do
    If [heaterrelay#btnState]=0
    GPIO,13,1
  Else
    GPIO,13,0
  Endif
Endon
Ath wrote: 12 Sep 2022, 22:15 Are you trying to use 16 timers in your code? as the current limit on timers is still 8... not sure what that will result in.
https://espeasy.readthedocs.io/en/lates ... imer#timer ;)
Last edited by chromo23 on 12 Sep 2022, 22:42, edited 2 times in total.

TD-er
Core team member
Posts: 6481
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Project: heated cabinet for charging batteries

#62 Post by TD-er » 12 Sep 2022, 22:25

What I meant is something like this:
- internal GPIO is set to PWM signal at some low frequency.
- This internal GPIO pin is then fed into a transistor which essentially will become the "+" for your LEDs. (call it T1)
- External GPIO pins will be sourcing the LED current to GND (call it extGpio)

So the current for the LED will then be something like this:
Vcc --- T1 --- LED + resistor --- extGPIO --- GND

TD-er
Core team member
Posts: 6481
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Project: heated cabinet for charging batteries

#63 Post by TD-er » 12 Sep 2022, 22:27

chromo23 wrote: 12 Sep 2022, 22:24 [...]
Ath wrote: 12 Sep 2022, 22:15 Are you trying to use 16 timers in your code? as the current limit on timers is still 8... not sure what that will result in.
https://espeasy.readthedocs.io/en/lates ... imer#timer ;)
Yeah @Ath... that will teach you to ask me to read the docs first before I answer you via chat about the nr of timers.,,,

User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#64 Post by chromo23 » 12 Sep 2022, 22:33

TD-er wrote: 12 Sep 2022, 22:27 Yeah @Ath... that will teach you to ask me to read the docs first before I answer you via chat about the nr of timers.,,,
:lol:
TD-er wrote: 12 Sep 2022, 22:25 What I meant is something like this:
..

Thats a very interesting approach but not suitable for my setup since the 16 leds all share the same vcc. That would mean that either all leds are blinking or none. Right?

Edit:
Ath wrote: 12 Sep 2022, 22:15 Are you trying to use 16 timers in your code? as the current limit on timers is still 8... not sure what that will result in.
I use when all buttons are pressed and it is cold outside 32 timer at the same time... 16 for waiting and 16 for blinking leds :)
Last edited by chromo23 on 12 Sep 2022, 22:46, edited 1 time in total.

TD-er
Core team member
Posts: 6481
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Project: heated cabinet for charging batteries

#65 Post by TD-er » 12 Sep 2022, 22:46

No, the idea is that the T1 is serving all LEDs the pulsing signal.
The ext GPIO pins then connect a LED to GND or not.

User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#66 Post by chromo23 » 12 Sep 2022, 22:52

TD-er wrote: 12 Sep 2022, 22:46 No, the idea is that the T1 is serving all LEDs the pulsing signal.
The ext GPIO pins then connect a LED to GND or not.
The problem with my setup is, that after the waiting time (leds are blinking ) is over the led is constantly on to visualize that the powersocket is switched on.
and the buttons are all pressed at different times. so some led are blinking and some are already constantly on...

TD-er
Core team member
Posts: 6481
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Project: heated cabinet for charging batteries

#67 Post by TD-er » 12 Sep 2022, 22:59

You could use a 2nd ext GPIO pin and a diode.

But there is another idea....
I know there are LEDs which are dual color and there are even ones that have a flashing circuit in them.
Or what about NeoPixel ones, which are very easy to set to a specific color.
This also needs a single GPIO pin to controll all LEDs.


Edit:
Example of flashing LEDs:
https://nl.farnell.com/c/optoelectronic ... nking-leds

User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#68 Post by chromo23 » 12 Sep 2022, 23:20

Thank you @TD-er, these are all good ideas but i don´t wanna change so much now because the cabinet will be picked up at the end of this week.
The buttons have the build in led and i am not gonna change every led in every button. but next time i maybe replace the led-strips which lights the shelves with adressable ones so that every "compartment" gets an "ceiling indicator light"

User avatar
chromo23
Normal user
Posts: 432
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Project: heated cabinet for charging batteries

#69 Post by chromo23 » 13 Sep 2022, 22:39

TD-er wrote: 12 Sep 2022, 21:32 And just as an idea, can you set some PWM on some internal GPIO pin and let the external GPIO just be the switch for such a blinking signal to flash a LED?
FIY @TD-er, by going through the datasheet of the PCA9685 i found out, that there is a pin for that ;) :
pca.png
pca.png (41.29 KiB) Viewed 270 times
Unfortunately blinking individual leds with a PCA9685 seem to be only possible using timer in rules...

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest