Thank for this, haven’t tried it this way yet. I do have another Pi in my network for music and I have Moode installed on it. The MPD binding controls simple commands for music and then I also have a python script that responds to MQTT which uses the GPIO pinson Pi to turn the amplifier ON/OFF with a relay.
This was exactly what I needed to get into the GPIO game. It is less than 2 hours later and I can now control my landscape lighting with openHAB.
Details: The lighting runs on 12V and the transformer/timer combo is indoors beside the electrical panel. I changed the mode on the transformer from TIMER to ON and am now using a 5V relay to toggle power to the lights (controlled by the raspberry pi that runs openHAB).
I have set the schedule by editing my .rules file which will also turn them on at 6:45PM: and off at 10:30PM
Next, I will be utilizing more GPIO to control additional relays for the pool equipment and to take temp/humidity readings and some other stuff TBD.
Hi,
I’m going crazy here. I’m just doing a simple test and want to just use Python. Everything seems fine, but I can’t seem to get the GPIO pin to switch and beginning to wonder if there is any reason this won’t work out-the-box with OpenHabian.
if you are using Python, you may need to install a few libraries. nevertheless it shouldn’t be too hard.
You may want to have a look at my other Tutorial control gpio pins with Python/MQTT
Things to look out for: you need to install the RPi.GPIO library and you need to address the pins by their proper number (Board or BCM), but you might have done that.
Anyway, have a look at my other tutorial (linked above) and see if that helps you
Thank you. I’ve gone through the list of binaries in your example and they’re were already installed and at the latest version.
Interestingly the gpio readall command doesn’t work for me (RPi 3).
I must have got something wrong with the pin-out. The multimeter reads 0 volts between pin 6 (GND) and pin 8 (+).
I’m using GPIO.BOARD, so with the Micro USB (Power) port facing me and the NIC to my right, pin 6 is the third pin in from the right, on the bottom row.
At this point, I am only testing with a multimeter, but I am using the code provided here, “Practice circuit 1”.
I have a PoE hat installed and although it shouldn’t affect it, I’ll try with it powered from the USB in the morning.
in order to use the gpio readall command you need to have wiringPi installed.
not sure if I fully understand your description coz the NIC and USB are at the same side of the board so they would all be facing you or all be on your right, but lets say with the pinheaders on the top of the board would be physical pin 35, BCMpin 19, WiringPi pin25.
In that same position physical pin 6 would be third from the left on the top row… but that is a ground connection. Pin8 is GPIO14.It will only be ’ +’ if you switch it on
I would suggest the following:
install wiringPi (sudo apt-get install wiringPi)
If you want to keep using the program in the link, use physical pin 8 which is BCM pin 14.Make sure you know which pins you are using. From your description I understood you had your board possibly 180 degrees wrong, but maybe I just didn’t understand you correctly.
If you remain unsure about using the right pin, issue the gpio readall command. That should represent the pins on your board in the same way as if you have the board upright with the pin header on your right hand side. The gpio readall command also shows the state of the pin so if you (think you) use pin 8,check with gpio readall to see if that pin now indeed is an output and if it is switched high or low
Sorry, when I wrote my last post, I didn’t have the Pi in front of me. By USB port, I meant the micro USB power socket. Updated my last post.
The code linked just seemed like a good, clear “hello world” example to turn an LED on and off. I’m actually creating the circuit for adding some LEDs to a MoBo case and wanted to use the 3.3v GPIO from my RasberryPi for a test rig. My only Pi happens to have OpenHabian installed, I suppose I could configure another SD card with ordinary Raspbian…
You were right, I had the board 180 degrees around the wrong way. Probably not helped by the fact the PoE hat has no numbering, although I’m sure I checked out which was pin 1. Anyway, it now works. Thank you.
On a side note, sudo apt-get install wiringPi didn’t work. I checked my libraries were up-to-date. I had to install and compile from Git, using these instructions.
I started using GPIO’s to get switches connected to OH. It took me a bit but it works. I am now in the process on implementing MQTT, so appears I’m doing the reverse to you in that respect. Anyway, do you know how to setup a toggle function in OH using two GPIO pins and one switch item?
For clarification I have an RF remote which have separate On and Off buttons. At the moment I have an On and Off switch setup in OH and using .rules to toggle each switch for 500ms. I am finding it a pain to tell my google home commands. The switches are setup for example, Lounge_On and Lounge_Off. So if I want to tell G’home to turn on the lounge lamp I have to say “turn lounge on on” and to turn off "turn lounge off on. It would be nice if I could switch it the usual way.
My thought train was along the lines of MQTT where you have the line
I have never tried that myself, but I believe it is possible to attach two outgoing and two incoming MQTT commands to a channel.
So as ON command you could actually send the ON command for the One and the OFF command for the other
There is no specific binding for analog values afaik.
But what you can do is read the value of /sys/bus/iio/devices/iio:device0/in_voltage_raw and either MQTT that to openhab OR use the REST API to put it in openhab.
This is simple to do with Python.
If you dont know how, have a look at how the DS18B20 or DHTx transfers their values with a python program, it basically comes down to reading the file, parsing it to get just the one value you need and then use MQTT or REST.
REST API uses: requests.put('http://192.168.xxx.yyy:8080/rest/items/<YOUR ITEM>/state',value) .