This can include systems to monitor pets or burglars. It has a number of nice features under the hood and one of those features is the ability to monitor GPIO pins and display information within the motionEyeOS web interface.
I wanted to use this feature to display the status of my two garage doors. They have magnetic switches so I decided to configure motionEyeOS to display their status given the Raspberry Pi is already setup in the same location. The door switches connect a GPIO pin to 3. The monitoring command feature is described in the motionEye Wiki. In general it is the same as motionEyeOS with the exception of the file path you need to use.
To start with we can create a script to monitor a single GPIO pin. Using SSH connect to the Pi. This file is also available from my BitBucket repository. If it has not two echo commands are run to set up the pin as an input. These will generally default to being tied Low with internal pull-down resistors. Connecting the pin to 3. When monitor scripts are added, removed or edited the web interface needs to be reloaded in your browser for the changes to take effect.
Clicking on the camera image will show the icons in the top right and the status of the GPIO in the bottom left :. Now change the state of the switch attached to GPIO You should see the text change on the screen. The bash script can now be modified to read more than one GPIO pin and the result can be combined into a single output to be displayed on the screen.
In the example below the script checks GPIO 17 and Their states are combined into a single output. For my final script I adjusted the text display to be more relevant to my garage door situation. It outputs a line of text showing the status of each door. D1 is on the left and D2 on the right. The following screenshot was taken from my smartphone and now shows the status of the two garage doors :. One thing I noticed was that the update text was truncated on my Smartphone.
I adjusted the text elements so this was avoided. On my phone the limit appeared to be 17 characters but I suspect this will vary on other devices. By default the script is run once per second.My problem is that even when I see the input signal go into saturation, I do not see the bit go high.
In the example code, it sets various manual gains for RX. This happens between the GPIO set up and the initial calibrations. Note that I have previously verified that AGC appears to be working, because if I scale up my input level, the output shown in various plots does not appear to change until we hit saturation. As a result of the fact that I get the correct gain index output on the GPIOs, but the overload bit is not working as expected, I am wondering if the problem is with my AGC setup.
Finally, it should be noted that the one time I noticed the bit going high but it only toggles momentarily is if I input a signal that would saturate the frontend BEFORE running my application. In this instance, during the initial calibrations, I see the bit toggle twice, but it stays low after calibration. Any help would be greatly appreciated since I think I am setting up the GPIO monitor correctly, it just doesn't seem like the device is outputting the bit when I would expect it to.
If an external attenuator is not used, zeros may be set in the external attenuator column of the gain table. The external attenuator requires the 3. External attenuator control is available on the Rx and ORx ports only. I modified my code to set the manual gain to index I see saturation effects in my plots, but I do not see the bit go high.
How you are probing the bit? Are you using oscilloscope? Can you trigger oscilloscope with the GPIO pin and whether the pin goes high? Have you tested this on our eval board? We have tested this on our eval board and we could see this pin goes high. Do you have the headless. What signal level are you providing to the transceiver? We see the pin toggle during initial calibrations i. I know I am probing the correct pin because I am able to read out the gain index properly if I change the GPIO monitor index to 0x09, which also eliminates any potential issues with our hardware we have a custom board.
Log in. Site Search Log in.This program, called gpiocan also be used in scripts to manipulate the GPIO pins — set outputs and read inputs.
In addition to using the gpio utility to control the GPIO pins, you can:. See the man page for the gpio program to see what all the features are by typing. Reads and prints the logic value of the given pin. It will print 0 low or 1 high. This loads the SPI kernel modules and optionally sets the internal buffer to the given size in KB multiples of The default is 4KB and is usually more than enough for most application which only exchange a byte or 2 at a time over the SPI bus.
This exports the given pin BCM-GPIO pin number as an input or output and makes it available for a user program running as the same user to use. This enables the given pin for edge interrupt triggering on the rising, falling or both edges.
Or none which disables it.
How to begin with Raspberry Pi GPIO programming using Python
This uses the wiringPi pin numbers to set pin 0 as an output and then sets the pin to a logic 1. The GPIO lines have internal pull up or pull-down resistors which can be controlled via software when a pin is in input mode.
These set the resistors to pull-up, pull-down and none respectively on wiringPi pin 0.
The PiFace is somewhat limited in that it has 8 inputs pins and 8 output pins and these are fixed in the hardware, so only the write and read commands are implemented:. This enables up or disables tri the internal pull-up resistor on the given input pin. You need to enable the pull-up if you want to read any of the on-board switches on the PiFace board.
Not looking for a full solution just a nudge.
So there is an old phrase used by programmers or is it a phrase used by old programmers! As for the compiling, yes, Sorry. However you might want to look at using a Makefile. If you get the wiringPi source and look in the examples directory — copy the Makefile from there and adapt as required. Just remember that spaces and TABs are different in Makefiles!This article uses the RPi. Raspberry Pi is a sensational single-board computer SBC and development board, which is heavily used for the prototyping of IoT based products.
It is the best-selling British computer ever, with more than 10 million pieces sold already. Contrary to common belief, Raspberry Pi is not entirely open source. Yet, it has been used in many open source projects. In this article, we will learn to use it as a development board. For all the programs and circuits discussed here, I have used Raspberry Pi 3. What makes Raspberry Pi suitable for making IoT projects is its pin expansion header.
Figure 1 is a pinout diagram, taken from Wikipedia. In the first case, the pins are numbered sequentially from one to In the figure, this is shown as Pin.
Monitoring Raspberry Pi GPIO with MotionEyeOS
And the image represents what is seen when the Pi is held with the USB ports facing downwards. That is, Pin 2 is the pin in the corner. As you have probably guessed already, all the pins are not programmable. There are other dedicated pins too.
Most of the pins have alternative functions, as shown in the figure. A majority of the pins are directly connected to the SoC; so while connecting circuits or components, one should be careful to avoid wrong wiring and short circuits. It is always good to have a descriptive pinout diagram printed out for quick reference as well as a multimeter on the work desk.
Armed with some understanding about the pins, let us move to programming. It is already installed in Raspbian, the default operating system for Pi. If you are using any other operating system, the package can be installed by using the following command:.
You will get some basic information about your Pi printed as the output. Step 2: Set the numbering style to be used. We use the method GPIO. It takes either GPIO. BCM as the parameter. BCM stands for Broadcom numbering. In order to keep things simple, we will use only GPIO. BOARD here. You must clean up the pin set-ups before your program exits otherwise those pin settings will persist, and that might cause trouble when you use the same pins in another program.
It only takes a minute to sign up. I actually joined StackOverflow to ask this question because I wasn't sure it was RPi specific, but as I was thinking about how to form the question, I realized it might be GPIO specific for some reason that I'm not even aware ofso hopefully this is the right place to ask. I'm running Raspbian Jessie 4. Over time, I've cobbled together a fairly basic python script to monitor a GPIO pin and send a network signal to a remote application. I run two slightly different copies of the script to monitor two different GPIO pins for two different network signals, and the scripts are launched from rc.
A previous version of these scripts ran for months on end, but I just had the current version fail after maybe two weeks due to "RuntimeError: maximum recursion depth exceeded. The log for script1 is 0 bytes, so I believe that command gives me a number that shows roughly how many levels of recursion the script encountered. The output wasand paired with the two functions I wrote repeating back and fourth all but 7 of those times, the iterations seem high enough to indicate the problem lies in how my script is written as opposed to within an imported package.
Here is an example of the script I am running:. Above that in the log file, the first two sections repeat times following the first bit which is roughly the same:. With a bit of searching, I've found advice such as " Rewriting the algorithm iteratively, if possible, is generally a better idea " and " For instance, it's quite possible that your outermost loop will hinge on a simple while. Given this, while it seems unlikely to me, it may be possible that I'm not understanding recursion right and there is an issue in requests that caused this error vs the bouncing back and forth between my functions.
However, logically speaking, even if the if loops are redundant and it would work with only while loops, I'm not sure that such a change would remove the recursion since each function still calls the other.
When you have a recursive function like this one with too much depth potentialyou need to convert it into a loop.
In this case you have two functions alternating calling each other:. This will loop forever as does the original version, you are exiting on a signalbut you can also use some kind of state as a condition in the while loop.
Sign up to join this community. The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered. Asked 9 months ago. Active 9 months ago. Viewed times. Here is an example of the script I am running:! I'm not sure how to proceed for a number of reasons such as these: 1 The original version of this script that ran for months on end used socket instead of requests and it looks like I never stopped importing that, so some script cleanup may be in order.
I posted this and then immediately came up with a search idea. I'm not even sure if I need to use an exception or if I can just place both of my functions or even just the code from the functions inside of a while loop that will always remain active so they don't need to call each other.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
If nothing happens, download GitHub Desktop and try again. If nothing happens, download Xcode and try again. If nothing happens, download the GitHub extension for Visual Studio and try again. This program does not change the mode of any of the pins, it just observes the logic value. If you want to set any of the these pins to output, and observe the change, you can open a console and type the following commands. If you want to observe the state of any of the pins as input, you can connect the pin with a suitable resistor to ground or 3.
Be carefull with the gpio command and use it only with a proper green wiringPi pin. Also, be carefull hooking up anything to the gpio connector. You might destroy your hardware if you make a mistake. Do not hook up any pin to 5V. Please open an issue in this repository or write to rricharz77 gmail. Your input is appreciated. Skip to content. Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up. Displays the pin status of the gpio pins of the Raspberry Pi zero, 2 and 3. Branch: master. Find file. Sign in Sign up. Go back. Launching Xcode If nothing happens, download Xcode and try again. Latest commit. Latest commit 8a1f Dec 3, You signed in with another tab or window.
Reload to refresh your session. You signed out in another tab or window. Jul 1, Dec 3, GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. If nothing happens, download GitHub Desktop and try again. If nothing happens, download Xcode and try again. If nothing happens, download the GitHub extension for Visual Studio and try again.
The example INI file contains the only configuration required. Depending on which you will need to ensure the appropriate Python module is installed. If using the PiFace extension board you will need to follow the instructions here to install the digital IO libraries. GPIO module should be installed as part of Raspbian. To install. You should now be ready to run the script. Obviously you can't do both monitor and update for the same pin. Any message arriving on that topic will trigger the script to re-send publishes with the current state of all monitored pins.
This is useful for requesting the current state of all pins if the calling system is restarted for example. Skip to content. Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up. Python Branch: master. Find file. Sign in Sign up. Go back.
Launching Xcode If nothing happens, download Xcode and try again. Latest commit Fetching latest commit…. If using the PiFace extension board you will need to follow the instructions here to install the digital IO libraries; sudo apt-get install python3-pifacedigitalio If just using the raw GPIO pins then the RPi. You signed in with another tab or window.
Reload to refresh your session. You signed out in another tab or window. Jul 7, Oct 2,