Adding to the answer above, how to do this really depends on the load you want to switch.
Here's a post about how much current you can draw from the GPIO see here
A few cases:
1) You have only one LED, that's it, and 20mA or so will do. See here an internet article on how to do this with one resistorsee here
2) You have more than one LED, you want the ...
You can add two Ethernet ports to your raspberry pi with EthernetBerry Dual ETHERBERRY. Check this link out:
EtherCAT® Shield for Raspberry PI – EtherBerry
You want to add at least 3 different port. So, one another can be a USB Ethernet port which you would connect to your raspberry pi by one of the USB ports.
You can add more USB Ethernet port but you ...
It's a switch. Connect it like you would any other switch. The only thing to decide is if you want to use it as normally open (normally reads as off) or normally closed (normally reads as on).
There are two basic ways - connect common to ground or connect common to 3V3. Whichever you choose it is safer to make that connection through a resistor to prevent ...
I would comment on @m-rostami's post but I don't have sufficient reputation yet.
The EtherCAT shields are very expensive, but adding USB->Ethernet adapters will work just fine. Yes, the performance will be very poor, but you probably don't care about that because you are running this as a learning experiment.
Remember that the Raspberry Pi model 3 and ...
The B+ has 26 usable gpios. In that context 8 doesn't seem a lot.
In effect you are trying to trade off the number of gpios used against complicating the circuit.
Have you considered a port expander, such as the popular MCP23017? That connects to the I2C bus (two gpios, SDA and SCL) and provides an additional 16 gpios per chip. Up to 8 MCP23017 may be ...
I just finished building a power-off circuit yesterday, although mine uses a momentary switch.
Here is the python code (with attribution embedded):
#This script was authored by AndrewH7 and belongs to him (www.instructables.com/member/AndrewH7)
#You have permission to modify and use this script only for your own personal usage
#You do not ...
Exactly, Just use it as a switch.
I assume when the door is open or closed the Pi wants to know about it via one of it's input pins. Is the pi looking for a low? Then wire the switch from the input pin to ground and take a pull-up resistor to the +3.3V line. When the switch is open i.e. no magnet present, the input will be logic high. When the magnet ...
I have a bank of 8 LEDs where I need to be able to tell which one of them a photoresistor is positioned over, and I think this is a version of the same problem.1 To determine which LED is lit, I don't need to be able to control them all individually. Instead I use 5 lines -- actually transistors toggling the return to ground, since one GPIO directly is not ...
The Raspberry Pi is not a good candidate for such an experiment. Raspbian is a general-purpose OS based on Debian Linux. Instead, buy, perhaps second-hand, a device intended to be a router that has multiple Ethernet ports and probably a wireless access point. Load one of the open-source firmware releases, DD-WRT, OpenWRT, Tomato, or perhaps something else....
The stated question is regarding contact bounce. However, the data presented in the question does not reflect contact bounce - contact bounce does not repeat over the 100msec & 300msec durations presented in the text of the question. Let me try to be clear: The data provided does not rule out contact bounce, but the issue described by the data is not due ...
The Raspberry Pi's GPIO pins work with 0V-3V3 differential from GND, and can work in either Output (the RPi sends out a signal) or Input (the RPi listens for a signal) mode. In Output mode, if you make the pin HIGH in your program, the GPIO pin's voltage will be at 3V3 compared to GND. If you make the pin LOW in your program, the GPIO pin's ...
It sounds like you are wanting to wire the wall switch and the relay as a three-way switch arrangement. This way, if the relay has the light turned on, flipping the wall switch will turn it off, and vice versa. You could wire a single-pole double-throw relay to work as a 3-way switch, and install a 3-way switch in the wall (if it isn't already a 3-way switch)...
You're looking at a floating input. When you read pin 25 without it being connected to anything at all it can be considered to have an undefined, unstable value. That's indicated by the LED randomly turning itself on and off. By pulling the value of the pin to ground with your resistor you render it non-floating.
The point of a pull-down is to ground an input when it otherwise isn't driven to a particular value -- a state known as high impedance or floating.
I was confused by the term "pull-down resistor" the first time I saw it. And the second, third etc. Read the wrong way it implies the resistor is the active element in the "pulling down", which it is not (...
The 40 pin expansion header connects to 28 GPIO. They are Broadcom GPIO 0 through 27.
You are recommended not to use GPIO 0/1 as they are intended to be used by HATs.
Any recent GPIO library will give access to all the GPIO connected to the expansion header.
The resistance of the cable is irrelevant in this case. Telephone cable would be suitable.
The configuration of switch in http://elinux.org/RPi_GPIO_Interface_Circuits is the most appropriate. You could use internal pullup, but I would recommend using resistors. Either NO or NC is suitable, just adjust your logic to suit.
I recommend you select a pin ...
I think I found what you are looking for :
In this exemple, we see that two switches are controlling one lamp, so toggling one of these switch will toggle the lamp.
In your case, you need to consider your relay as the first switch, and your pre-existing switch as the second one.
Image taken from : https://diy.stackexchange.com/questions/31632/wiring-a-...
The double switch method (also called a staircase switch) would be preferable, as it's easier to integrate with existing wiring, but it leaves your Pi without knowledge about the state of the load.
As I see it you have two options:
Make the switch pull an input high or low on the Raspi, which you then use in your code to control the lamp or other load ...
Not sure why you've got Ground and 3V3 used in your circuit, you want one or the other depending on whether the input is pulled high or low.
You are also using the wrong pin (12) if you are using GPIO.BOARD - should be pin 32. If you were using GPIO.BCM then 12 would be correct. There is also no need for your 2nd while loop.
I've solved the problem.
UPDATE: The main issue appears to be in the kernel drivers. Problem solved by upgrading the kernel from 4.14.50-v7+ to the latest stable version (currently 4.14.79-v7+) using sudo apt-get install raspberrypi-kernel, and rebooting. The steps outlined below are no longer necessary. (reference).
UPDATE 2: Bad drivers on the client ...
You could simply wire the buttons up as a matrix, your usecase already describes the buttons being placed in a grid pattern. If you wire all the button pins vertically and horizontally you can form a matrix, with the 28 GPIO pins avalible on all Pi models but the first edition. You should be able to theoretically run 14^2 buttons or aprox 196 buttons.
I'm assuming the code you posted is for the push buttons?
Switches work very similar to push buttons. When you switch it on, voltage on your gpio port goes high until you switch it off. This is the same as if you were to hold a push button down for that same period of time. So lets modify this to your new requirements. You want:
On switch play sound a
It is trivial to write a script that runs the shutdown command on button press. The complication comes from people who want to power down the Pi. Unless you are using batteries this seems pointless.
It is simple to "restart" the B or B+ from the halt state see https://raspberrypi.stackexchange.com/a/23725/8697
I hope it's not too late to answer your question; I encountered the same issue and wanted to post the solution I found! What I did was using the buttons and switches introduction on the official Raspberry site and their workaround.
It doesn't use add_event_detect but defines a function (called BtnCheck). What I use looks like this:
I've re-indented your code, and you make a mistake on two lines (at line 68 and 117).
You wrote :
Whereas the correct way is :
Here is your file with the fix ;) :
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var gpio = require('pi-gpio');
var app = express();
var mysql = require('mysql');...
You have (2) options to power a Pi from your PoE switch (USB is not one of them):
PoE Hat: powers a Pi by just connecting the Ethernet cable to the Pi's Ethernet port; job done. Presently £20 (inc VAT) from all Pi retailers
PoE Splitter: has two connections: an Ethernet for data and a MicroUSB that diverts the power from the switch to the MicroUSB port ...