Review of a nice 8 ...
 
Notifications
Clear all

Review of a nice 8 channel i2c solid state relay board available  

Page 2 / 2
  RSS

tico
 tico
(@tico)
Trusted Member
Joined: 4 months ago
Posts: 68
August 3, 2020 2:57 pm  

@kylegabriel So it's been one crazy week after another and my few bits of spare time trying to get up to speed on python itself, and troubleshooting my attempts to make a python module for mycodo haven't gone as well and as quickly as I'd hoped, so I'm sticking with the bash scripts for the time being since I've got to be able to use the board now. I've gotten a bit mixed up with the scope of some of the objects in the output module, but have managed to make this code importable by Mycodo, however it fails when I try to configure the initial settings.

I've looked at the initialization for the sht21, sht31, bme280/680 inputs, and all of the output modules, and i'm not sure what all code should go into the initialization function versus the setup function?

Anyhow, I'll take a crack at it later if I can get some more free time. I appreciate your example code -- I was able to make it run as a standalone python script, but I can't get it integrated into Mycodo yet.

On another note, I'm currently working on getting the MCP23008 and also MCP23017 GPIO chips to work as relay driver boards, and it looks like they have the same issue as the PCF8574 GPIO chip -- namely, that if a pin is set to an output, then attempts to read the state of the pin will not work correctly.

I'm also looking at adding support for the DS2408 1-wire 8-channel IO expander chip in order to hopefully have better luck driving relays at further distances from the Pi without as much interference issues with the i2c bus (and having to use i2c differential extenders, etc). It *looks* to me from reading the datasheet that this DS2408 *can* have an output pin enabled/disabled and then subsequently read the state of that pin from a separate register on the 1-wire address, however I haven't received mine yet and can't confirm that.

If it turns out that a number of IO expander chips used/usable for relay driver boards must have all relay states written to them each time that one desires to change the state of a single relay channel, would it make more sense to try to create a "Relay Group" output object type in Mycodo, that enumerates a series of channels within it, similarly to how many of the input sensors previously discussed also have multiple channels within the same sensor object for reading temperature/humidity/pressure/etc ?


ReplyQuote
tico
 tico
(@tico)
Trusted Member
Joined: 4 months ago
Posts: 68
August 3, 2020 2:58 pm  

forum sw didn't like the attachment having a .py extension.


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 302
August 6, 2020 7:17 pm  

I looked through your module and it looks good, but I haven't tried to debug it. It does have a lot of unnecessary code. Here's the Output module I came up with, which is a minimal example. Let me know how it works.

Mycodo Developer


ReplyQuote
tico
 tico
(@tico)
Trusted Member
Joined: 4 months ago
Posts: 68
August 9, 2020 9:43 am  

Hi! Yeah, I know there was a ton of cruft in my code -- I need to get better at / more familiar with python and the mycodo framework -- thanks for looking at it.

 

I just got a few moments to take my system offline and try out your code and I noticed a few problems:

I connect the Krida 8channel relay board to a spare Pi, and initially all output channels are on.

After importing your pcf8574.py code into Mycodo I setup a PCF output for channel 1, (set with logic state high to trigger), i hit activate, and all relays turn off except for channel 8 (not 1).

I turn it off, and all channels are now off. I assume that there's just a numbering swap from little-endian to big-endian or something like that.

I turn output for channel 1 back on again, and the relay channel 8 is reenabled.

 

Then, i create another another PCF output for channel 8 in Mycodo, (also set with logic state high to trigger), I hit activate, and all relays turn off except it turns on relay channel 1. Ok, so I've confirmed that channel 1 in Mycodo = relay channel 8, and vice versa.

Then now that enabling mycodo channel 8 (relay 1) has also undesirably turned off mycodo channel 1 (relay 8), I try clicking the but to turn mycodo channel 1 on again, but I get the message that that output is already on, and on the relay board no state changes.

If I then deactivate mycodo channel 1 and then reactivate it, then it is successful and reenables relay channel 8 as expected, however it also deactivates the other relay channels.

Aside from the mycodo channel  != relay channel issue, it looks like your code isn't saving the state of the other channels, and isn't able to read  that state from the chip either, as expected based on the earlier testing.

I have to run  for now, but in the meantime, I've confirmed that the other chips I'm working on (MCP23008 and MCP23017) *do* allow you set a pin as an output, set a pin state, and then read that pin state back even though it's configured as an output:

for the mcp23017 --

# set all pins on bank A as outputs

 i2cset -y 19 0x20 0x0 0x00

#set all pins on bank B as outputs
 i2cset -y 19 0x20 0x1 0x00

i2cset -y 19 0x20 0x12 0x41  # enable pins 6 and 1 (and disable all others on bank A, but not on bank B)

i2cget -y 19 0x20 0x12 # read state of all pins on bank A:

0x41


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 302
August 12, 2020 1:32 pm  

When you have a chance, take a look at https://github.com/kizniche/Mycodo/issues/813 and let me know if you would like to help me develop and test this feature. I don't have any of the chips you mention, so at your advisement, I will purchase some for testing. Let me know your thoughts.

Mycodo Developer


ReplyQuote
tico
 tico
(@tico)
Trusted Member
Joined: 4 months ago
Posts: 68
August 12, 2020 1:47 pm  

Just read it -- that's awesome! Yeah, I'd be happy to, although as you've already seen I'm still a bit rough on coding modules for mycodo specifically and in python in general, but hopefully I'll get better soon. I'm actually about to finish cleaning up another set of bash scripts for controlling the MCP23017 and 23008 and get them presentable enough to share with the forum.

In my searching I saw that there's also a PCF8575 (16channel) version which seems worth investigating.

For those users who aren't great with surface-mount soldering or have access to a reflow oven, it's nice to note that both of the MCP chips are available in DIP format, and the pinout order pairs up perfectly with the ULN2803a Darlington array chips in order to drive 5/12/24V relay coils or any of the ubiquitous counterfeit Fotek-clone SSRs all over the market that often draw more than 20mA to enable and also often don't enable with less than 5 or 6V despite claiming only 3V to be necessary.

What can I do to help?


ReplyQuote
tico
 tico
(@tico)
Trusted Member
Joined: 4 months ago
Posts: 68
August 12, 2020 1:58 pm  

Forgot to add, if you want a pre-built board with the PCF8574, I really gotta say I'm happy with the build quality of the Krida board I introduced in the original posting, and if you want to clarify anything with the creator of it I'd be happy to assist in translation though he does read/write English pretty well.

If I were to suggest any purchases aside from that,  I would get one MCP23008, one MCP23017, and 3 ULN2803a's in order to drive the 8+16 outputs (the ULN2803a also includes a freewheeling diode on the output, though if you're trying to directly drive a motor or something at its max of 50VDC it might be wise to add an additional external diode to snub the input). On Amazon I got 10 ULN2803's for $8

Also, not a bad idea to have a spare +5 or +12V power supply to drive the ULN2803 and output coils, since the Pi is a bit anemic at supplying power, and to provide some isolation.

Lastly, I'm using some clones of the sainsmart 8-channel relay boards (both SSR and mechanical) and they've worked well on the +5V output, but not on 3V3. Same with the various Fotek/TWTADE/AOSH/etc 25 and 40 amp SSRs.


ReplyQuote
Page 2 / 2