Project: heated cabinet for charging batteries

Moderators: grovkillen, Stuntteam, TD-er

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

Project: heated cabinet for charging batteries

#1 Post by chromo23 » 13 Apr 2022, 12:15

A friend of mine asked me to build him a heated cabinet for charging batteries.
He has a small company for cutting trees and they have many chargers for their devices.
So in the winter when it gets cold he wants charge the batteries after use.
The idea is to put a batterie in the heated cabinet push a button (with a led for feedback) and if the outside temperature (measured by the ds1820) is below a given value wait a given time before turning the charger on so that the batterie can get warm before charging. And on the next day you have a heated batterie wich can operate unter full load.

My question regarding my "schematic":
- Can i daisy chain the devices this way (what do I have to consider?)? Especially three PCA9685? If so how would i address them individually.
Pseudocode (how do i get the # of the gpio of the pushbutton as an eventvalue...this would make the rules much smaller):

Code: Select all

On PCA#2,gpio#1 = 1 do  // when pushbutton on the first gpio is pressed
 PCA#3,<gpio of PCA#2>,1     //switch on the corresponding led
 if [ds1820#temperature] < 5
  timerset,<gpio of PCA#2>,1800
 else
  PCA#1,<gpio of PCA#2>,1  //if it is not too cold switch the charger on immediately  
 endif
endon
  
on Rules#Timer=1 do
PCA#1,<gpio of PCA#2>,1  //turn on the charger after half an hour 
endon
- Is the esp8266 capable of handling this? (5 devices on i2c and at least one relay more and the ds1820) Worst case on software are 16 timers at the same time an maybe 16 more for blinking leds (all in all maybe 48 timer)
- Are there any better choices hardwarewise?
akkuschrank 2.jpg
akkuschrank 2.jpg (161.13 KiB) Viewed 12069 times

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

Re: Project: heated cabinet for charging batteries

#2 Post by TD-er » 13 Apr 2022, 12:45

Running devices via I2C is no problem at all.
Only thing you might want to check is that all chips connected can run at the same clock speed.
You may also want to look at the wiring of the I2C bus as you do have quite a lot of "coils" next to it.
Thus switching relais may cause magnetic fields which may disturb the signal.
It is best to use the I2C wires as short as possible, and given you may have some noise caused by the relais you better twist the GND and the SDA/SCL wires just like is done in network cables.
Also look at the pull-up resistors on the SDA/SCL cables as all of these boards may have their own pull-up resistors present.
Having too many of those resistors may make it harder to pull the signal down, either by the ESP or the I2C devices.


The noise aspects may also cause issues on the push buttons, so try to keep those cables as short as possible.
Maybe use a keypad matrix (and keypad plugin) for those?

The LEDs are not critical as those will not be an input.

Regarding the rules, I think you should look into writing some basic rule blocks which accept several eventvalues as that makes the rules quite simple.
Also using a keypad instead of considering them as 16 switches will make things a lot simpler.
N.B. you can also wire the buttons into a matrix using diodes, so choosing a keypad plugin does not mean you need a flimsy film keypad which may be challenging in harsh environments as those contacts are not always very reliable or the size of the buttons may be hard to use wearing work gloves.

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

Re: Project: heated cabinet for charging batteries

#3 Post by chromo23 » 13 Apr 2022, 13:00

Thank you for the hints.
A keypad matrix is a nice idea but each push-button will be next to the corresponding charger to make it more "foolproof".

Is there already some documentation how to a write rules for multiple instances of the PCA9685?

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

Re: Project: heated cabinet for charging batteries

#4 Post by TD-er » 13 Apr 2022, 13:10

The GPIO expander boards have their pins enumerated based on the I2C address.
Thus by setting it to a different address, it may be represented in ESPEasy via different pin nrs.

Hmm the documentation for the PCA9685 is apparently non-existent and what is present does not make any sense as it seems to have some wiring details which do seem to be about the SenseAir S8 sensor.

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

Re: Project: heated cabinet for charging batteries

#5 Post by Ath » 13 Apr 2022, 13:26

For the Keypad plugin (P061) I've added documentation in PR#3927 but that doesn't support PCA9685, and for P022 I've also updated the documentation a bit (mostly the commands supported) in PR#3970
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#6 Post by chromo23 » 13 Apr 2022, 13:42

That means, that since there is no proper way to address these board as multiple instances in rules (at least no documented way) i have to use another option... is there any?

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

Re: Project: heated cabinet for charging batteries

#7 Post by Ath » 13 Apr 2022, 15:18

There is a perfectly fine way to address each pin separately, both for input and output, even when daisy-chaining the max. possible number of boards together (8 or 16 not sure), by using 'monitor,pca,(pin)' for input and 'pcagpio,(pin),(0|1)`for output ('monitor,mcp,(pin)' and 'mcpgpio,(pin),(0|1)' for MCP23017), where pin can be between 0 and 255 (AFAIK). The monitor command does involve having an event for each pin, though, that's why was suggested to use the Keypad plugin, as that supports a matrix-like switch configuration (max. 9x8 = 72 with one plugin using MCP23017 or PCF8575 board/chip, 5x4 = 20 using a PCF8574, multiple plugins when using the code from the P061 PR). Currently, P061 does not support the PCA9685.
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#8 Post by Ath » 13 Apr 2022, 15:27

Ath wrote: 13 Apr 2022, 15:18 Currently, P061 does not support the PCA9685.
So there's still room for improvement :lol:
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#9 Post by Ath » 13 Apr 2022, 15:30

Also, take care to wire the LEDs to light up by setting the pins to 0, not to 1, as the outputs can not deliver much current (~5mA), but they can sink 'much' more to ground (~20mA).
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#10 Post by chromo23 » 13 Apr 2022, 15:33

Thank you...

So i could monitor the state of all 16 push buttons with 'monitor,pca,(pin)' which i set on booting like this right?:

Code: Select all

On System#Boot do
 monitor,pca,1
  .
  .
  .
 monitor,pca,16
endon
I feel like I've read it before that monitoring gpios is recource hungry.... ??? (If i wanted to monitor also the relay states it would be even 32)

and do you have a suggestion how i could somehow put this then in a variable form where i do not need to address each pin (of relay + led) in rules seperatly.

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

Re: Project: heated cabinet for charging batteries

#11 Post by Ath » 13 Apr 2022, 15:39

The addressing is by soldering a resistor either to GND or VCC, like in this picture:
Screenshot - 13-04-2022 , 15_32_16.png
Screenshot - 13-04-2022 , 15_32_16.png (134.51 KiB) Viewed 12028 times
and it actually allows 128 different addresses, but that would fill the I2C address-space, not leaving any room for other devices :o :lol:
But ESPEasy only supports the first 16 addresses, as it calculates the address (0-15) from the pin-number (0-255). And for a P022 task the pin-number range supported from the address selected in the task.

Why would you want to monitor the relays? If you need to keep status, you can store that in internal variables (let 100+relay_number,state).

And there is the, not yet correctly documented, 'monitorrange,pca,(startgpio),(endgpio)' command.
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#12 Post by chromo23 » 13 Apr 2022, 15:49

Ok...it seems that it can be done and this project might be an interesting challenge so i will order 3 PCA9685 to test this and report about it. :)
Why would you want to monitor the relays? If you need to keep status, you can store that in internal variables (let 100+relay_number,state).
You are right this should suffice...


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

Re: Project: heated cabinet for charging batteries

#14 Post by Ath » 13 Apr 2022, 17:26

chromo23 wrote: 13 Apr 2022, 15:49 Ok...it seems that it can be done and this project might be an interesting challenge so i will order 3 PCA9685 to test this and report about it. :)
If you would order some MCP23017 boards, then you would be able to use the Keypad driver, as an alternative option. For the rest it is quite similar to the PCA9685, or did I miss some special feature of that board, besides the PWM functionality that you shouldn't need for this project?
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#15 Post by chromo23 » 13 Apr 2022, 20:18

