callefr
Posts: 6
Joined: Thu Sep 20, 2018 3:09 pm

how to use the GPIOs

Thu Sep 20, 2018 3:16 pm

It appears to me that ther eis very little informaiton around about hardware configurations that correctly connect to the raspberry. Sure, some simple examples making leds blink and so, but nothing substantial.

If I am not completely mistaken then you need quite a bit of precautions when using GPIO using e.g. by using an optocoupler.

Is there somewhere a reference architecture, or drawings, for this? With no relevant experience, I would hate it to blow my raspberry up :-)

The same for switching mains, and using AC engines

pcmanbob
Posts: 4340
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Hardware

Thu Sep 20, 2018 3:57 pm

Hi.

There are some basic interfacing circuits here : https://elinux.org/RPi_GPIO_Interface_Circuits

But really it comes down to what you want to connect to your pi gpio, there are so many possibilities dependent on what hardware you are using that no list of examples could possibly hope to cover them all.

Its down to you to do your own research and design suitable interfacing.

As for connecting or controlling AC voltages and AC motors at mains voltage its not some thing people here will be comfortable helping you with due to the dangers involved in working with mains electricity, you really need to be electrically qualified to work with mains voltage and if you are asking for this sort of help on a computer forum I suspect you are not qualified so attempt this.

Mains AC can and will KILL you or someone else and burn down your house given the chance.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

callefr
Posts: 6
Joined: Thu Sep 20, 2018 3:09 pm

Re: Hardware

Thu Sep 20, 2018 5:59 pm

@pcmanbob:

You will be surprised but I have mains AC at home (like many people I guess). In fact, I put most of those mains in the house myself and it was afterwards without any problem certified.

You are correct that mains can kill, so can dogs, cars, planes and much other stuff if not treated with sufficient precaution. That is however not a reason to stay in bed and do nothing all day.

Fact is, I need little help in the programming department, or in the mains department. I am qualified both as an electrician and as a programmer.

What is unknown territory to me is how to bridge the low voltage DC world with the AC world and find out how to safely connect raspberry GPIO to standard mains for e.g. domotics, hence my question.

If you say (and everyone here agrees) that this is a software only forum, then I am obviously at the wrong place.

Thanks for the link, very useful

User avatar
rpdom
Posts: 12804
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: Hardware

Thu Sep 20, 2018 6:26 pm

callefr wrote:
Thu Sep 20, 2018 5:59 pm
What is unknown territory to me is how to bridge the low voltage DC world with the AC world and find out how to safely connect raspberry GPIO to standard mains for e.g. domotics, hence my question.
This is the bit that can be very dangerous if you get it wrong. Hence people advising against doing it unless you do know exactly what you are doing.

Relay boards are a common way of controlling high voltages/currents from the gpio, either mechanical relays (ideally with an opto-isolator on the input side) or solid state ones. You'll need a board that is fully Pi compatible. Some switch on 5v, which won't work. Some can cause 5v to get back to the Pi, which will kill the gpio.

This post would probably have been better in the Interfacing section of the forum.

Heater
Posts: 9829
Joined: Tue Jul 17, 2012 3:02 pm

Re: Hardware

Thu Sep 20, 2018 6:37 pm

I would not say you are in the wrong place exactly.

Problem is that the Pi is power by 5 volts. The GPIO pins work at 3.3 volts. Thou shalt never apply more than 3.3 volts to a GPIO input. Thou shalt never draw more than a couple of milliamps from a GPIO output.

These limitations are of course true for any micro-computer/controller today.

Given those constraints how does one interface to a switch that should turn on and off 110 or 240 volts with perhaps 10s of amps current draw?

Or conversely how does one measure the state of a 110 or 240 volt line?

And do it safely?

That brings us into the world of serious electronics. Driver transistors, triacs, opto-isolators etc, etc.

Which is perhaps out of scope for a mirco-computer / programming forum.

But, there must be ready made, well engineered solutions to these problems available.

Any one have suggestions?

Aside: Yes I do wonder about the nanny safety attitude of the world today. When I was a young teenager I was building vacuum tube circuits with 400 volt power supplies. I built a light dimmers with TRIACs (A light dimmer was a high tech novelty at the time). Meanwhile we had industrial lathes and milling machines to play with during lunch breaks in school. It was expected that at 14 years old or so you have some idea about what you are doing and take responsibility for it.

