node red rookie questions

  • 2
  • Question
  • Updated 4 months ago
i am trying to understand how to use node-red to control a SainSmart
16-Channel 12V Relay Module using a Raspberry Pi over i2c. Using the following i2c interface:
Here is the Python code to make it work:
Controlling it with Python

When it comes to scripting languages, python’s really hard to beat.  It’s simple, quick, and you can do almost anything with “import some-module”.

In this case, I’ve made a class called “relay16” – it’s a really simple wrapper around the smbus calls needed to run the PCA9671 part on the I2C-RELAY16 board.   The example code is in the src/RasPi-Python subdirectory of the I2C-RELAY16’s Github project.

Let’s start with the very minimum amount you need to make this work:

#!/usr/bin/python
import smbus
import relay16
import time

bus = smbus.SMBus(1)
address = 0x20

relayBoard = relay16.relay16(bus, address)
relayBoard.setRelay(1)
time.sleep(1)
relayBoard.clearRelay(1)




Photo of joe camilli

joe camilli

  • 27 Posts
  • 1 Reply Like

Posted 4 months ago

  • 2
Photo of Dave Garber

Dave Garber

  • 29 Posts
  • 1 Reply Like
is this Flex related??  not understanding
Photo of joe camilli

joe camilli

  • 27 Posts
  • 1 Reply Like
Yes the relay switch will be used for my 2x6 matrix antenna switch for use on my 6600
Photo of Nick RN3KK

Nick RN3KK

  • 31 Posts
  • 3 Reply Likes
https://github.com/rn3kk/RemoteSwitcher
16 reLay, web server. All done.
Photo of W7NIK

W7NIK

  • 51 Posts
  • 4 Reply Likes
SainSmart boards are Junk , 2 returned. Fyi
Photo of Steve Sterling

Steve Sterling

  • 38 Posts
  • 14 Reply Likes
Thanks for the link. Appreciated.
Photo of Joe N3HEE

Joe N3HEE

  • 546 Posts
  • 122 Reply Likes
Joe, you can find more Node Red info and help in the Node Red Thread located here. 

https://community.flexradio.com/flexradio/topics/remote-operating-and-node-red

I am using an 8 channel SainSmart relay to control my Six Pak antenna switch.  It is connected directly to my Flex 6600M via usb cable.  I've had no issues with my relay board.  Works great ! 

Joe
N3HEE
Photo of Michael Walker

Michael Walker, Employee

  • 1252 Posts
  • 373 Reply Likes
We have been supporting Node-Red integration for projects just like this for remote station operation.  There is an entire thread regarding it as other have posted.

Bob, while I appreciate you are trying to be funny, please take a movement and delete your recipe.  

Mike 
Photo of Michael Walker

Michael Walker, Employee

  • 1252 Posts
  • 373 Reply Likes
Joe

What I would do first is to get this working outside of Node-Red with your python scripts.  Once you have that part playing well, you should then be able to call the script from within Node-Red with the ‘exec’ I think.

I don’t have one to test with, so I can’t help you out much unless I order the board to play with.   My i2c experience is pretty limited to I hook it up and pray it works. :). That being said, I do have 6 temperature gauges on i2c on my Flex 6000 remote control interface.  

We do have lots of customers using SainSmart devices directly connected to the 6000 series radios with wonderful success.   Others can comment if they have some experience.

Mike


Photo of joe camilli

joe camilli

  • 27 Posts
  • 1 Reply Like
Michael,

thanks for the feedback. yes i have the relay working just fine using a python program. The use of i2c in way easier than GPIO.

Joe N7QPP
Photo of Michael Walker

Michael Walker, Employee

  • 1246 Posts
  • 365 Reply Likes
Have you now also got Node-Red able to control it by calling your python script?

As for easier, etc.  I guess it it based on your comfort level. 

All my Relays are TCP connected to external to the RPI.  That way, if I need to reboot the RPI, the relays don't toggle and shutdown other things in the process.  

Mike
(Edited)
Photo of W7NIK

W7NIK

  • 43 Posts
  • 4 Reply Likes
I use FOX delta RUSS board and KMtronics, does  not cycle of relays, I have couple connected to the ALS1300 amp , power on and another relay for operate/standby ,  the sainsmart  boards cycle,  the two  work sometimes then it would disappear, restart the computer, work couple more times then it  will lock the relay on .