Ath wrote: 13 Apr 2022, 17:26 If you would order some MCP23017 boards, then you would be able to use the Keypad driver, as an alternative option. For the rest it is quite similar to the PCA9685, or did I miss some special feature of that board, besides the PWM functionality that you shouldn't need for this project?
I read this a bit too late...i already ordered
The only thing that led me to the PCA9685 was the board layout. For separately connecting pushbuttons or leds the three row header of vcc, data and ground is really convenient.

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

Re: Project: heated cabinet for charging batteries

#16 Post by Ath » 13 Apr 2022, 20:58

Well, looking at the PCA9685 datasheet now, it is in fact a LED driver, offering up to 10 mA on high output, and able to sink up to 25 mA per pin. It 'only' supports up to 62 I2C addresses, not 128, as I have previously stated. But it also states: No input function :shock:

So for your buttons you will need another type of chip, like the MCP23017, or PCF8574, that offer Input/Output GPIO's, and can both be used by the Keypad (P061) plugin ;)
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#17 Post by chromo23 » 13 Apr 2022, 21:11

Ha!... thank you @Ath!!

I was able to cancel the order... :)
What do you recommend?
2 x PCA9685 for relay and LED and 1x MCP23017 for input
or
3x MCP23017

I also haven't found a MCP23017 board where i can change the i2c address....

