Relay integration
#1
Any leads how to integrate Pine64 with a relay switch, to turn things on and off from a script ? Linux version is fine, no Android required. 
I would need both wiring diagrams and software, any leads appreciated.
Looking to automate a thing in garage.
  Reply
#2
(08-15-2016, 06:08 PM)vigor Wrote: Any leads how to integrate Pine64 with a relay switch, to turn things on and off from a script ? Linux version is fine, no Android required. 
I would need both wiring diagrams and software, any leads appreciated.
Looking to automate a thing in garage.

As I recall from programming on Arduino, relays are super simple just require a GPIO pin to be set to high or low and the relay responds accordingly.  I think that the first question that you need to ask is how to control a GPIO pin on the Pine64.  I have not done this, but I am sure that many have and so I would start by searching the forums on that.

Regarding the wiring, as I recall, it needs ground at GPIO pin and power.  It is really quite simple to wire and there are many examples on the Internet.

Update:
I am not sure what language you are using, but here is a good thread talking about a Python library. http://forum.pine64.org/showthread.php?tid=723
  Reply
#3
jl_678 is correct, it is quite simple, but if you do it wrong, it will destroy your PineA64.

... the most important thing to remember about triggering a relay with a GPIO pin is to have a protection diode across the coil of the relay.  Inductive loads (via back EMF, which can be thousands of volts, believe it or not) will destroy your Pine board if you don't account for it... with a protection diode.

I recommend purchasing a good relay driver board... they have convenient screw terminals and the protection diode is usually provided on the board. 

Also, I recommend driving the relay board with a ULN2803 driver. Basically, the GPIO drives the ULN2803 and the ULN2803 drives the relay coil.  This buffers the GPIO on the PineA64, and it protects the current output limits of the GPIO bus, and it allows you to drive a wider range of relay boards up to 500ma coils.  The ULN2803 can drive up to six relay boards. Sometimes the ULN2803 is included on the driver board too... makes them more expensive, but its worth it in the end.

Also, remember that the pineA64 is a 3v3 system. You will want to power the ULN2803 with 3v3 NOT 5v. Make sure that you never touch more than 3v3 to any GPIO pin on the PineA64 board. On the other hand, the ULN2803 will take up to 30v on its outputs... so you can use 12v relays and drive them with the PineA64. Be sure you understand the data sheet of the ULN2803 before you start.

The best thing to do first though, is learn to blink an LED... how to use Python is important, and you'll need to download the software; see below.

I recommend you download and use the RPi.GPIO-PineA64 codes from github.  You will also need to install:

sudo apt-get install python-dev
sudo apt-get install python3-dev

... and if you're using the ubuntu image, you will also need to install

sudo apt-get install gcc

------

If you have questions, please join us on the irc chat;  I'm there most days... or post here too, and we'll try to help you.  Again, there are examples on-line, and I'm even willing to post some for you if you give things a shot and need further help... if you figure it out yourself, you'll  learn more, and you'll feel better about it too.

best of luck to you and your project
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
  Reply
#4
marcushh77, thanks for you guidance, i've installed RPi.GPIO-PineA64 and i am familiar with python.
as for LED lab, the only step that works for me is constantly lit up LED (pin 1 and pin6).
i was following steps from here http://www.thirdeyevis.com/pi-page-2.php
turning LED on and off and blinking LED example did not work, my LED stays always on being attached to pin7 .
I wander if gpio pin numbers in pine are different than Raspberry pi ?
Also i did not find resistor 50 ohm, i only found 10 ohm, this is the only deviation from the lab.
Should I be connecting the wires to PI 2 Bus or Euler bus ? pins ?
  Reply
