Numato USB relay

Hi everybody :blush:

I have bought a Numato Lab 16ch USB relay
Link: Numato 16ch USB relay

The setup should be fairly simple, but I seem to be missing something, so I hope you can help me :see_no_evil:

Link to relay connections: relay connections

First the basics:
The relay is connected to Raspberry with a USB cable of course
Jumper is set between 1 & 2 (External power) + 5v connected (polarity checked)
It is the model with 24v coil voltage so 24v connected (polarity checked)

On the code side:
I’ve made a module called Relay with a Method called RelayControl

Here the code in RelayControl:

Dim s As New SerialConnection
If s = Nil Then Return

s.Baud = Serial.Baud9600
s.Bits = Serial.Bits8
s.Parity = SerialConnection.Parities.None
s.StopBit = SerialConnection.StopBits.One
s.XON = False
s.CTS = False
s.DTR = False

Try
s.Device = SerialDevice.At(1)
s.Connect
//MessageBox(“The serial connection is open.”)
Catch error As IOException
MessageBox(“The serial connection could Not be opened.”)
Return
End Try

Dim outString As String = "relay "
Dim nextString As String

Select Case relayNumber
Case 1
If state Then
nextString = “on 0”
Else
nextString = “off 0”
End If
Case 2
If state Then
nextString = “on 1”
Else
nextString = “off 1”
End If
Case 3
If state Then
nextString = “on 2”
Else
nextString = “off 2”
End If
End Select

dim finalString As String

finalString = outString + nextString

//MessageBox(finalString)

s.Write (finalString)

s.XmitWait

s.Close

Then I made a simple button with the following code to test it:

RelayControl(1, true)

But I get absolutely no response so hope you can help me in the right direction?
Here the documentation: https://numato.com/docs/16-channel-usb-relay-module/

Thanks in advance :relaxed:

The first thing I always do with new serial devices is try connecting to them via a simple Terminal application and running a few commands manually, just to make sure things work in the most basic sense. I use Roger’s CoolTerm.

1 Like

I have confirmed connection to it so that shouldn’t be the issue :slight_smile:

?

And can you manually write a value to the device, say “relay on 0”? Often times it’s a matter of sending the correct terminating character on the end. Have you tried adding chr(10) or chr(13) (or both)?

When you say you get absolutely no response, what does that mean? No serial output or the relay does not click, or? Have you just tried querying the module for its firmware version or the relay’s status per the docs?

Send a picture of your wiring, there are headers that need to be set and power that needs to be supplied to board.

Also, this is confusing. Are you sure you are checking the correct relay? If the relays are “0” based, I’d simplify your code to match. I.e. passing 0 turns relay 0 on/off, etc.

shouldn’t… You need to test the device with a serial terminal app.

Maybe it is better to add the SerialConnection as a control in your window?

Hi William
I have tested the relay using putty and have it responding and reporting back version etc. so my problem is with setting everything up right in Xojo :slight_smile:

Hi Jean
Yes that was the 16ch Sainsmart relay, which got up and running but now I’m trying to get the Numato lab relay up and running.

Would you be able to paste the string you sent with Putty here? (and any response you may have gotten too). I’d be eager to see the terminating characters and entire request string :slight_smile:

Hi William
That was the missing link :smiley:
I got it working now by changing s.write to: chr(13)+(finalstring)+chr(13)

For some reason it must get chr(13) in front and after the command to work properly
Out of curiousity, do anyone know why that is?

I’d double check to see if the leading chr(13) you are adding isn’t just merely committing the previous command. Many serial commands end with a CR or CR+LF, but rarely do they start with one. Glad you’re making progress!

I have tested that it doesn’t just duplicate previous command and it doesn’t.
but I found my last little bug :innocent:

I was adding to the end “chr(13)” instead of chr(13) so it parsed the text instead of the command if that makes sense.

now it is working with:
Dim outString As String = "relay "
Dim nextString As String
Dim endString As String = Chr(13)

Next string being for example: nextString = “on 0”

finalString = outString + nextString + endString
s.Write (finalString)