Edit: found one...

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

Re: Project: heated cabinet for charging batteries

#18 Post by Ath » 13 Apr 2022, 21:23

As you are only switching On/Off, both for input and output (led brightness can be selected using an appropriate resistor), I'd go for all MCP23017, as that (also) has 16 pins. That even allows to deliver up to 25 mA from a pin, but the max. current for 16 pins concurrently is 150 mA, so limiting the current is required. But a few (5..10) mA should be enough to light up a LED sufficiently.
chromo23 wrote: 13 Apr 2022, 15:53 What is the "Mode2" in P22?
This seems no longer so relevant, but since you asked:

That is the value that is written to the MODE2 register, this are the configuration options for that register from the datasheet:
Screenshot - 13-04-2022 , 21_10_22.png
Screenshot - 13-04-2022 , 21_10_22.png (160.63 KiB) Viewed 11991 times
(Not exhaustive, for the details, download the datasheet from the NXP site)
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#19 Post by Ath » 13 Apr 2022, 22:00

To add to the confusion ;) recently plugin P126 'Output - Shift registers (74HC595)' has been added (TEST_E builds), that can offer many output pins (16 per chip) when daisy-chaining chips, and has the added feature that the states of up to 128 outputs can be retained across a reboot (not a power-cycle!).
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#20 Post by chromo23 » 14 Apr 2022, 14:27

Ath wrote: 13 Apr 2022, 22:00 To add to the confusion ;) recently plugin P126 'Output - Shift registers (74HC595)' has been added (TEST_E builds), that can offer many output pins (16 per chip) when daisy-chaining chips, and has the added feature that the states of up to 128 outputs can be retained across a reboot (not a power-cycle!).
:shock:

I think i´ll stick to the mcp for now... :)
I just ordered one for testing.
And i realized that i had lying around two PCF8574 and since they are syntaxwise similar to the MCP23017 i started trying...
Monitor a range of pins works well. Which leads me to my next question:
Is there a way to get the pin number in rules or do i have to write

Code: Select all

on pcf#<pinnr> do
16 times?

Something like:

Code: Select all

on PCF#AnyPin=1 do
LogEntry,'Pin Number: %eventvalue%'
endon
Edit: question nr 2: is there a long press option without assigning every pin to a task?

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

Re: Project: heated cabinet for charging batteries

#21 Post by TD-er » 14 Apr 2022, 14:40

You could use it with the ! in front of the event, this way the event is present in the %eventvalue% variable.
This can then be processed by the substring command. See: https://espeasy.readthedocs.io/en/lates ... #substring

Code: Select all

on !pcf# do
  let,1,{substring:4:6:%eventvalue%}
endon
Or fire some new event if you need to include other stuff too.

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

Re: Project: heated cabinet for charging batteries

#22 Post by chromo23 » 14 Apr 2022, 15:04

Code: Select all

on !pcf# do
does not work...

build is from 3rd april
edit: also tested on mega-20220328

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

Re: Project: heated cabinet for charging batteries

#23 Post by Ath » 14 Apr 2022, 15:21

You may need to use:

Code: Select all

