Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
USB relay card via shell command in qb64
#1
First a lot of info:

On my PC's I use Linux Mint xx (latest versions) with xfce4 as desktop.
"Mint" is "Debian" and "Ubuntu"
In this installation I the "Ubuntu" installation.
I have no idea how this works in Windows or on the Mac.

I used info from this link:
https://github.com/darrylb123/usbrelay/b.../README.md

This is also a module-supplier who gives a lot of info and links:
https://www.phippselectronics.com/suppor...gritHpGk3v
Possible You found here also info of hints for other operating systems
If anyone found installation-info for Windows or Mac, please announce it on this forum.

Why? I'm now searching for an USB card system to measure temperature via PTC or ds18B20 sensors.
Thereafter, together with this relays system, I can use identical the same QB64 listing on a PC and on a Raspberry.

How I did it:

I followd the instructions in the Read.me file in the above first github link:

I did the ubuntu installation.
Thereafter the instructions to avoid/eliminate the "sudo" in Your terminal commands or in the QB64PE _shellhide instruction.
You can test it out in a terminal window: "
First: Don't forget to Plug in the relay-card on a USB port!
If the use of sudo is not eliminated You need to give in: sudo usbrelay --usage
After elimination of sudo You only need to give the command: usbrelay --usage

Search the ID number of Your USB relaycard:
In a terminal window give the command: usbrelay  (Hint: Test out all info in a terminal via "usbrelay --help")
For a 4 relay-card You read something in the terminal something like:
QAAMZ_1=1
QAAMZ_2=1
QAAMZ_3=1
QAAMZ_4=1

Important:
QAAMZ is the ID of my USB-relay-card, each relay-module has is own ID number!!!
So You can use many cards on the same PC.
The numbers 1 2 3 and 4 are the four relays on a 4-relaycard (or 1 to 8 ir You use an 8 relaycard...)
(The last number is the status of the relay)

OK, possible a little bit of work, but... once OK, Your QB64 program became very simple.

And now the simple QB64 listing to use the relays:

Code: (Select All)
OPTION _EXPLICIT

' Heater elements, motors, pomp... I give them all a "CONST" number in place of a relaynumber
' CONST BIGHEATER = 1, SMALLHEATER = 2, WATERCOOKER = 3, PUMP = 4
CONST R_ON = 1, R_Off = 2, All_OFF = 9

DIM SHARED Driver_RelaysName$
Driver_RelaysName$ = "usbrelay QAAMZ"
'Each relaymodule has his own ID, in my case "QAAMZ"
'===================================================
'Linux: Connect the relay-card via a usb-port. Open a terminal and type: usbrelay to find the ID of Your card.
'So if You need to replace a module You only need to change this ID-info

DIM x%
'CALL Relay(2, R_ON)
FOR x% = 1 TO 4
  ' All relays ON
  CALL SwitchRelay(x%, R_ON)
NEXT x%
SLEEP

CALL SwitchAllRelaysOff 'All relays OFF

END

'================================================
SUB SwitchRelay (RelayNr%, OnOff%)
  'Switch one Relais ON of OFF on usb-relay-module, or all relays OFF

  DIM FullAssignment$
  FullAssignment$ = Driver_RelaysName$ + "_" + LTRIM$(STR$(RelayNr%)) + "=" + LTRIM$(STR$(OnOff%))
  SHELL _HIDE FullAssignment$

END SUB 'SwitchRelay ON OFF------


'=================================
SUB SwitchAllRelaysOff ()
  'Purpose: Switch OFF all Heaterelements, valve(s), pump(s)...
  ('The job can also be done with the first sub... )
  'Practical for an emergency-stop or at the end of a program.
  DIM FullAssignment$
  'The driver use relais nr 9 (nine) to switch OFF all relais
  FullAssignment$ = Driver_RelaysName$ + "_9=0"
  SHELL _HIDE FullAssignment$
END SUB '-------------------------


Rem.: To put ON OFF a big heater elements, after the mechanical relais I put a big SSR relays (380V 40A) mounted on a  Aluminum Heat Sink.

Rudy M
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  real 2-4 player Pong (requires 2-4 USB mice plugged into your PC) madscijr 1 736 06-26-2024, 01:09 PM
Last Post: madscijr
  Access GPIO pins on Raspberry via QB64 Shell command and raspi-gpio utility Rudy M 1 751 06-25-2024, 02:18 PM
Last Post: a740g
  read 2 or more USB mice on one PC - fully working with keyboard input madscijr 2 1,097 06-16-2024, 01:48 AM
Last Post: madscijr
  Simple Menubar Shell Keybone 0 452 12-31-2022, 03:46 AM
Last Post: Keybone

Forum Jump:


Users browsing this thread: 1 Guest(s)