jbudd
Posts: 706
Joined: Mon Dec 16, 2013 10:23 am

Re: Hardware

Thu Sep 20, 2018 6:39 pm

There are quite a few smart switches available cheaply which use WiFi, Zigbee or 433MHz radio.
I have used Itead's Sonoff range (inline) and Orvibo's S20 (plugged into the mains) to switch things without the Pi coming anywhere near mains voltage.

Unfortunately I have not come across any such device that works with UK lighting circuits (Live and Earth but no Neutral)

callefr
Posts: 6
Joined: Thu Sep 20, 2018 3:09 pm

Re: Hardware

Thu Sep 20, 2018 7:05 pm

Hai everybody,

Thanks for all the input.

Apologies for posting this in the wrong forum section: I am a newbie you know ;)

I can't imagine that I am the only one getting on-line to find proper schema's to link mains to the raspberry. I think we all agree that safety is important, which is perhaps one more reason to make sure that there is decent documentation on how to do certain things. After all, mains is not the same as big power. e.g. LED lights at home all function on 220V AC but are limited wattage. Shutter engines are often less than 200 Watt ...


But Hey, I just got here and already I have a pointer to an interesting page on elinux and a number of very good suggestions :-)


Thanks everybody

Heater
Posts: 9829
Joined: Tue Jul 17, 2012 3:02 pm

Re: Hardware

Thu Sep 20, 2018 7:27 pm

callefr,
After all, mains is not the same as big power. e.g. LED lights at home all function on 220V AC but are limited wattage.
Hmmm.... perhaps it's misunderstandings like this that cause this kind of forum to stay away from and discourage dangerous things.

Sure LED lights don't use much power but if you are messing with 220V mains supplies you can easily kill yourself, or others, if you don't know what you are doing or take precautions.

Sure LED lights don't use much power but it's amazing how few watts it takes to ignite a fire and burn the house down.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20465
Joined: Sat Jul 30, 2011 7:41 pm

Re: Hardware

Thu Sep 20, 2018 7:54 pm

callefr wrote:
Thu Sep 20, 2018 7:05 pm
Hai everybody,

Thanks for all the input.

Apologies for posting this in the wrong forum section: I am a newbie you know ;)

I can't imagine that I am the only one getting on-line to find proper schema's to link mains to the raspberry. I think we all agree that safety is important, which is perhaps one more reason to make sure that there is decent documentation on how to do certain things. After all, mains is not the same as big power. e.g. LED lights at home all function on 220V AC but are limited wattage. Shutter engines are often less than 200 Watt ...


But Hey, I just got here and already I have a pointer to an interesting page on elinux and a number of very good suggestions :-)


Thanks everybody
I suspect if anyone published schematics for main switches for the raspberry, someone, somewhere would probably kill themselves using it, because you simply cannot assume everyone is competant. The guy who did the schematics then gets sued.

I wouldn't risk it.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

travisfarmer
Posts: 14
Joined: Sun Jan 07, 2018 9:33 pm
Location: Maine, USA
Contact: Website

Re: Hardware

Thu Sep 20, 2018 8:25 pm

i don't recall where the OP said he was from, but i would suggest something pre-made for switching mains power, similar to Adafruit.com item 2935. other than that, without evidence of qualifications for dealing with mains power, i am hesitant to provide what i know about how to do this task.

i know in the USA, where i am, the homeowner is "legally" allowed to run and modify mains power circuits in their own house, without a license (but with restrictions). believe me, as a carpenter, i have seen some very scary "homeowner" wiring. i know how to properly wire home mains circuits, and how to interface them with a Rpi. but when someone states that they are qualified, but don't know how to do it, i am very skeptical. no offense, just playing it safe.

~Travis
Most of my electronics/programming experience is in Arduino, but i am learning Rpi to broaden my projects capabilities.

drgeoff
Posts: 8491
Joined: Wed Jan 25, 2012 6:39 pm

Re: Hardware

Thu Sep 20, 2018 9:27 pm

There is a lot more to safely controlling mains with a RPi than a schematic diagram.

Brandon92
Posts: 472
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Hardware

Thu Sep 20, 2018 9:55 pm

