Relay Hat Question - I2C - Printable Version +- SIP (https://nosack.com/sipforum) +-- Forum: SIP (Sustainable Irrigation Platform) (https://nosack.com/sipforum/forumdisplay.php?fid=1) +--- Forum: Installation and set up questions (https://nosack.com/sipforum/forumdisplay.php?fid=2) +--- Thread: Relay Hat Question - I2C (/showthread.php?tid=54) Pages:
1
2
|
Relay Hat Question - I2C - mg360 - 2016 Sep 08 Hi, First up - huge thanks, great project, awesome software. I have been hacking away at this and got the system setup using the relay_board plugiin to a relay that I had wired up myself. I think I did something wrong and fried a Raspberry pi. Wiht a new Raspberry Pi and the SD card from the previous Pi I was up running but this time with a 4 channel relay hat that uses I2C. With Python code provided by the relay hat I can control the relays. What I cannot do now is get this software to toggle the relay. I have tried with the relay plugin and without but regrettably I am just not sure about what I am doing. Couple of question that might point me in the right direction: 1. With a relay hat and this software is the communication via I2C (is this even a properly formed question) 2. Is there something I can change in the code that might make this work? This is the relay hat that I have: http://wiki.seeedstudio.com/wiki/Raspberry_Pi_Relay_Board_v1.0 The software on the page above is working correctly on my device. Any help is much appreciated. RE: Relay Hat Question - I2C - dan - 2016 Sep 09 This is something I have not seen before. Looks interesting but only supports 4 stations. I guess you could stack a couple of them to get more stations. It is using I2c for communication with the Raspi. Therefor it will not work with the existing relay_board plugin. It would take a new plugin to be able to use the relay hat. If more than one hat is used there would need to be something in the code to handle multiple I2c addresses. It is possible but not currently implemented. Dan RE: Relay Hat Question - I2C - mg360 - 2016 Sep 09 Hi Dan, Thanks very much for getting back to me. Looks like I might want to get something a little more compatible. RE: Relay Hat Question - I2C - schmooot - 2019 Oct 10 I am also hoping to use a similar setup and was wondering how to do the same thing. Its a 4-chnnel add-on board for the pi that uses I2C. And its stackable up to four boards making a total of 16 different channels available. Would love to get it to work with this system. I've created very basic small python programs to turn on or off each channel of my boards. ch1on.py. ch1off.py, etc etc. I feel like an easy solution for me would be to modify something in the SIP platform to actually run my "on" program at its designated 'on interval' and execute the "off" program at its designated 'off interval' for each respective channel? I just don't know how to do that RE: Relay Hat Question - I2C - dan - 2019 Oct 11 It may be possible. Could you post an example of your Python code? So far SIP can interface with shift registers and to relays connected directly to the Pi's GPIO pins but an I2C interface should be doable. I will need to look into it. Dan RE: Relay Hat Question - I2C - schmooot - 2019 Oct 11 For sure. This is from the writeup I found for the specific HAT system I have. http://wiki.52pi.com/index.php?title=DockerPi_4_Channel_Relay_SKU:_EP-0099&oldid=5501 I can do a direct control from a terminal with this Ch1 relay ON <code>i2cset -y 1 0x10 0x01 0xFF </code> CH1 relay OFF <code>i2cset -y 1 0x10 0x01 0x00</code> Or by running my .py file My ch1on.py looks like this: <code> import time as t import smbus import sys DEVICE_BUS = 1 DEVICE_ADDR = 0x10 bus = smbus.SMBus(DEVICE_BUS) bus.write_byte_data(DEVICE_ADDR, 1, 0xFF) sys.exit() </code> My ch1off.py file looks like this: <code> import time as t import smbus import sys DEVICE_BUS = 1 DEVICE_ADDR = 0x10 bus = smbus.SMBus(DEVICE_BUS) bus.write_byte_data(DEVICE_ADDR, 1, 0x00) sys.exit() </code> My original design is using this style in a cron job as an alarm and it has worked just fine. (except I have alarm1, alarm2, etc) But my next project is a 16 channel sprinkler system and I wanted a user interface for it as its for my neighbor and he needs to be able to modify the times himself. This seemed like a great solution as long as I can get the program to actuate my relays RE: Relay Hat Question - I2C - dan - 2019 Oct 11 Thanks for the code. It looks like there a couple of ways to go. 1) Make a SIP plugin to handle I2C with various address configurations. That could take a while since I am working to upgrade SIP to run on both Python 2.7 and Python 3. Python 2x will no longer be supported after the end of 2019. 2) There is an existing plugin named "cli_control" which sends a command on the command line when SIP turns a station on or off. Take a look at that plugin. It should be usable as is. EDIT: removed suggestion to test Python3 version of SIP. It is working but there are complications when switching between SIP versions. If you tried it and got a "pickle.loads(pickled) EOFError" just delete the contents of SIP/sessions/. Let me know how it goes. Dan RE: Relay Hat Question - I2C - schmooot - 2019 Oct 15 Thanks for that. cli_control seems like the most economical solution I'm having issues with it though. I tried telling it to run the i2cset command and also tried running just my .py program. (both of which currently activate my relay board from a separate command line window...I double checked that) SIP will run it through with no errors but nothing happens on my board. I assumed it would run a direct command line on my local machine? or do I need to set another parameter to tell it where to run? (note: I am interfacing directly from my pi, and using the web browser to access SIP) Or do I have something wrong with the SIP setup initially perhaps? RE: Relay Hat Question - I2C - dan - 2019 Oct 15 The i2cset commands should be the way to go. SIP must be restarted after adding the commands. That may require a slight tweak of the plugin but you can do it manually for now. How are you running SIP? Is it setup to start at boot-up and run in the background or are you launching it from the command line? That could make a difference. I will try to do some testing but I'm not sure if I have an I2C device to test with. I am sure we can get it working but I will be offline for a couple of days. I will let you know as soon as I have a chance to do some testing. Dan RE: Relay Hat Question - I2C - schmooot - 2019 Oct 15 I'm launching it from the command line right now. I'll try starting it at boot Works now. Time to play around with it. Thanks |