I have Raspberry Pi B+ and i just bought 8 channel relay. i successfully connected but i really need a simple code to run it to trun on and off the channel relay?
would you please help me
I have Raspberry Pi B+ and i just bought 8 channel relay. i successfully connected but i really need a simple code to run it to trun on and off the channel relay?
would you please help me
Do you have any sample code that you've tried so far?
What make/model is the board?
Simsim,
#!/usr/bin/python import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) # init list with pin numbers pinList = [17, 23] # loop through pins and set mode and state to 'low' for i in pinList: GPIO.setup(i, GPIO.OUT) GPIO.output(i, GPIO.HIGH) # time to sleep between operations in the main loop SleepTimeL = 2 # main loop try: GPIO.output(17, GPIO.LOW) print "ONE" time.sleep(SleepTimeL); GPIO.output(23, GPIO.LOW) print "TWO" time.sleep(SleepTimeL); GPIO.cleanup() print "Good bye!" # End program cleanly with keyboard except KeyboardInterrupt: print " Quit" # Reset GPIO settings GPIO.cleanup()
This code assumes two relays are used and wired to BCM pin 17 and 23. If you wire differently, change pinlist and the two output as well.
Clem
Dear: Simsim
You should know that it is fairly simple using GPIO. As a matter of a fact I used GPIO to make an LED blink Morse code. You should know the code is simple. Try this in python.
import RPi.GPIO as GPIO import time
You should know that this basically imports GPIO and time so we can use the GPIO board and use time to control the amount of GPIO we use but it does not do anything else. Try this to turn on the board.
GPIO.setmode(GPIO.BOARD)
This will turn on the board try this to create an output.
number = 37 GPIO.setup(number,GPIO.OUT) GPIO.output(number,True)
Of course there are many ways to create an output but this is the easiest for me anyways. What the the code does is turns on GPIO 26 to ouput high. to create an input do this.
GPIO.setup(GPIO.BCM) number = 37 GPIO.setup(number, GPIO.IN) GPIO.input(number, True)
To create a bidrectional (or IO) I don't know. I am sorry but I can't answer that. Next you will need to look at this diagram to help you with your code. Also you should know to look for the diagram relavent to your raspberry pi.
Good luck and bye..
From: Noah
PS in case you are wondering the pinout above is for B+ the pinout below is for A.
My favorite reference for RasPi GPIO hardware and programming is the RasPi Hardware Wiki: http://elinux.org/RPi_Low-level_peripherals
It has programming examples in various languages, including Python: http://elinux.org/RPi_Low-level_peripherals#Python
The Wiki indicates that you need to "sudo" in order to access the GPIOs. Most of the examples require "sudo" in some form because the /dev/mem device driver normally requires that you run as root. For more information on this, see the Wiki and the element14 discussion: http://www.element14.com/community/message/60894/l/anyone-know-how-to-access-raspi-gpio-without-sudo#60894
HI Noah
I was just looking at this post as I am looking for assistance with getting a PI A+ board to run 4 Relays with multiple programs held on the SD Card on the PI board.
As well as a web page hosted on the board to access via the wifi dongle directly via iPone or Android to run the programs at the push of a button.
Can you possibly help or be able to point me in the right direction.
Craig