callefr wrote:
Thu Sep 20, 2018 7:05 pm
I can't imagine that I am the only one getting on-line to find proper schema's to link mains to the raspberry. I think we all agree that safety is important, which is perhaps one more reason to make sure that there is decent documentation on how to do certain things. After all, mains is not the same as big power. e.g. LED lights at home all function on 220V AC but are limited wattage. Shutter engines are often less than 200 Watt ...
Like the others said. Controlling the mains voltage is not the same as just turning a led on. And connecting wire's in you house is not the same as designing electronics. There are a lot of variables that you need to take into account. And yes, it's look so easy. Until it goes wrong...

The "load" could be, as you said, reasonable low. However, when it goes wrong. There is a lot more power / energie that can be delivered.

However, there is always a change that you do not listen to our advice.
So, for that. First watch this video. And after that watch his follow-up video. Here is a good example what could happens, when you think you did the right thing. Or you use someones schematic, that is not correct.

This will happens if you choose the wrong part and/or manufacture, or the design itself.

User avatar
davidcoton
Posts: 3160
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Hardware

Thu Sep 20, 2018 10:35 pm

callefr wrote:
Thu Sep 20, 2018 5:59 pm
I am qualified both as an electrician and as a programmer.
I am qualified as a programmer, electronics and electrical engineer, and as an electrician. I have earnt my living in each of those fields at different times. I still find it daunting to interpret component specifications correctly and design mains interfaces -- which is not to say I don't do it, but that it takes a lot of professional level skill to get it right. A lot of this is in the grey area between wiring regulations and product design. You need a good understanding of both.

I find it slightly scary that you, as a "qualified electrician", think that LED lights at mains voltage are less dangerous because they are lower power. (Yes, maybe less fire risk, but not zero; and the shock risks are dependant on voltage not power).

I too will not give tutorials or reference designs for mains interfaces. However if you propose a scheme, I will comment on it and point out weaknesses and problems, as will others. Of course we don't know your skill set and ability, but you may need a thick skin.... :o
"Thanks for saving my life." See https://www.raspberrypi.org/forums/viewtopic.php?p=1327656#p1327656
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”

callefr
Posts: 6
Joined: Thu Sep 20, 2018 3:09 pm

Re: how to use the GPIOs

Fri Sep 21, 2018 2:44 pm

Good, this may be a bit difficult;

for a start: I am not trying to start a flame ware or to offend. I just want to introduce a different point of view.

Apologies if the english is not totally correct but I hope you can/want-to understand.

First, an example:

The "danger" of an experiment involving mains appliances can be easliy (or should I write: should in all cases) be limited by a few simple measures:

1. the correct (smallest possible) fuse installed before (in an electrical sense) your testing/experimenting set-up and limiting the current in the tested circuit to anything reasonable for the tested application.

For my LED example earlier in this thread: this would, in a 220 Volt AC circuit (as common in Europe) and for a typical 220V/10watt LED come down to 0.045 Ampere per lamp which means that any 220 Volt fuse of 0.5 Amp would do. This is a substantial reduction of the risk.

2. By using a residual-current circuit breaker. We have two of these as standard for the whole house where I live, one switching of at 300mA, and another one for "wet rooms" such as the bathroom switching of at 30mA. Obviously, an experiment should preferably be done on a circuit covered by the 30mA circuit braker.

3. By ensuring that the EARTH connection is properly tested and functioning correctly, and that it is embedded in whatever you are producing (or what is the english technical term of this).

Second, What I try to explain:

The above informs a novice user to be carefull with mains and immediately (partly?) explains how to do that.

Now, compare this with the sentence: "Mains AC can and will KILL you or someone else and burn down your house given the chance."

Which of the above would be more helpfull?

Point is, people visit fora in search of information because they want to learn, because they have an interest, because they have a project ...

Sending them away with "i will not help you because you may be an incompetent idiot" will not stop them but may well lead to ill-informed dangerous experiments that do lead to tragedies. It seems also in contradiction with the very reason for having a forum.

The same for showing a video of a burned Solid State Relay where the victim was probably tricked in using a cheap fake SSR with internals not up to the job. I am sure that every experienced maker could have explained him that such cheap SSR from some internet store contaisn a 12A or 16A TRIAC instead of a 40A one as written on the box.