on !pcf#* do
(Add the '*' wild-card character)
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#24 Post by chromo23 » 14 Apr 2022, 15:25

no luck with this either... do i have to enable something for this to work?

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

Re: Project: heated cabinet for charging batteries

#25 Post by TD-er » 14 Apr 2022, 18:38

chromo23 wrote: 14 Apr 2022, 15:25 no luck with this either... do i have to enable something for this to work?
The thing is, this feature was recently rediscovered through an issue.
So we also need to look into the code to see how it is supposed to work as it is not documented.

Just to make sure, you are using %eventvalue% and not %eventvalue1% ?

And do you see the exact events in the logs? If so, please show some here.

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

Re: Project: heated cabinet for charging batteries

#26 Post by chromo23 » 14 Apr 2022, 18:42

this is the log:

EVENT: PCF#15=0

an this is the test rule:

Code: Select all

on !pcf#* do 
logentry,'test'
endon
and this is the rule to verify the content of the last rule :) : (which is working of course)

Code: Select all

on pcf#15 do 
logentry,'test'
endon
edit: as you can see i didn´t try to get the eventvalue i just wanted something so see if the event is triggered at all..

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

Re: Project: heated cabinet for charging batteries

#27 Post by Ath » 14 Apr 2022, 20:03

Both logentry statements have the same message, how do you determine which one was logged :shock:
/Ton (PayPal.me)

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

Re: Project: heated cabinet for charging batteries

#28 Post by TD-er » 14 Apr 2022, 20:35

Just thinking, maybe you could test something like this:

Code: Select all

on !pcf* do
  logentry,"PCF event: %eventvalue%"
endon

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

Re: Project: heated cabinet for charging batteries

#29 Post by chromo23 » 14 Apr 2022, 22:43

Ath wrote: 14 Apr 2022, 20:03 Both logentry statements have the same message, how do you determine which one was logged :shock:
I didn‘t… i just edited the one rule and tested again ;)

@TD-er: I’ll keep trying…

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

Re: Project: heated cabinet for charging batteries

#30 Post by chromo23 » 14 Apr 2022, 22:54

TD-er wrote: 14 Apr 2022, 20:35 Just thinking, maybe you could test something like this:

Code: Select all

on !pcf* do
  logentry,"PCF event: %eventvalue%"
endon
Still no luck…

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

Re: Project: heated cabinet for charging batteries

#31 Post by TD-er » 15 Apr 2022, 09:31

Since I'm working on that part of the code currently to improve the rules handling speed, I will make sure to look at it.
Either to make it work like we suggested, or add %eventvalue0% to access the event name.
Or if by looking at the code, I find out how it does work in current builds, I will report it here of course :) (and document it...)

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

Re: Project: heated cabinet for charging batteries

#32 Post by chromo23 » 15 Apr 2022, 10:48

Ok… thank you!
I have anyway time until next winter to build this and worst case is, to write 16 rules. one for each push button. :)

But this feature would be a really nice to have of course. Not only for this project.

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

Re: Project: heated cabinet for charging batteries

#33 Post by TD-er » 15 Apr 2022, 13:05

Ah found why it might not work how we tried it.
The ! idea is handled in the rules as a special case and the Serial Server plugin (P020) does generate special events with the ! as first char in the event.

So maybe you could rename your task to have the ! as first char.
You will probably get a warning, but it will save it.

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

Re: Project: heated cabinet for charging batteries

#34 Post by chromo23 » 15 Apr 2022, 19:11

TD-er wrote: 15 Apr 2022, 13:05 So maybe you could rename your task to have the ! as first char.
this works.. but only for the one pin you can assign in the task (all the other pins are listed in the log as a different event)

This is the log for an assigned pin (i gave the task another name than pfc to make clear there are different events):
474499: EVENT: !pcftest#All=0
474527: ACT : logentry,#A
474528: #A


The rule for that:

Code: Select all

on !pcftest#* do // also tried and triggert : !pcftest and !pcftest*   did not work: !pcftest# 
  logentry,{substring:4:6:%eventvalue%}
endon
For all the other pins not assigned to to a task, the log shows this:
EVENT: PCF#1=0
EVENT: PCF#2=0
...


