Simple GPIO example

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.

Thanks again. One happy camper.

great that you got it working.
bit surprised the apt-get install wiringPi didn’t work. Had no problems with it. Oh well, you got it now :slight_smile:

Hi @Kees_van_Gelder,

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

String KitchenTopL "KitchenTopL [%s]" {mqtt="<[mqtt:buttons:state:*:10-54],>[mqtt:openhab/out:command:*:${command}]"}

Is there a way to place the two GPIO pins as the controlling state and the string do the switching work?

Any help for a push in the right direction would be appreciated if possible.

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

@Kees_van_Gelder

Do I install this on the opnehabian Pi or the Remote Pi?
Sorry for such a stupid question, very new to this!

this is for the openhabian Pi.
If you want to adres GPIO pins on a remote Pi you can use MQTT like here https://community.openhab.org/t/controlling-a-raspberrypi-gpio-pin-with-mqtt/40912?u=kees_van_gelder

Hi. I want to read an analog input. My hardware is a beaglebone black. I could read it from linux but not from OH2. I tried to add an item like this:

Number AIN5 “Analog Input 5” { AIN5=“ANALOG_IN:5” }

but it didn’t work.

from linux I put this “cat /sys/bus/iio/devices/iio:device0/in_voltage5_raw” and I can see the value.

I have no problems with DI’s and DO’s using contact and switch with GPIO bindings.

Any idea? Someone can help me? Thanks

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) .

Maybe this tutorial can help you on your way Reading a DHT11/22 with 'overlay' and send result via REST API

1 Like

Thanks. I dont know anything about python but I will try it. Thanks again

its good to try, in order to learn. if you really don’t manage, call on me again

I’m trying to trigger a relay with this but the relay just stays on all the time. Any ideas what could be causing this?

do you mean you cannot switch it off?

I had wired it up incorrectly - thank you though.

1 Like

great. Sorry my earlier reply might have been late but I was on holiday

What if I want to control the LED with a script? Is this possible while using this binding? I want to write a script that turns off the normally on LED when the state of a thing changes.

Hi

Would you happen to know if this process is purely for Raspberry Pi, or can I try it on any Linux based SBC?

(In my case, an ODroid C2 or XU4)

Cheers :smile:

@MDAR I don’t know about support from the GPIO binding, but you could maybe use my MQTTany. Currently the GPIO module only supports RPi but can easily be modified to support other boards if there are Python 3 libraries available to control their GPIOs.

Let me know if you are interested and if you already know of any Python libraries.

1 Like

Thanks Michael.

I have limited knowledge of anything outside of GUI things.
So python is outside of my skill set.

Thanks for the offer.

No I mean I would make the changes. Looks like there is a library. I’ll get to this next, I’m just working on a module for DS18x20 sensors right now. Keep an eye on the github for the odroid support getting added.

@MDAR keep an eye on this issue over on github for updates.

1 Like