Stating this on the forum would be more useful than: "This will happens if you choose the wrong part and/or manufacture, or the design itself. " or "There is a lot more to safely controlling mains with a RPi than a schematic diagram".

Both of these answers may be entirely correct but don't provide any value to the reader.

So, let me repeat my question (a bit more elaborated than the first time and in the hope that I have not totally alienated all of you):

I can program, and I can make a 220v electrical circuit. In fact, I've done my whole house and it passed the legally required technical control without trouble.

However, I have little experience with electronic circuits but know that one can't simply connect a GPIO with a TRIAC or lamp without blowing things up.

Can someone point me to schema/drawings ... or other information showing me how to safely connect the GPIO with the external world. Consuming less than 3mA per GPIO ...

@davidcoton: thanks for the offer. As soon as I am far enough to produce a schema, I'll show you :-)

By the way, schock risks are not determined by voltage alone as someone writes here. Electric cattle fencing can operate on 10 to 13 kiloVolt (which is much more than a 220 Volt home appliances) but the very limited current makes it safe (although higly uncomfortable) for cattle as well as humans.

Brandon92
Posts: 472
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: how to use the GPIOs

Fri Sep 21, 2018 3:36 pm

callefr wrote:
Fri Sep 21, 2018 2:44 pm
Stating this on the forum would be more useful than: "This will happens if you choose the wrong part and/or manufacture, or the design itself. " or "There is a lot more to safely controlling mains with a RPi than a schematic diagram".

Both of these answers may be entirely correct but don't provide any value to the reader.
True, but not every scenario is the same.

However you sound like you have some knowledge about this.

So, is your basic goal to turn of and on a mains voltage load?
And what for kind of diagram are you looking for. A diagram that you simple can connect of the shelf part. Or a schematic, that you need to solder the parts by your self?

And what is the mains voltage that you have?

Edit
And how much can it cost?

callefr
Posts: 6
Joined: Thu Sep 20, 2018 3:09 pm

Re: how to use the GPIOs

Sat Sep 22, 2018 6:58 am

I would like to make some basic modules/schema that can be used in a variety of projects. First to be able to use the raspberry as controller for some appliances such as lights, shutter engines, dimmers … Later to use the raspberry as the central element for reading sensors in a home network.

First for output, I think that I cobbled together more or less what it takes to do that but being careful by nature I am now searching for advice to reassure myself that my schema's are not having a temperamental (exploding) nature.

Next to having something that works, it has quite some importance that I learn about the exciting electronics world along the way. Today, I know what a transistor, resistance, capacitor … are but that is more or less it :D .

The kind of things I get stuck on are e.g.: if I place a snubber over a Triac what values should the resistance and capacitor have?

What I am going to do next week is make and upload a decent drawing of my first schema and open the floor for criticism, maybe that can help.

Once I have a final design, I will have to upscale my soldering and printing board making skills. I know that one can buy many ready made modules but by doing that I am not learning anything.

About costs: the cheaper the better with the big disclaimer: whatever I produce must be safe: No fake SSR that blow up in my face.

My mains voltage is 220 Volt.

jpham
Posts: 18
Joined: Thu Sep 20, 2018 4:19 am

Re: how to use the GPIOs

Sat Sep 22, 2018 9:51 pm

instead of using RSP GPIO, I would recomend looking at Microchip MCP23017 (I2c) or MCP23S17 (SPI)
this gives you 16 GPIO per chip- if you use I2c, you can put it on the I2C Bus for a max of 8 device (x16 = 128 GPIO ports!!!)
enough for a blinking led show or some fancy I/O

Brandon92
Posts: 472
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: how to use the GPIOs

Sat Sep 22, 2018 10:42 pm

callefr wrote:
Sat Sep 22, 2018 6:58 am
What I am going to do next week is make and upload a decent drawing of my first schema and open the floor for criticism, maybe that can help.

Once I have a final design, I will have to upscale my soldering and printing board making skills. I know that one can buy many ready made modules but by doing that I am not learning anything.

About costs: the cheaper the better with the big disclaimer: whatever I produce must be safe: No fake SSR that blow up in my face.

My mains voltage is 220 Volt.
Sounds like a good plan. And I'm looking forward to see your schematic. Then we also know what your knowledge is about this subject. And give you a better awnser.

