I2C io interface - Printable Version +- SIP (https://nosack.com/sipforum) +-- Forum: SIP (Sustainable Irrigation Platform) (https://nosack.com/sipforum/forumdisplay.php?fid=1) +--- Forum: Feature requests (https://nosack.com/sipforum/forumdisplay.php?fid=4) +--- Thread: I2C io interface (/showthread.php?tid=252) |
I2C io interface - astrogerard - 2021 Aug 12 Hi Dan, You might have seen the "shift register" discussion. I had some thoughts about the level of knowledge one needs to succesfully and reliably build this. For me no problem but I'm not so sure about the larger audience. In my setup I directly connect the relayboard to the Pi. Although the Pi has some IO pins and in most setups it works fine I'm still not happy with it. Therefore I want to make a seperate interface between the Pi and the relay board(s). First I wanted to make/develop a pcb with shift registers but now I'm going to focus on I2C. I'm going to use a (or more) PFC8574 IC's or modules. There are ready to use modules for less than $2 and these modules can be daisy chained effectively having 64 channels/valves to use. Long intro but I want to know if you have any design considerations on this. From python it is only a few lines of code and I'm not sure if a plugin or just a commandline call is the best approach. Do you have any thoughts on this? Is it worth to create a plugin for this or will I be the only user and is an commandline call a better/easier choice? --Gerard RE: I2C io interface - dan - 2021 Aug 12 Hi Gerard, That sounds interesting. I would be interested in more information such as a link to a source of the board you are using. How would you use it from the command line? If it is easy to use and can support many stations I think there would be considerable interest from the user community. Dan RE: I2C io interface - astrogerard - 2021 Aug 13 Hi Dan, At the moment I'm testing with a boardless IC. It is the PCF8574 which officially is called "Remote 8-bit I/O expander for I2C" The datasheet you can find here. Also this wiki gives some usefull info There are many boards based on this chip. The most famous board is the one for 2x16LCD displays. Also a lot of IO boards are available for almost nothing from Asia. The one I showed is likely the most useful because it can be daisy chained to the next board without soldering. Also the I2C adres can be manually set via jumpers. The PCF8574 can have 8 different adresses (0x20..0x27) so one could connect 8 boards together. 8 boards x 8 I/O pins gives a potential of 64 channels to adress. The testing I did both from the command line and from a minimal python script. From the command line you can set (or get) a port with i2cset, like "i2cset -y 1 0x27 0x08" where 1 is the smbus id (usually 1), 0x27 is the I2c adress (module with no jumpers) and 0x08 is pin 4 of the PCF8574. The pins is a bitmask so to set pin 3 (0x04) and 8 (0x80) you send 0x84. From python it is also really easy. To set pin 4 like the example above the minimal code is: Code: import smbus I think this could be a useful addition to SIP so a plugin might be the best approach. The internals of SIP are not always clear to me but I can give it a try to write a plugin. If I'm correct the plugin should listen to a signal when to do its thing. Correct? Hopefully this gives you some info to "judge" my thoughts. --Gerard RE: I2C io interface - dan - 2021 Aug 13 Gerard, Thank you for the details. Your idea looks very promising. I will see about getting a couple of boards for testing. It may be possible to use the cli_control plugin with this. It can send a command line command when SIP switches a station on or off. Or at least it could be a starting point for developing a new plugin. Dan RE: I2C io interface - astrogerard - 2021 Aug 14 Hi Dan, Controlling the modules/ic's from python is very easy so most of the time I have to spend on the plugin. Just to be sure (since this is my first plugin) I want to know if it is correct that I have to create within the plugin a callback function attached to signal(u"zone_change"). Also I would like to know if the callback function is called once or multiple times in case there are more stations to address. So when one station is activated and a master valve is defined, is the function called once or twice? --Gerard RE: I2C io interface - dan - 2021 Aug 14 The signal(u"zone_change") returns a list of all stations. The stations that are on are indicated by 1 those that are off are indicated by 0. The callback just needs to parse the returned list to determine which stations to turn on or off. Dan RE: I2C io interface - astrogerard - 2021 Aug 14 I just slightly modified the signaling_examples plugin the generate some extra info. It is clear now. Also I've seen multiple "zone_change" calls but these are expected since there can be a delay between the master and station. So the only thing to do is counting the number of boards (gv nbrd) and assign a i2c address in the config. Then, during runtime use the address for every 8 channels which is one board. Doesn't seem too difficult, but I know the devil is in the details. :-) --Gerard RE: I2C io interface - dan - 2021 Aug 18 Gerard, I received the I2C boards a couple of days ago. Today I had a chance to hook one of them up to the pi and an 8 channel relay board. It was easy to get it working using an external power supply for the relay board. I made a quick modification of the cli_control plugin to use I2C. I posted it as a gist on GitHub. You can download it from: https://gist.github.com/Dan-in-CA/98440df0975c5a8883aecc0c7723a8d4 Let me know what you think. Dan RE: I2C io interface - astrogerard - 2021 Aug 19 Hi Dan, Good to see you get it working too. My plugin in a basic version works. I can configure multiple boards based on the number of boards defined in nbrd: For now my plugin is based on the pcf8574 wich has 8 channels but I've seen also boards based on the pcf8575 which has 16 channels. I'm changing my design a little bit to support the pcf8785 as well. I'm a bit new to web.py and am (steep) learning the interaction between the (template) html and the code. Therefore it will take some time to "present" a beta version of my plugin. The good news however is that it already works :-) Also I'm investigating the power requirements when connecting the maximum number of boards in relation to connecting to the Pi. Potential issues are connecting to 5v or 3.3v. 5v from the Pi can easilly drive all 64 (or 128) optocouplers but has a potential issue when connecting sda and scl from a 5v device to the 3.3v Pi. Safer is to connect to 3.3v but the Pi will struggle with powering all the optocouplers. I'm now thinking of a safe solution somwhere in between. A hardware prototype is on my bench now connected to the scope so some measurements should give the right answers. So, a lot is done and has to be done. I will continue with both the plugin and hardware and will give updates here. I might need some assistance with web.py and the interaction between the html template but I will give a "shout out" when needed. --Gerard RE: I2C io interface - astrogerard - 2021 Aug 23 Hi Dan, can you help me with a small design question? As you might have seen in the screenshot of the plugin I want to add some tools to my page. These tools will include i2c bus scanning and i2b io port testing. Since I'm a newbie on web.py (and you are the opposite ) what is the best thing to do. Make a separate page for the i2c tooling or include this in the main plugin page? I'm new to the parameter/variables interaction between the code and templates so I don't want to make "wrong" design choices.... if there are any. Thanks, Gerard |