#5
(08-21-2016, 09:37 PM)vigor Wrote: marcushh77, thanks for you guidance, i've installed RPi.GPIO-PineA64 and i am familiar with python.
as for LED lab, the only step that works for me is constantly lit up LED (pin 1 and pin6).
i was following steps from here http://www.thirdeyevis.com/pi-page-2.php
turning LED on and off and blinking LED example did not work, my LED stays always on being attached to pin7 .
I wander if gpio pin numbers in pine are different than Raspberry pi  ?
Also i did not find resistor 50 ohm, i only found 10 ohm, this is the only deviation from the lab.
Should I be connecting the wires to PI 2 Bus or Euler bus ? pins ?

You'll want to change the value of that resistor if you can - shouldn't be anything below about 47ohm (running a standard red led at it's max recommended current), and preferably not below 68ohm. You can put a couple in series to increase the resistance if you don't have anything else. A standard red led is visible (although admitidly quite dim) on the pine64 all the way up to 4.7K (that is 4700 ohms!!!), so have a lot of room to play with as far as values. Basically, a higher resistor value is better, as it puts less strain on the LED and the Pine64 GPIO pins. Otherwise, you'll be putting too much current through the led (and possibly damaging the GPIO pin output drive??)

AFAIK, the GPIO numbers are the same (when using the Raspberry Pi header). However, GPIO 7 is not usable at present, as it is used for the LCD backlight drive. If you skip down two pins, to 11, and change the three references to pin 7 in the blink code on that page to 11, it should work just fine.

If you have a look at the pinout map Marcus has linked to in another thread, you'll see which headers to avoid due to secondary functions... just remember green is good Wink
  Reply
#6
I will add to what pfeerick as said, that the PL10 GPIO04 pin(7) used for the s-pwm LCD back-light, is not really a compatible PI bus pin per se. Someone found in the manual that the PLx pins are on a different base address. So, you not only have to disable the s-pwm in dts (and the driver) but you also have to set the base register (again dts) for the PLx pins in order for pin(7) to be used on the PI bus with RPi.GPIO-PineA64.

I don't recommend that. Just don't use pin(7). All the rest of the PI bus pins should behave as expected.

Typically, I used either 180, 330, or 470 ohm resistors with GPIO pins, depending on the required ma for the load... you can use higher resistors for 3mm low power LEDs and you will need to use lower resistors for the 5mm higher power LEDs . I recommend using the 3mm low power LEDs .
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
  Reply
#7
marcushh777, Thank you very much. Pin7 is what my mistake was, blinking led works with pin 11,13,15
while other leg of the LED connected to pin6 via 100 ohm resistor
I only need two pins for my relay project, so I am unblocked, thanks again you are awesome !

So then to trigger the relay, do i still need a resistor and what tolerance would you recommend (sorry my radio electronics skills are very limited Smile) ?
The circuit i am going to turn on and off via the relay powered by 4.3 volt battery, so there 's not a whole lot of power in that circuit.
  Reply
#8
DO NOT try to drive the relay with a GPIO pin (not even with a resistor).

... always drive the relay with some other driver like a simple 2N2222 or PN3904 transistor, or more preferably (as stated earlier) drive the relay with a ULN2803 (it has six channels, and you just use two of them). (its an inexpensive IC).

And, do not forget about the protection diode on the relay coil. Again, I strongly recommend purchasing relay driver boards that have the diodes and ULN2803 built-in. But you may do it all yourself too.
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
  Reply
#9
Marcushh77 thanks for this lesson in driving relays!

Do you also need a diode when using a solid state relay?
  Reply
#10
(08-22-2016, 10:11 PM)Boring Wrote: Do you also need a diode when using a solid state relay?

You need a protection diode anytime you are driving an inductive load (um, it has a coil as part of the load).

I'm not sure what you mean by solid state relay... if its a power fet or some other solid state device like that, then no, you don't need the diode protection.  The protection diode is only for going across a 'coil' to alleviate the back EMF that might otherwise destroy your Pine board. 

Some relays are in a solid block (they look solid state) but are inductive loads... and these need the diode protectors.  Again, many relay driver boards have the diode built-in, so check the data sheet of the boards you purchase ...
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)