So for a task it might work if the eventoutput would give the right informations but for this plugin which also creates "extra" events it doesn´t....

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

Re: Project: heated cabinet for charging batteries

#35 Post by TD-er » 15 Apr 2022, 22:53

Check!
So we need the %eventvalue0% option to make this work properly.


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

Re: Project: heated cabinet for charging batteries

#37 Post by chromo23 » 20 Apr 2022, 11:01

Hi TD-er,

can you compile this for me (esp8266 4m). I am in my weekend house and i forgot my computer (somewhat intentionally :roll: ). i have a very old laptop here on which i am writing right now but it is awfully slow.

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

Re: Project: heated cabinet for charging batteries

#38 Post by TD-er » 20 Apr 2022, 12:14

When the GitHub actions build is done (with very nice latest commit ;) ) can you try to download the built assets from here: https://github.com/letscontrolit/ESPEas ... 2194997001 ?

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

Re: Project: heated cabinet for charging batteries

#39 Post by chromo23 » 20 Apr 2022, 13:32

First of all: It is a very nice addition!!!
It seems to work as expected and if i find issues i´ll let you know...

But this doesn´t help me as stated before:
chromo23 wrote: 15 Apr 2022, 19:11
TD-er wrote: 15 Apr 2022, 13:05 So maybe you could rename your task to have the ! as first char.
this works.. but only for the one pin you can assign in the task (all the other pins are listed in the log as a different event)

This is the log for an assigned pin (i gave the task another name than pfc to make clear there are different events):
474499: EVENT: !pcftest#All=0
474527: ACT : logentry,#A
474528: #A


The rule for that:

Code: Select all

on !pcftest#* do // also tried and triggert : !pcftest and !pcftest*   did not work: !pcftest# 
  logentry,{substring:4:6:%eventvalue%}
endon
For all the other pins not assigned to to a task, the log shows this:
EVENT: PCF#1=0
EVENT: PCF#2=0
...


So for a task it might work if the eventoutput would give the right informations but for this plugin which also creates "extra" events it doesn´t....
So what has changed for me:
Rules are now also triggered by an event that is not defined by a taskname. That´s progress....
But for these particular events there is of course no possibility to add an ! to get the whole event as an eventvalue...
Suggestion: don´t define this with an ! in front of tasknames. It would be better to achieve this by something like: %eventvalueA% (a as in all).. what do you think so we get all events by this and no renaming of tasknames...

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

Re: Project: heated cabinet for charging batteries

#40 Post by TD-er » 20 Apr 2022, 13:40

You don't need to prefix the ! anymore.
That's also being fixed now.

%eventvalue0% has all eventvalues
%eventname% has everything of the event before the =
%eventpar% has everything of %eventname% between # and = (might thus be empty)

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

Re: Project: heated cabinet for charging batteries

#41 Post by chromo23 » 20 Apr 2022, 13:45

That is so cool!! it works.. Thank you.

(I did look at the new documentation but i was searching for %eventvalue% to find the changes.. but the really interesting stuff is one section before :roll: )

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

Re: Project: heated cabinet for charging batteries

#42 Post by TD-er » 20 Apr 2022, 13:50

Now added a "restrict" keyword so you can safely execute eventvalues too.

event,eventvalues='logentry,test'

Code: Select all

on eventvalues* do
//  logentry,"test eventvalues: 0:%eventvalue% 1:%eventvalue1% 2:%eventvalue2% 3:%eventvalue3% 4:%eventvalue4% 5:%eventvalue5% 6:%eventvalue6%"
//  logentry,"All eventvalues: %eventvalue0%"
//  logentry,"Not existing eventvalue: %eventvalue10|NaN%"
  %eventvalue1|%
endon

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

Re: Project: heated cabinet for charging batteries

#43 Post by TD-er » 21 Apr 2022, 11:22

Just pushed a new commit to fix a bug I introduced yesterday which mangles the rules line when processing an eventvalue without | for the default value.

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

Re: Project: heated cabinet for charging batteries

#44 Post by chromo23 » 22 Apr 2022, 11:17

Can you elaborate the "restrict" keyword...

I´m not getting it :?

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

Re: Project: heated cabinet for charging batteries

