Closed DrJeff closed 3 years ago
Oh so you have 2 mcp23017 boards on different addresses for a total of 32 I/Os?
Si (yes)
Even if I only have one MCP connected same behavior
That should be fine so long as they have separate addresses. Do both chips show in REM on separate addresses?
I am going to add some code to initialize these as outputs for each of the relays you have defined. It should be reading 0x12 to get the current state of the first 8 (on each board) and 0x13 to get the state for the second 8.
When you see a return of 0xFF
1|REM | debug: Executed read command 0x12 byte read:0xff
It should indicate that the first 8 relays are triggered.
That should be fine so long as they have separate addresses. Do both chips show in REM on separate addresses?
Yes They are seen separately I am going to add some code to initialize these as outputs for each of the relays you have defined. It should be reading 0x12 to get the current state of the first 8 (on each board) and 0x13 to get the state for the second 8.
👍🏽
1|REM | debug: Executed read command 0x12 byte read:0x7f 1|REM | debug: Executed read command 0x13 byte read:0x80 1|REM | error: Multi-Relay Board Read Command: Invalid I2C command undefined 1|REM | debug: Executed read command 0x12 byte read:0x7f 1|REM | debug: Executed read command 0x13 byte read:0x80 1|REM | error: Multi-Relay Board Read Command: Invalid I2C command undefined
This is from the other MCP @ address 0X26
Go ahead and pull REM. It now initializes the I/O registers for the chip to outputs for every defined relay. There is also a dump of all the registers on the chip (sans GPIO). This lists the settings. Mine are 0 because I do not have an mcp relay. Please provide a screenshot so I can see the value of all these registers after you get set up.
Ok was working but then setup other and lost all. Address 39 was the working toggle of relays ok. then setup address 38 and lost both.
I got Greedy/Excited!
Alright, I think I figured this out. Turns out the pin directions are exactly opposite of how I read the docs. Pull REM. 0 = output (what we want). 1 = input (what we don't want to control a relay).
In your case we were setting the IODIRA/B to 255 which meant add ports were inputs.
I also find it a bit weird that your IPOLA/B settings are set to reversed for some of the pins. Is this intentional?
Alright, I think I figured this out. Turns out the pin directions are exactly opposite of how I read the docs. Pull REM. 0 = output (what we want). 1 = input (what we don't want to control a relay).
Nice
In your case we were setting the IODIRA/B to 255 which meant add ports were inputs.
Makes since now
I also find it a bit weird that your IPOLA/B settings are set to reversed for some of the pins. Is this intentional?
Not Sure maybe because I set them in Node Red?
Yes, Thanks
Here goes both fully functional!
Ok now that the lighting relay board is in REM can nixie control Intellibrites with just the relays? Im currentlly doing it via Node Red
Oops too excited too fast on the relays on address 39 1-6 not working?
Hmmm.... that can't be. There is a single register being set for the first 8 relays. Is anything else hitting those relays?
I wonder if the latch has to be written instead of the GPIO, The docs couldn't be more unclear. The GPIO docs say this.
But the OLAT docs say this.
Ok so pull REM. It is now writing to OLAT instead of directly to GPIO. I can only imagine that this is the difference between writing instantaneous values vs writing a latched value. The docs are pretty dumb.
You conquered that dumb document nicely! 😁
Now they all work they are inverted or no let me correct that my relays are inverted active LOW. Can I invert the GUI or do it via filter expressions and if so how do I write that?
I am a bit puzzled by the values of IPOLA/B on both boards. According to the docs the power on reset value for these registers is supposed to be 0x00 but yours are 0xFF.
On top of that the documentation says that this is input polarity but they actually incorrectly use that term very loosely to describe the actual GPIO pin in other places in this document. So first lets try running this from a console prompt.
i2cset -y 1 0x27 0x02 0x00 b
You may have to sudo this command depending on your installation. Then test the relay and see if it is set to active-HIGH. If it is then power off the pi and restart it. Do not simply reboot it power it down. Then come back into REM and see it the main relay board has IPOLA set to 0. If it does and IPOLB is still 255 (0xFF) then run the following commands.
i2cset -y 1 0x27 0x03 0x00 b
i2cset -y 1 0x26 0x02 0x00 b
i2cset -y 1 0x26 0x03 0x00 b
Then power down the pi and restart it. Go into both boards and see if the IPOLA/B values are all still 0. If they aren't and that command worked then something (probably the carrier board) is setting these values outside of REM. The board you referenced doesn't seem to have any documentation.
So first lets try running this from a console prompt.
i2cset -y 1 0x27 0x02 0x00 b
Tried above with sudo shutdown now
doesn't change behavior does change IPOLA to 0
The Pin
still follows the polarity ON
in REM is HIGH
on pin. I'm looking for ON
= LOW
I did remove Node Red from the Mix just in case it was messing with the I2c.
Oh wait. Hold on why do you have it wired this way? The way you should be doing this is when the you are low 0v the relay should be switched to NO. That way if the relay fails or the pi loses power or a connection is broken the NO state is the default state. If not a failure means that the whole thing comes to life.
So you most likely have the wires on backwards on the relay itself. If you must do this and I highly suggest you don't, you can do this by setting the trigger on the binding tab.
Ok I get the hole thing wakes up is an issue, because it is! I solved this in the past with a separate independent relay that supplies the ground between the relay board and I2c when switched. The relay board is Active Low like this one https://www.amazon.com/SainSmart-101-70-103-16-Channel-Relay-Module/dp/B0057OC66U/ref=sr_1_3?crid=37PTJ2HR1KVMZ&dchild=1&keywords=16+relay+board&qid=1616607050&sprefix=16+relay%2Caps%2C215&sr=8-3 I don't understand the binding? Does that mean it will not work until it's booted? Then can I set the reverse logic in the Filter Expression? How, If statement?
All the boards I'm finding are active LOW (5v 12v) it was if I remember correctly because less power consumption?? Any suggestions I'm open
Found this
https://www.best-microcontroller-projects.com/mcp23017.html
Is this helpful?
Yeah the mcp chip only operates Active High with a default initial setting of 0v hence the reason why there is no pull down. The active low scenario plays well with installations where a battery is involved since there is no parasite power draw to keep the relay latched.
However, this is the antithesis of what we want to accomplish here. Realistically, you want all circuits open when power is removed. I get that you are doing this with another relay on the ground but yuck. I can synthesize this in the code but you still have that mismatch. If we were driving this from GPIO then inverting the pin is ok since the states are all persisted so long as you do not un-export the pin. But you still would get a burp when the pin is initialized.
If it were me I would choose another path. Either find a relay board that operates active-HIGH and use the mcp or stack 4 of these to get to 32 relays. https://sequentmicrosystems.com/shop/home-automation/raspberry-pi-relays-stackable-card/ Either way I will put an invert flag on the relay to simulate a GPIO active-LOW.
Yeah the mcp chip only operates Active High with a default initial setting of 0v hence the reason why there is no pull down. The active low scenario plays well with installations where a battery is involved since there is no parasite power draw to keep the relay latched.
However, this is the antithesis of what we want to accomplish here. Realistically, you want all circuits open when power is removed. I get that you are doing this with another relay on the ground but yuck.
😆
I can synthesize this in the code but you still have that mismatch. If we were driving this from GPIO then inverting the pin is ok since the states are all persisted so long as you do not un-export the pin. But you still would get a burp when the pin is initialized.
Yes thats the "burp" I'm used to.
If it were me I would choose another path. Either find a relay board that operates active-HIGH and use the mcp or stack 4 of these to get to 32 relays. https://sequentmicrosystems.com/shop/home-automation/raspberry-pi-relays-stackable-card/
I will hunt for an active High board but my new setup moved the Pi inside of the house no more heat issue in a box! 👍🏽 Because the only thing in the box is a Relay board and a MCP23017. The data is Solid between the Pi and the board which was a concern it's about 6' I read max of I2c of 12' depending on speeds cabling and such.
Either way I will put an invert flag on the relay to simulate a GPIO active-LOW.
Thanks, should I flip IPOLA back to 0xFF?
Actually, I am experimenting with an LCT4311 that extends the i2c distance to 100+ feet at 400. I have it hooked up but I haven't run the wire for my pressure sensor yet. I did an active cooling scenario where there is a thermistor at the top (just above the voltage regulators) and a active cooling fan on the pi as well as venting out the box.
Thanks, should I flip IPOLA back to 0xFF?
It doesn't matter the register is only used when the pin is set to input.
Nice looking Setup! What size box is that? I see the relay Hat whats above that? https://sequentmicrosystems.com/shop/industrial-automation/raspberry-pi-industrial-automation/ I could use 3 relay boards and the above board for rs485. Are you using Pi 3b+ or a 4?
Thanks. It is a 16x16 Altelix box. I made the inner door myself from 3/8" ABS with C channel aluminum supports on the sides.
Yep that's a Sequent MEGA-IND. Primarily I am using it for power and RS485 but want to mess around with 4-20ma (not the pot kind) inputs and above that is an Atlas Scientific Tentacle. This has the pH, ORP, Pressure, and Temperature sensors attached. I am using a pi 4 there is a fan attached to the rail mount that pulls heat out of the stack and is attached to the DIN mount for the pi. This control is all done through an AC Infinity controller.
If you pull REM there is now the ability to invert the state and set a startup state. It will get you part way there but I suspect that for the biggies that run pumps and the like you will want to find a relay that is open when the power is off. We aren't talking about TTL stuff here with constant battery operation. It will certainly make it more robust if the relays are open.
Yes I agree, Sounds good but now how are the triggers written all I see is add a feature then it should follow the state?
But it doesn't follow the state of the relay so is an
IF
statement necessary?
Yes it knows how to resolve to true or false from the feature event. You only need one trigger in this case for true and false. Double check your feature id though. It should be the same as you find in the poolConfig.json. There is a lot of magic going on behind the scenes.
That Invert option means you do not have to mess with the binding.
The filters let you limit the events that affect the particular relay. In this case it is relay #1. The njspc connection will send a socket event whenever the feature state changes. This will be the documented event object from njspc.
So it will then apply filters to determine if the event is destined for relay #1 on the Main Control Relay Board. If the basic filters evaluate to true then the trigger will apply the state to relay #1. If they do not then it will ignore the event.
Oh and one more thing. If this is the first time subscribing to the event it does not initiate sockets until you Reset Server from the general tab. Unfortunately, the node socket interface requires quite a bit of work to kill a route.
Yes it knows how to resolve to true or false from the feature event.
It seems to only turn the relay OFF
if relay is On and feature is on then off when switched if relay is on and feature is off then switches relay off only
I know sounds confusing but will only switch relay off from njspc never turns relay on
There was a logic error with external sockets and inverted pins. Pull REM.
Ok I pulled it now exactly the same, I did notice changes on njspc so did a pull . Also no joy same behavior ugh... sorry for all this grief
Ok lets be sure. You have nothing in the binding tab for the trigger. Is that correct?
Pull REM I went through all the bindings and it appears that I missed the invert function for features. This should behave as it should.
This should behave as it should.
Yay! That must have been it works like it should now!
Yeah the invert thingy got a little more complicated since it needed to track 2 states. REM tries very hard to only act on rising and lowering edge. This will keep it responsive on minor hardware.
Almost! Set trigger as ID==17 to relay 1 and another Trigger ID==14 to relay 4
turn on 17 it blurps relay 1 but turns on relay 4 turn on 14 it is already on but now turns on relay 1
turn off 14 relay 4 turns off turn off 17 relay 1 turns off
if turn off 17 first relay 4 turns off yet 17 stays on until 14 is turned off If 17 is turned off it will turn off as long as 14 is on
confused yet? Sound like something you can figure out or more logs? Yes restarted Server disconnected Node Red.
Upload your controllerConfig.json from the data directory. I want to mimic all your triggers. The tough part of this is I don't have that chip. I should have just bought one and added it to the pile on the island of misfit boards.
controllerConfig.json.zip LOL yes chips and components wife thinks I have a store in my Lab
The crappy part is that you never seem to have the right diode, capacitor, or resistor. I'll mimic your setup to replicate this. I am sure it has something to do with the invert change. While I am at it I will remove the requirement to reset the server after making mods to the triggers.
I replicated your setup and found the issue. The binding was using the underlying address in one spot when it was initiating the triggers. This caused the trigger to use the wrong filtering function which made it send the incoming state to other relays. This has been fixed. Also, making changes to the triggers no longer requires you reset the server. This is now done automatically and MQTT topics are subscribed as well and the proper sockets are bound.
Pull REM.
Ok I pulled it and all working as expected. NICE! 😀
Also Like how I can now use Acid pump directly from REM Chem to a relay without needing to use a Feature
button or GPIO
Connected the heater and Solar through the Event Name
now to figure out how they work via Nixie
Thanks for all your hard and perserverance!
Did you figure out the heaters? This should fire a heater event whenever the heater should be on. The type will be heater or solar or you can set it up with the ids. How are you feeding water temp?
Did you figure out the heaters?
No
This should fire a heater event whenever the heater should be on.
? (I'm excited)
The type will be heater or solar or you can set it up with the ids. How are you feeding water temp?
I already read them via Dallas ds18b20 on the same pi onewire then send to njspc via mqtt
Hmmm... does the UI in dashPanel work to add a solar heater and a gas heater to the configuration?
Yes it does but I get an ID on both of -1
Boo. Shut down njspc and edit poolConfig.json and poolState.json to set the ids to 1 and 2. I will go in and fix this as we no longer need to worry about the ids for webClient.
Scratch that. Delete the heaters and make sure you select the Virtual checkbox for them. This should be automatic but it isn't right now.
Ok I see the check box and checked it now what? :) heaters not in frontend
They should show up in the body panel. And when the heat mode is for the specified heater and the temperature is < setpoint it should turn the heater on.
Ok I'm not crazy they are not there.
That is today I'm having a time date issue but not to concerned about that yet
Help setting up REM to complement Virtual Pump, and IC60. Ok my thoughts are to use this as my complete pool controller currently using nodejs-PoolController to operate the Pump and IC60 until a few days ago. Then I use an esp32 to control relays for actuators, heater, multiple pumps, blower, acid pump, Temperatures from 1 wire ds18b20, pressure from a transducer. Orp and PH from atlas. Just wondering what can be put into REM.