more G-Labs products

Author Topic: virtual/GPIO module  (Read 3534 times)

December 13, 2014, 05:45:30 PM
Read 3534 times

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Is there an easy way to use a GPIO as a module?  I have a motion sensor that has a relay switch that indicates it's status.  I want to use a couple GPIO pins to control a module and then use that module in code.  I'm sure I could see the pin status in code, but I want to address this as though it were any other module so no special code is required to swap from x10, zwave, GPIO, etc.

December 13, 2014, 11:51:33 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Apparently I disabled the built-in module that does just this.  After turning it on, I have a question.  When I go to add the GPIO module, I can only add pins 4 and 20-28 (I believe).  I'll have to look up the raspi specs, but is that all that are available or did I do something wrong?

December 14, 2014, 04:46:41 PM
Reply #2

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
if you're using latest HG sd card image gpio #4, #17, #18 cannot be used since these are allocated for 1-wire bus and IR transceiver.
All other gpios are free.
If you updated to r443, the gpio modules app will now report a popup message when cannot allocate a gpio.

g.

December 14, 2014, 05:01:20 PM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I'm on r441 right now.  I looked at the code and it looked like there were quite a few GPIO's that were listed that didn't show up in the UI.  I added a GPIO module yesterday to see if it would show up (pin 4), but the only others available are 21-25.

It looks like there aren't as many GPIO's as I thought.  I was looking at the Raspi documentation on GPIO's and it had a picture that looked like there were 17 available GPIO's.  But, after reading further, it looks like that's not quite right.  I saw the header and thought all were available, but the only usable ones are 4, 17, 18, 21, 22, 23, 24 and 25.  Since 4, 17, and 18 are not available in HG, that means that 21-25 are the available options.

I'll play with it and see if it works for me.

December 28, 2014, 02:54:09 AM
Reply #4

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I'm having an issue setting up the GPIO's correctly in HG.  I used a sample code from the O'Reilly cookbook to generate a verification that shorting GPIO's work on my board via a Python script (see attached).  When I set up GPIO25 in HG as IN+ (input with pull-up), which is the same setup as the script, I get a result...but it's backwards.  HG sees GPIO25 shorted to ground as 0% on (off) and unshorted as 100% on (on).

My setup is simple.  I have a female jumper connecting GPIO25 to ground.  Please advise on what I am obviously doing wrong.

December 30, 2014, 08:28:51 PM
Reply #5

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi bkenobi,

when using internal pull-up (IN+) the button is connected to GND and to the GPIO pin, but you'll get 1 when released and 0 when pressed.
when using internal pull-down (IN-) the button is connected to 3V3 and the GPIO pin then  you'll get 0 when released and 1 when pressed.

Don't ask me why it is like this =D I simply dunno.

Cheers,
g.

January 03, 2015, 08:47:42 PM
Reply #6

Wibo

  • ***
  • Information
  • Full Member
  • Posts: 95
Hi all,

I think I can clarify.

When you use pullup(IN+) it means the chip will internally connect a resistor to 3V3, there by the logical level will be 1, only something stronger then the resistor is able to force the voltage to 0V and that's the button.
With a pull down the stronger force has to be connected with the 3V3 else it will stay 0

In other words, by choosing pullup(IN+) or pull(IN-) down you're choosing the default logical level, pullup = 1 and pull down = 0

January 08, 2015, 06:31:50 AM
Reply #7

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
So if I want the default to be 0 and the relay on to result in 1, does that mean I should use a pull-down (IN-) and connect the relay to GPIO25 and 3.3v?

EDIT:  The reason I ask is because I tried this configuration and the module in HG always shows a value of 1.  I found several guides that show that if I hook the relay up to GPIO25 and 3.3v with a pull-down internal resistor, I should get the configuration I need (default 0, relay on 1).  Is there something I'm missing, or is HG not working as intended?
« Last Edit: January 08, 2015, 07:42:11 AM by bkenobi »

January 10, 2015, 07:21:56 PM
Reply #8

Wibo

  • ***
  • Information
  • Full Member
  • Posts: 95
Hi bkenobi,

I tested your setup on Raspberry Pi B+ with revision 432 of HomeGenie and it works without problems.
Generic sensor is showing the value "0" and when the switch/relay connects it shows "1"

Attached a simple schematic to show how my wiring was done.

Best regards,
Wibo.

January 10, 2015, 09:16:24 PM
Reply #9

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I was able to get this working a couple days ago actually.  I believe the issue was that I was using an incorrect pinout for the GPIO header.  I was trying to connect to pin 1 which showed as 3.3v on the diagram I was using, but I believe it may have actually been 5v (or at least not 3.3v).  When I switched to a different 3.3v pin, GPIO25 responded as expected.

Thanks for following up!