#45 Post by Ath » 22 Apr 2022, 11:30

/Ton (PayPal.me)


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

Re: Project: heated cabinet for charging batteries

#47 Post by chromo23 » 02 May 2022, 11:16

Only one mcp2307arrived. :( So i bought the pca9685 in a package of three because it is much cheaper and was here after one day.
For the testing of the code i connected on each pca9685 a 8channel relay so that one can act as the "status-leds"....
With the new event options the rules get really (esp)easy. :P
The test code does this:
-if a mcp-pin gets high the "status-led" blinks 5 seconds an after that the relay is activated
- if the mcp-pin gets high again the "status-led" and the relay turns off

Code: Select all

on system#boot do
 relay.gpio,1,0 //initially all pins are high and somehow setting one pin low
 led.gpio,3,0 // sets them all low (doesn´t matter which one)
 MCPmodeRange,1,16,1
 MonitorRange,MCP,1,16
endon

on mcp* do
 if %eventvalue1%=0 and [var#%eventpar%]=0
  timerSet,%eventpar%,5
  let,40,%eventpar%+16
  loopTimerSet,[var#40],1
  let,%eventpar%,1
 elseif %eventvalue1%=0 and [var#%eventpar%]=1
  let,41,%eventpar%-1 //here inline calculation works 
  relay.gpio,[var#41],0 //inline calculation doesn't work here
  led.gpio,[var#41],0 //inline calculation doesn't work here
  let,%eventpar%,0
  timerSet,%eventpar%,0
  timerSet,[var#40],0
 endif
endon

on rules#timer* do
if %eventvalue1%<17
 let,42,%eventvalue1%+16
 timerSet,[var#42],0
 let,[var#42],0
 let,43,%eventvalue1%-1 //here inline calculation works
 relay.gpio,[var#43],1 //inline calculation doesn't work here
 led.gpio,[var#43],1 //inline calculation doesn't work here
else //blink
 let,%eventvalue1%,![var#%eventvalue1%]
  let,44,%eventvalue1%-17
  led.gpio,[var#44],[var#%eventvalue1%]
endif
endon
Issues:
1. no inline calculation option for the first parameter. therefore i have to use an extra line for calculation with variables.
-> is there a syntax for that?
2. pca9685: [<taskname>].gpio,all,<value> to switch all pins doesn’t work but is stated in the documentation. what do i wrong?
3. relays are initally high because of the way they are handeled in combination with the pca9685. So i have to turn them all off after boot (it is a fraction of a second and if it leads to problems i use a mosfet to cut the power until the command is issued )
4. using a max7219 7seg leads to a (fortunately not infinite) bootloop and a deactivation of the plugin after that. -> i´ll do some investigation. i already testet 2 modules and with a fresh microcontroller detached from this project -> edit:opened a new issue in github for that -> edit2:fixed

Good things:
The pca9685 is really nice to drive leds since it has already current limiting resistors for each pin and the pinlayout makes it easy to connect them individually...

Test setup:
IMG_0890.jpg
IMG_0890.jpg (288.23 KiB) Viewed 11044 times

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

Re: Project: heated cabinet for charging batteries

#48 Post by chromo23 » 03 May 2022, 17:34

chromo23 wrote: 02 May 2022, 11:16 4. using a max7219 7seg leads to a (fortunately not infinite) bootloop and a deactivation of the plugin after that. -> i´ll do some investigation. i already testet 2 modules and with a fresh microcontroller detached from this project -> edit:opened a new issue in github for that -> edit2:fixed
The display works thanks to the quick resonse of @TD-er and @Ath

There is still this inline calculation issue
chromo23 wrote: 02 May 2022, 11:16 1. no inline calculation option for the first parameter. therefore i have to use an extra line for calculation with variables.
-> is there a syntax for that?
@TD-er do you know if it is possible with the current firmware?

I added a longpress option in rules :)
code is still relatively small...

Code: Select all

on system#boot do
 loopTimerSet_ms,50,10,16 //substitution for [pca].gpio,all,0
 MCPmodeRange,1,16,1
 MonitorRange,MCP,1,16
endon

on mcp* do
 if %eventvalue1%=0
  let,60,1
  timerset_ms,40,1000
  timerset_ms,41,1500
 else
  if [var#60]=1
   timerset,40,0
   event,shortpress=%eventvalue1%,%eventpar%
   let,60,1
  endif
 endif
endon

on shortpress do
 if %eventvalue1%=1 and [var#%eventvalue2%]=0
  let,%eventvalue2%,1   //status
  let,45,%eventvalue2%-1
  timerSet,%eventvalue2%,10 //delayed on
  let,40,%eventvalue2%+16
  loopTimerSet,[var#40],1
 elseif %eventvalue1%=1 and [var#%eventvalue2%]=1
  let,%eventvalue2%,0  //status
  let,41,%eventvalue2%-1 //here inline calculation works 
  relay.gpio,[var#41],0 //inline calculation doesn't work here
  led.gpio,[var#41],0 //inline calculation doesn't work here
  timerSet,%eventvalue2%,0
  timerSet,[var#40],0
 endif
endon

on longpress do
 let,46,[var#45]+1 //status
 let,[var#46],1
 relay.gpio,[var#45],1 
 led.gpio,[var#45],1
 timerSet,[var#40],0
 timerSet,[var#46],0
endon

on rules#timer* do
 if %eventvalue1%<17
  let,42,%eventvalue1%+16
  timerSet,[var#42],0
  let,[var#42],0
  let,43,%eventvalue1%-1
  relay.gpio,[var#43],1
  led.gpio,[var#43],1
 elseif %eventvalue1%<33 //blink
  let,%eventvalue1%,![var#%eventvalue1%]
  let,44,%eventvalue1%-17
  led.gpio,[var#44],[var#%eventvalue1%]
 elseif %eventvalue1%=40
  let,60,2
 elseif %eventvalue1%=41 
  if [var#60]=2
   event,longpress
  endif
 elseif %eventvalue1%=50 //turn all gpios off
  if [var#50] > 16
   let,50,0
  endif
  relay.gpio,[var#50],0
  led.gpio,[var#50],0
  let,50,[var#50]+1
 endif
endon

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

Re: Project: heated cabinet for charging batteries

#49 Post by TD-er » 03 May 2022, 20:07

chromo23 wrote: 03 May 2022, 17:34 [...]
There is still this inline calculation issue
chromo23 wrote: 02 May 2022, 11:16 1. no inline calculation option for the first parameter. therefore i have to use an extra line for calculation with variables.
-> is there a syntax for that?
@TD-er do you know if it is possible with the current firmware?

[...]

Code: Select all

  let,41,%eventvalue2%-1 //here inline calculation works 
  relay.gpio,[var#41],0 //inline calculation doesn't work here
  led.gpio,[var#41],0 //inline calculation doesn't work here
Ah those...
Nope, right now if you need to calculate things, you need to assign it to a variable first using the let command.

At some other places it still might work, but not sure when. So better assume it only works on the let command.

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

Re: Project: heated cabinet for charging batteries

#50 Post by chromo23 » 06 May 2022, 17:56

I printed holder for the boards and attached them to a "main-board"
IMG_0909.jpg
IMG_0909.jpg (361.93 KiB) Viewed 10759 times
Testing is much more fun when not all of the components sort of flying around on the desk.


I went with old school perfboard soldering. Not the most beautiful piece i ever did but it will suffice. :D
(I never found the motivation to create a circuit board on the computer and order it. I guess it doesn’t make sense when every board is unique and it probably doesn’t save me a lot from torturing my body, since soldering and working at the computer are playing in the same class when it comes to that. )
And i decided to go with an esp32 (the first time ever :) ) to have a bit headroom in terms of gpios. I could have used another board extender but i wanted to uses as little extra components as possible to reduce the room for errors.
IMG_0898.JPG
IMG_0898.JPG (141.08 KiB) Viewed 10759 times
IMG_0897.JPG
IMG_0897.JPG (122.21 KiB) Viewed 10759 times
A first sketch how the chargers are placed. I prefer the 2 rows 8 chargers variant but the 4x4 options is easier to put in existing cabinets:
(under each charger is a backlit button to activate the charger)
cabinet.png
cabinet.png (190.28 KiB) Viewed 10756 times

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests