dkwsloth1
Posts: 4
Joined: Thu Mar 08, 2018 2:04 am

Using a relay, with USB and not GPIO

Thu Apr 05, 2018 11:03 pm

Hello all,
I am a 100% newbie.
I am looking to use a simple control to trigger an action. I have some code used for GPIO, however I would like to connect to my relay using the USB port instead of the pins. can someone please help to modify the code to talk to the USB port, instead of using the pins.

Is there an easy way tell the Pi, to do the GPIO operation using the USB?
THANKS,


here is the current code:

import web, requests
import RPi.GPIO as GPIO
import time
urls = ('/advance/(.*)/(.*)', 'advance')
app = web.application(urls, globals())
class advance:

def GET(self, digi_cam_ip, loops):
for loop in range(0, int(loops)):
# specify how the pins are referred to
GPIO.setmode(GPIO.BOARD)

# pin the relay is connected to on the Raspberry Pi
pin = 2

# activate the relay for 0.25 seconds, then release
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
time.sleep(0.25)
GPIO.output(pin, GPIO.HIGH)

GPIO.cleanup()
# wait for the projector to advance the slide
time.sleep(0.5)

# take the picture by calling DigiCam's webservice
requests.post("http://" + digi_cam_ip + ":5513/?CMD=Capture")

# wait for the image to transfer from the camera to the computer
time.sleep(2)

return "Finished"
if _name_ == "__main__":
app.run()

klricks
Posts: 7172
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Using a relay, with USB and not GPIO

Fri Apr 06, 2018 2:11 am

dkwsloth1 wrote:
Thu Apr 05, 2018 11:03 pm
Hello all,
I am a 100% newbie.
I am looking to use a simple control to trigger an action. I have some code used for GPIO, however I would like to connect to my relay using the USB port instead of the pins. can someone please help to modify the code to talk to the USB port, instead of using the pins.

Is there an easy way tell the Pi, to do the GPIO operation using the USB?
THANKS,
You will need to get documentation and programming examples from the seller / manufacture of your addon USB controlled relay board or USB IO board.
Post a link to your board.

When you post code please use the code tags button [</>] so that your code looks like this:

Code: Select all

 import web, requests
 import RPi.GPIO as GPIO
 import time
 urls = ('/advance/(.*)/(.*)', 'advance')
 app = web.application(urls, globals())
 class advance:

 def GET(self, digi_cam_ip, loops):
 for loop in range(0, int(loops)):
 # specify how the pins are referred to
 GPIO.setmode(GPIO.BOARD)

 # pin the relay is connected to on the Raspberry Pi
 pin = 2

 # activate the relay for 0.25 seconds, then release
 GPIO.setup(pin, GPIO.OUT)
 GPIO.output(pin, GPIO.LOW)
 time.sleep(0.25)
 GPIO.output(pin, GPIO.HIGH)

 GPIO.cleanup()
 # wait for the projector to advance the slide
 time.sleep(0.5)

 # take the picture by calling DigiCam's webservice
 requests.post("http://" + digi_cam_ip + ":5513/?CMD=Capture")

 # wait for the image to transfer from the camera to the computer
 time.sleep(2)

 return "Finished"
 if _name_ == "__main__":
 app.run()

Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Return to “General discussion”