Also when you design a PCB for high voltage. There are some rules that you need to follow up. Otherwise it's not save. But, we are not at this point.

However, this could be a problem down the line. But, I don't want to make a concussion yet.
callefr wrote:
Thu Sep 20, 2018 3:12 pm
Hai,

I am a newbie, not much to say about myself actually, just that I have experience programming in visual basic, c sharp, fortan and a load of other languages but no hardware experience whatsoever.

guymark
Posts: 15
Joined: Fri Sep 14, 2018 2:56 am

Re: how to use the GPIOs

Mon Sep 24, 2018 3:38 am

The safest way to interface would be using Bluetooth to drive blutooth enabled switches / dimmers etc. This gives you TOTAL isolation from the mains - though I am guessing this might not be where you want to start.

Like others, I am not comfortable in guiding someone over the net how to make a "wired" control to the mains - BUT certainly if you looked around for a simple circuit that used a GPIO pin to drive (via a 10K resistor) something like a small mosfet (IRF610 would be perfect) to drive a relay, and if the only part of the relay connected to the Pi and associated drive electronics is the coil, then you have "DRY Contacts" to switch whatever you want.

You can then switch whatever voltage / current the relay is rated for. Clearly if you are familiar with house electrical systems, then you will understand the versatility of a simple relay with dry (unpowered) contacts.

Incidentally, if you don't have a MOSFET to hand, you could also use any of the chunkier transistors BUT make sure you plonk a diode over the relay coil to squash any potential back-EMF. A humble BC109 or BC337 could easily do the job for pennies.

https://www.ebay.co.uk/itm/5V-1-2-4-8-C ... 2sjw9zXU5Q sells relays ready buffered. You can connect the signal input directly to the GPIO pin. It just needs a 5v DC supply for the relays - check if you like but I think it would be VERY happy activating from the 3.3v - and I suspect way lower than that too.

In this case, the seller shows the relays are rated for mains at upto 10A - personally I would want to inspect track clearances and quality of relays before even thinking of that - but as a "thing to get you switching stuff on and off" - it could be a useful building block. Once you are happy with the design, nothing to stop you duplicating the circuit using higher quality components. I would be wary of using a Chinese made cheapo board to switch mains - but an excellent learning PCB which can VERY EASILY be reverse engineered to then use high quality components (good quality relays etc).

This one https://www.ebay.co.uk/itm/1-Piece-8-Ch ... SwvP9aoinO has the added safety of an opto isolator. MIGHT just be worth checking it will work at 3.3v but I wouldn't be surprised if it would work from a few hundred millivolts. Could always pop them a questions.

Dimmer being driven by a Raspberry Pi. https://www.youtube.com/watch?v=wqY4-gHqvZI
The universal dimmer board in question:- https://www.tindie.com/products/nEXT_EV ... r-mpdmv41/

Whether this will work on a "neutralless lighting system like the UK uses I don't know - but I would guess the manufacturer would know, again worth popping them a line.

I make NO recommendations here at all for connecting anything to the mains - but it might prove to be useful viewing material which you could then adapt should you wish to accept the risk of doing so.

Safest (and possibly simplest) might still be to consider the Bluetooth approach - I would be VERY cautious about designing your own interface from scratch to use with anything much South of around 48VDC. I hear what you say about being an electronic engineer and an electrician - BUT I would be very tempted to at least start with a professionally made device - and then decide for yourself and at your own risk - if you reckon you can make it better.

Searching for "dimmer circuit raspberry pi" and "dc controlled AC dimmer" may also yield results - though I make ZERO guarantees for their safety or accuracy.

Best of luck - oh and if you get a decent PWM circuit, you may find it can be used to regulate small motors too.

jpham
Posts: 18
Joined: Thu Sep 20, 2018 4:19 am

Re: how to use the GPIOs

Wed Sep 26, 2018 5:15 am

How about publish a document on how to use GPIO with common device like a UART - a 16550 Uart - simple 8bit bus, with /CS, /REset, /ioread and /iowrite - alot of common interface chip has that common features

I like seeing those GPIO connect to blinking lights, but why buy a 1.2Ghz SBC module to do blinking lights test, let use some 8bit 8051 for those blinking lights experiment

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 12 guests