petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Mon Dec 03, 2018 4:31 am

Hmmm. I am getting very good results detecting 24vac with the a3700. I'll create a diagram of my circuit and post it. I have previously posted a picture of the 16 channel circuit board I made. Perhaps I am not understanding what your issues are.

Brandon92
Posts: 770
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: GPIO.input voltage levels vs edge detection

Mon Dec 03, 2018 7:00 am

petermeigs wrote:
Sun Dec 02, 2018 9:43 pm
I'd like to add an LED to show which circuit is active. My idea is to use an LED in the pullup circuit between Vcc and Vo. It seems to me that there were concerns about this approach last August. This addition to the LED will have the LED on when the AC circuit is on. This is because Vo will be driven low, allowing current to pass through the LED. When there is no current on the AC side, Vo should float. There is a pullup turned on on the MCP2017, so I would expect no current flow.

Does this make sense?
It is a workable idea?
Are there any problems with doing this?
Is there a better way to add an LED to this circuit?

Thanks --
PS. The circuit is labeled 5v but I would be using 3.3v from my raspberry pi.
I would not use that. I would use a real pull up resistor and add a resistor with a led in series parallel to that pull up resistor. Then you know for sure the state of the output of the device. With a led in series you will use a certain voltage across the led.
And this might give you a unexpected result. So, the problem is there will always be a certain current flow through the input of your mcp and the a3700. What could cause a voltage drop. What means that you will not have the vcc voltage on that line. And if the current is to small, the led could also not conduct an then your input is really floating and you could measure anything.

Your are by the way not 100% correct about your explanation about the distance and high voltage. But, I will come back to that later.

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Mon Dec 03, 2018 6:35 pm

Brandon92 wrote:
Mon Dec 03, 2018 7:00 am
... I would use a real pull up resistor and add a resistor with a led in series parallel to that pull up resistor. ...
Vo of the A3700 connects to a GPIO pin on the MCP23017. When Initializing the MCP23017, I turn on the internal 100k ohm weak pull-up resistor. (See data sheet for MCP23017, section 3.5.7, for Register 3-7., http://ww1.microchip.com/downloads/en/d ... 01952c.pdf) Do you think this internal resistor would be sufficient or do I need additional, lower ohm value resistor as well?

In the pcb I built, I have an external 4.7k pull up resistor but I'm now starting to think that that resistor is unnecessary. Do you think this is correct or that the 4.7k resistor serves a significant purpose?

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Tue Dec 04, 2018 2:53 pm

I thought I'd post a single channel of my circuit for detecting presence of 24vac by a raspberry pi. I built a 16 channel version of this.
This circuit would work for higher (or lower) AC voltages if the resistors R1 and R3 are chosen accordingly. You can find how to do this calculation earlier in this topic and in Application Note 1004 "Threshold Sensing for Industrial Control Systems with the HCPL-3700 Interface Optocoupler" http://www.avagotech.com/docs/AV02-3699EN. Don't forget to choose a capacitor C2 rated for your peak voltage which is 1.4 times the stated AC voltage.

I am also including python code that I use to log the on and off state of my 12 ac channels. I plan to add two flowmeters to this circuit. The flowmeter is a simple reed switch that I plan to connect at 24vac. Since I am only using 12 of my 16 channels, I can use 2 of them to interface to the flowmeters. In the python code, these are intended to be on position 15 and 16.

The flowmeter (Hunter HC100FLOW) will be at the end of a 100ft (33m) shielded cable and will close the reed switch and then reopen it once every US gallon of water that passes.

During the operation of this system, a valve will open selecting one of my 12 zones to be watered as the python code will get a signal as to which valve opened. Then, as the water flows, there will be a number of ticks representing the number of gallons that flow. The rate of flow can be calculated as well (this calculation is not present yet in the code). When the valve shuts off, a completion signal will be received and the valve controller will go to the next zone.

So far the code only logs the events.

Code: Select all

#!/usr/bin/env python3
import smbus
import sys
import RPi.GPIO as RPIGPIO
import time
import traceback
import queue
# you may need to install pytz
# sudo apt install python3-pip
# pip3 install pytz
import pytz
import threading
from datetime import datetime
from datetime import timedelta
from datetime import timezone

# code to duplicate all stdout output to logfile
class Logger(object):
    def __init__(self):
        self.terminal = sys.stdout
        self.log = open("logfile.log", "a")

    def write(self, message):
        self.terminal.write(message)
        self.log.write(message)
        self.log.flush()

    def flush(self):
        #this flush method is needed for python 3 compatibility.
        #this handles the flush command by doing nothing.
        #you might want to specify some extra behavior here.
        pass

running = True      # set to false to stop background thread
bus = None          # smbus object set up in init()
starttime = None    # datetime object of when program started
useDebug = True     # print debug lines
useThread = False   # use internal thread.  If False, then we are driving mcp23017 externally 

ticCounters = [ 15, 16 ] # these are the indexes for 1 gpm ticCounters for flowmeters

# create a 16 entry dict with keys being valveNumber and value 0
# this will hold the starttime for a valve
valveTimer = {i + 1: 0 for i in range(16)}

currentValve = 0
currentFlow  = 0

eventqueue = queue.Queue()

SIMFLOWPORT = 21 # gpio21 used to signal flow tick    
DEVICE_ADDRESS = 0x20   # MCP23017 address to use
# default addresses

BANKA   = 0
BANKB   = 1
NOTIFY  = 2 # notification pin = TRUE means ready to send FALSE means done

IODIR      = 0x00 # Pin direction register A
IPOL       = 0x02 # Input polarity regsiter A
GPENTEN    = 0x04 # Interrupt on change pins A
IOCON      = 0x0a # Config register A  Bank, Mirror, SEQOP, DISSLW, HAEN, ODR, TPOL, N/U
GPPU       = 0x0c # 100k ohm pullups A
GPIO       = 0x12 # GPIO pins
OLAT       = 0x14 # output latch register
INTF       = 0x0e # interupt flag register

# IOCON I/O Expander Configuration bits
iocBANK   = 0x80 # if 1 registers are in different banks
iocMIRROR = 0x40 # if 1 INT pins are ORed togetther
iocSEQOP  = 0x20 # if 1 address pointer does not increment
iocDISSLW = 0x10 # if 1 Slew rate disabled

iocHAEN   = 0x08 # if 1 Hardware address enable MCP23S17 only
iocODR    = 0x04 # if 1 open drain output, overrides INTPOL
iocINTPOL = 0x02 # if 1 Active-high (sets polarity of INT output pin


# map of gpioports given bank

GPIOINT = {
    BANKA : 22, # gpio connected to port A interrupt line.
    BANKB : 27,  # gpio connected to port A interrupt line.
    NOTIFY : 4,  # notification from other side
}

# map of banks given gpioport
# this map is calculated from GPIOINT to provide fast inverse lookup
# 

GPIOINTREV = {gpioport: bank for bank, gpioport in GPIOINT.items() }

# same code without dict comprehension
# GPIOINTREV = {}
# for bank, gpioport in GPIOINT.items():
#     GPIOINTREV[gpioport] = bank

MASKBITS = {
    BANKA : 0x00FF, # BANKA are low order bits
    BANKB : 0xFF00, # BANKB are high order bits
}

def utc_to_local(utc_dt):
    return utc_dt.replace(tzinfo=timezone.utc).astimezone(pytz.timezone("America/Los_Angeles"))

# get current time as a formatted string
def logTime():
    timeStr = time.strftime('%Y/%m/%d %H:%M:%S')
    return timeStr

# put bits in BANKB byte and a copy in BANKA
# for tidyness, mask off any bits not in low order byte
def bothBanks(bits):
    bits = bits & 0xff
    return (bits << 8) | bits

# see https://wiki.python.org/moin/BitManipulation for these bit manipulation functions
# gets the number of bits needed to hold number
def bitLen(int_type):
    length = 0
    while (int_type):
        int_type >>= 1
        length += 1
    return(length)

# clears all but the lowest bit set
def lowestSet(int_type):
    low = (int_type & -int_type)
    lowBit = -1
    while (low):
        low >>= 1
        lowBit += 1
    return(lowBit)

# given an integer, generate a list of the bits set
# where the low order bit is bit zero
def bitsSet(int_type):
    bitsset = []
    val = int_type
    len = bitLen(val)
    while  len > 0:
        ls = lowestSet(val)
        bitsset += [ ls ]
        val = val - (1 << ls)
        len = bitLen(val)
        # print (ls, val, len)
    return bitsset


# these routines try to deal with the MCP23017 as a 16bit register rather than 2 8 bit registers
# intbits determine whether to read reg for bank A or B or both.
# returns 16 bit value with B in high order and A in low order
def readREG(port, intbits = 0xFFFF):
    # need to separate bus reads because we don't want to clear an interupt we aren't handling
    # intbits will be non-zero in top 8 and/or bottom 8
    pinAdata = 0
    pinBdata = 0
    if (intbits >> 8) & 0xFF:
        pinBdata = bus.read_byte_data(DEVICE_ADDRESS, port + BANKB)
    if intbits & 0xFF:
        pinAdata = bus.read_byte_data(DEVICE_ADDRESS, port + BANKA)
    return (pinBdata << 8) | pinAdata

# intbits determine whether to set reg for bank A or B or both.
# sets B from high order and A from low order if any bit is set in the corresponding by
# int intbits

def writeREG(port, data, intbits = 0xFFFF):
    # only write to the BANK we need to
    if (intbits >> 8) & 0xFF:
        bus.write_byte_data(DEVICE_ADDRESS, port + BANKB, (data >> 8) & 0xFF)
    if intbits & 0xFF:
        bus.write_byte_data(DEVICE_ADDRESS, port + BANKA, data & 0xFF)
    return None

# read next item in the queue and print it out
# queue consists of a list per entry
# processing in the callback routine is minimized by doing string formatting when extracting from the queue
# that way, we can clear the interupt as quickly as possible

def getQueueItem(eventqueue):
    queueitem = eventqueue.get()
    itemtime, gpiolevel, bank, intfBA, pinBA, gpioport = tuple(queueitem)
    # get time difference object and calculater elapsed time string
    mstime = itemtime - starttime
    elapsed = "%d"%mstime.seconds + ".%06d"%mstime.microseconds
    message = ""
    # check to see if any bits changed other that those causing the interrupt
    message = " bitsset=" + str(bitsSet(pinBA))
    if (intfBA | pinBA) != intfBA:
        message += ", intFA !~ pinBA"
    strtime = utc_to_local(itemtime).strftime('%Y/%m/%d %H:%M:%S')
    print ("%s Elapsed=%s, gpiolevel=%d, bank=%d, intfBA = 0x%04x, pinBA = 0x%04x, gpioport=%d%s"%(strtime, elapsed, gpiolevel, bank, intfBA, pinBA, gpioport, message))
    return queueitem


def my_callback(gpioport):
    # Note: Multiple interupts can occur simultaneously
    global bus
    global valveTimer       # dict of all valves to hold timers (one-based)
    global currentValve     # current open valve (one-based) 
    global currentFlow      # flowmeter ticks

    # we have the gpioport but need the bank
    # bank 0 BANKA   MCP23017
    # bank 1 BANKB   MCP23017
    # bank 2 NOTIFY  Signal raised on GPIO4

    bank = GPIOINTREV[gpioport]  # we got an interupt on a port.  Look yp which bank that is
    nowtim = datetime.utcnow()
    gpiolevel = RPIGPIO.input(GPIOINT[bank])  # read the CGPIO pin that cause the interupt. Only used for extra info
    myChgBits = []
    # if bank = NOTIFY, it means we got a signal other than mcp23017
    if bank == NOTIFY:
        intfBA    = 0x0000
        pinBAbits = 0x0000
        eventqueue.put([nowtim, gpiolevel, bank, intfBA, pinBAbits, gpioport])
    else:
        maskBits = MASKBITS[bank]
        intfBA = readREG(INTF, maskBits)    # findout which pin changed
        myChgBitsSet = bitsSet(intfBA)      # get a list of the bits set
        pinBAbits = readREG(GPIO, maskBits) # get the BANK's pin value and clear interrupt, so don't delay much
        # myBitsSet = bitsSet(pinBAbits)    # get a list of the bits that are now on
        for thisBit in myChgBitsSet:        # check each changed bit was turned on or off
            thisValve = thisBit + 1
            if thisValve in ticCounters:
                intfBA &= ~ (1 << thisBit)        # turn off interupt bit
                if 1 << thisBit & pinBAbits:      # bit was turned on, so bump counter
                    pinBAbits &= ~ (1 << thisBit) # turn off pin bit
                    print("Tic: %d" % (thisValve))
                continue                        # no more to do with this counter
            if 1 << thisBit & pinBAbits:        # bit was turned on, so start timer
                if not valveTimer[thisValve]:   # make sure it was not alreeady on
                    valveTimer[ thisValve ] = nowtim # set time it turned on
                    currentValve = thisValve    # the current open valve
            else:                               # this valve just went off
                if thisValve == currentValve:   # checking to make sure the valve that turned off makes sense
                    currentValve = 0            # no more current valve (global)
                    if valveTimer[thisValve]:       # if it was already off, do nothing
                        thisValvetimer = valveTimer[thisValve]
                        valveTimer[thisValve] = 0
                        elapsedTime = nowtim - thisValvetimer
                        if useDebug:
                            print("%s Valve %d on for %d:%d:%d.%06d" % (utc_to_local(thisValvetimer).strftime('%Y/%m/%d %H:%M:%S'),
                                                                        thisValve, 
                                                                        elapsedTime.seconds / 60 / 60,   # hours
                                                                        elapsedTime.seconds / 60 % 60,   # minutes
                                                                        elapsedTime.seconds % 60,        # seconds
                                                                        elapsedTime.microseconds ) )     # microseconds
                    
                elif currentValve:
                    print("WARNING: Valve %d got a shutoff but current valve is %d" % (thisValve, currentValve)) 
                    print("Checking Valve %d" % thisValve)
                    print(str(valveTimer))
                else:
                    print("WARNING: Valve %d got a suprious shutoff with no current valve" % (thisValve)) 
                    print("Checking Valve %d" % thisValve)
                    print(str(valveTimer))
                    # got a spurious shutoff but nothing was on.
                    pass 

        if intfBA:  # we've turn off bits for flowmeter counters so if thats all there were, don't send event
            #  add to event queue
            eventqueue.put([nowtim, gpiolevel, bank, intfBA, pinBAbits, gpioport])
    
    return

class MyThread(threading.Thread):
    def run(self):
        global running
        print("{} started!".format(self.getName()))              # "Thread-x started!"
        while running:
            for i in range(1):
                if not running:
                    break
                time.sleep(.01)                                     # Pretend to work for a decade of seconds
            for i in range(5):
                if not running:
                    break
                time.sleep(.01)
                RPIGPIO.output(SIMFLOWPORT, RPIGPIO.LOW)
                time.sleep(.001)
                RPIGPIO.output(SIMFLOWPORT, RPIGPIO.HIGH)
        print("{} finished!".format(self.getName()))             # "Thread-x finished!"


def init():
    global bus
    starttime = datetime.utcnow()

    RPIGPIO.setwarnings(False)
    RPIGPIO.setmode(RPIGPIO.BCM)

    RPIGPIO.setup(SIMFLOWPORT, RPIGPIO.OUT, initial=RPIGPIO.HIGH)    # set GPIO24 as output
    RPIGPIO.output(SIMFLOWPORT, RPIGPIO.HIGH)          # make it high

    bus = smbus.SMBus(1)    # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)

    # port A & B all in input bits
    writeREG(IODIR, 0xFFFF)

    # reverse input values.  This is because A3700 is low when upper threshold is detected
    writeREG(IPOL,  0xFFFF)

    # Activate all internal pullup resistors at Port A & B for output:
    writeREG(GPPU, 0xFFFF)

    # disable interupts on change
    writeREG(GPENTEN, 0x0000)

    # clear any previous interrupts
    time.sleep(.1)
    writeREG(OLAT, 0x0000)
    time.sleep(.1)
    writeREG(GPIO, 0x0000)
    time.sleep(.1)
    pinBAbits = readREG(OLAT)
    time.sleep(.1)
    pinBAbits = readREG(GPIO)
    time.sleep(.1)

    # I/O Expander config register. Set INT pins NOT internally connected, Interupt polarity Active-high
    # for both A & B
    writeREG(IOCON, bothBanks(iocINTPOL)) #  | iocMIRROR))
    # enable interupts on change
    writeREG(GPENTEN, 0xFFFF)

    time.sleep(1)
    # set up all interrupt
    for bank, thisGPIOINT in GPIOINT.items():
        RPIGPIO.setup(thisGPIOINT, RPIGPIO.IN, pull_up_down=RPIGPIO.PUD_UP)    # set interrupt from MCP23017
        # when a changing edge is detected on OPTO1 port, regardless of whatever
        # else is happening in the program, the function my_callback will be run
        cbType = RPIGPIO.RISING
        if thisGPIOINT == GPIOINT[NOTIFY]:  # want both rising and falling for NOTIFY
            cbType = RPIGPIO.BOTH
        RPIGPIO.add_event_detect(thisGPIOINT, cbType, callback=my_callback)
    pass


def main():
    global bus
    global starttime
    sleeptime = 0.1  # 5ms
    print("start=========================================================")
    init()
    starttime = datetime.utcnow()
    if useThread:
        mythread = MyThread(name = "MyThread")
        mythread.start()

    while True:
        elapsedtime = datetime.utcnow() - starttime
        time.sleep(sleeptime)
        while not eventqueue.empty():
            queueitem = getQueueItem(eventqueue)
    pass

if __name__ =='__main__':
    try:
        sys.stdout = Logger()
        main()
    except KeyboardInterrupt:
        pass
    except:
        traceback.print_exc()
        pass
    running = False
    time.sleep(2)
    RPIGPIO.cleanup()
    print ("Done")
    sys.stdout.log.close()
    sys.stdout = sys.stdout.terminal
    print ("...")

Attachments
SingleChannelRPI-MCP23017-HCPL3700.PNG
SingleChannelRPI-MCP23017-HCPL3700.PNG (43.69 KiB) Viewed 3067 times

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: GPIO.input voltage levels vs edge detection

Thu Dec 06, 2018 6:57 am

Brandon92 wrote:
Mon Dec 03, 2018 7:00 am
petermeigs wrote:
Sun Dec 02, 2018 9:43 pm
I'd like to add an LED to show which circuit is active. My idea is to use an LED in the pullup circuit between Vcc and Vo. It seems to me that there were concerns about this approach last August. This addition to the LED will have the LED on when the AC circuit is on. This is because Vo will be driven low, allowing current to pass through the LED. When there is no current on the AC side, Vo should float. There is a pullup turned on on the MCP2017, so I would expect no current flow.
Does this make sense?
It is a workable idea?
Are there any problems with doing this?
Is there a better way to add an LED to this circuit?
I would not use that. I would use a real pull up resistor and add a resistor with a led in series parallel to that pull up resistor. Then you know for sure the state of the output of the device. With a led in series you will use a certain voltage across the led.
And this might give you a unexpected result. So, the problem is there will always be a certain current flow through the input of your mcp and the a3700. What could cause a voltage drop. What means that you will not have the vcc voltage on that line. And if the current is to small, the led could also not conduct an then your input is really floating and you could measure anything.

Fake pullup vs Real pullup V0.1

01. A fake pull up consists of a current limiting resistor, usually 500R to 1k, in series with an LED which is a nonliner diode.
02. Let us suppose we use 500R, and Vcc 5V, and Vout Low almost zero, Vout High almost 5V.
03. When Vout low, the current passing the fake pair is usually around 5mA to 20mA, depending on the LED.
04. Let us suppose the fake LED and resistor gang passes 5mA.
05. That means the equalivant resistance is 5V/5mA = 1k.
06. That means the equivalent resistance of the diode at this and only at this point of 5mA is around 500R.
07. And in case the diode current is smaller, the equivalent resistance is bigger.
08. Suppose Vo is connected to a the base of a NPN transistor switching circuit, then the fun begins.
07. Consider Vo High (which is not really High voltage level, but ridiculously high impedance, or non conducting, or floating), then we have three little guys in series, 500R at the top (Vcc) , LED (which is actually a diode) in the middle, and another diode like thing (base to emitter) at the bottom (Ground).
08. Vout High does not pull down current, but current flows from Vcc to R, D1, and D2, to Ground.
09. This time the current passing three guys is smaller than 5mA, perhaps 1 mA, and the non linear diode resistancess might jump to 10k!
09. If the non linear variable resistances of D1, and D1 at this point 10K are much bigger than R, then we have a potential divider giving 2.5V at Vo!.
10. All newbies could not understand why they get 2.5V instead of the expected 5V. And of course if they do understand, then they are no newbies! :mrgreen:
11. The tricky thing is that a LED or diode is a non linear thing. Newbies need to understand the "Load Line" thing first.
12. https://en.wikipedia.org/wiki/Load_line_(electronics)

...
Attachments
loadline_2018dec0601.jpg
loadline_2018dec0601.jpg (103.73 KiB) Viewed 3052 times
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: GPIO.input voltage levels vs edge detection

Sat Dec 08, 2018 3:08 am

tlfong01 wrote:
Thu Dec 06, 2018 6:57 am
I'd like to add an LED to show which circuit is active.
I would not use that. I would use a real pull up resistor and add a resistor with a led in series parallel to that pull up resistor.
Fake pullup vs Real pullup V0.1
01. A fake pull up consists of a current limiting resistor, usually 500R to 1k, in series with an LED which is a nonliner diode.
07. Consider Vo High (which is not really High voltage level, but ridiculously high impedance, or non conducting, or floating), then we have three little guys in series, 500R at the top (Vcc) , LED (which is actually a diode) in the middle, and another diode like thing (base to emitter) at the bottom (Ground).
09. This time the current passing three guys is smaller than 5mA, perhaps 1 mA, and the non linear diode resistancess might jump to 10k!
09. If the non linear variable resistances of D1, and D1 at this point 10K are much bigger than R, then we have a potential divider giving 2.5V at Vo!.
11. The tricky thing is that a LED or diode is a non linear thing. Newbies need to understand the "Load Line" thing first.

Fake Pull Up connected to 2N2222 switching buffer

Suppose Vout with fake pull up of (1k + LED) is connected to Vin of a say, 2N2222 with Rin = 1k, and the NPN BJT driving Vo is now high impedance/disconnected/floating, then Vo will be around 2.5V instead of newbie's expected 5V!

Transistor as a switch - Electronics Tutorials
https://www.electronics-tutorials.ws/tr ... ran_4.html

Why pull base of BJT switch? - StackExchange
https://electronics.stackexchange.com/q ... 6011#56011
...
Attachments
2n2222_switching_2018dec0802.jpg
2n2222_switching_2018dec0802.jpg (132.26 KiB) Viewed 2993 times
I am an electronics and smart home hobbyist.

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Sat Dec 08, 2018 6:34 pm

Thanks for the additional info. I am studying this.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: GPIO.input voltage levels vs edge detection

Sun Dec 09, 2018 12:28 pm

petermeigs wrote:
Sat Dec 01, 2018 6:45 pm
I'm going to assume "high voltage" is anything above 50v dc or 36v ac. Certainly 120vac and even more certainly 240vac are high voltage.
So at 24vac, I think we agreed we are ok, right?

Back EMF Magnitude

I have decided not to play with 220VAC any more. My cheap KY109 relays are now switching 12VAC and 24VAC. I read that the back EMF is usually two to three times the applied voltage. In other words, 12V, 24V, 220V becomes 36V, 72, and 600V.

Just now I played with switching 2VDC of a 3V3 electromagnetic buzzer, and found the back EMF becomes 10V. I have little experience in AC circuits, so my conclusions might be wrong.

...
(Back EMF Magnitude) RE: DETECT CURRENT ON RASPBERRY PI - tlfong01 2018-Dec-09 Sun
viewtopic.php?f=91&t=224976&p=1402105#p1402122
I am an electronics and smart home hobbyist.

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Wed Dec 12, 2018 12:45 am

With regard to the fake pullup using an LED, I have finally been able to get my head around it. What I neglected to consider was that there were BOTH the A3700 floating Vo pin 6 and the GPIO input pin on the MCP23017.

When the A3700 has Vo low, it is sinking current and this will provide the flow needed to light the LED and to drive the GPIO pin on the MCP23017 low. The LED is on and the MCP23017 is reading that the A3700 is telling it that there is AC voltage detected across pins 1 and 4.

So far so good and I thiis what I understand to have been said in the first few points in the discussion.

When the A3700 is NOT detecting an AC voltage, its as if pin 6 Vo is not connected (more or less). Little or no current flows and no voltage is supplied on pin 6. This would be the job of the pullup resistor and with a real resistor, a current limited 3.3 v are provided. The MCP sees this a HIGH and we are happy that all is good. However, with the fake pullup (ie diode plus resistor) the nonlinear resistance makes the resistance very high until the forwarding voltage is reached.

I tested with a fake pullup and saw the led flicker. This makes sense because now the pullup is trying to supply current to the gpio pin. I can confirm the values read by the MCP23017 on that pin were a bit flakey. Since the LED would flicker when the AC current is off, there is no point in having it there even if the MCP23017 GPIO pin reads were solid.

I measured the current through the LED, a green B4303F5 with a 2v forward voltage at 10Ma.
For 3.3v power from the rpi and a 4.7k Ohm resistor in series, I measured .3mA, meaning the LED plus resistor were 11k Ohms and subtracting off my 4.7k resistor, we see 6.3 k ohms due to the LED.

For the next test, I had a 4.7k resistor in parallel with an LED + 2.2k resistor series combination. This means while the LED is on we have 6.3k Ohms plus 2.2k Ohms for a total of 8.5k Ohms. The 4.7k resistor is in parallel with that (see my picture if the words are making you crazy) yields 1/(1/4.7k + 1/8.5k)) ==> (4.7k x 8.5k) /(4.7k + 8.5k) => 3.01 k Ohms. At 3.3v we should see about 1ma sunk by A3700 Vo when there is ac voltage present. I measured this at 2 ma so at least this is in the right order of magnitude. I'm guessing we can use the non-linearity of the LED resistance to explain the difference

When I connected this all up, as in my picture, the LED worked as desired and the operation my python code was nice and tidy. I'm glad to get to the bottom of this and appreciate all the help. -- Thanks --

I have to say I am not happy with the current usage at 2 mA. There is a lot of discussion about how much current is available at 3.3v. The discussion speaks in term of 50 - 100 mA but there is a lot of hand waving for these numbers. I have measured current drawn by my MCP23017 when I have connected 12 A3700's and I recall it (can't find my notes) being safely below that. That said, if I add 16 LED's at 1 mA additional each, and if all are on at the same time, that is a large part of my current budget.. Perhaps there are some nice low power LED's I haven't seen yet.
Attachments
withLED.png
withLED.png (73.07 KiB) Viewed 2943 times

Brandon92
Posts: 770
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: GPIO.input voltage levels vs edge detection

Wed Dec 12, 2018 8:14 pm

petermeigs wrote:
Sat Dec 01, 2018 6:45 pm
Brandon92 wrote:
Fri Nov 30, 2018 7:01 pm

You need indeed take a closer look at the components that you are using at high voltage. But you need also physical more space between the part. So, the clearance and the creeping distance need to be according to the safety standard. For example you could make in the pcb a milling slot under the "optocoupler". And there are a couple other things you need to do.

By the way, the spacing on your current pcb is to small for high voltage. So the high voltage can "jump" to a other input or to your low voltage part.
Thanks for the helpful comments. In summary review, I hear you suggesting:

1. Make sure the components are suitable for the voltage to be used.
2. Consider the possibility of arcing or other physical jumping in the spacing of components, especially ones with high voltage.

I'm sure what "creeping distance" or "milling slot" are but I am guessing that you mean
1. creeping distance: Solder slightly overflowing its solder point.
2. milling slot: a groove physically cut into the pcb between the high voltage side and the logic side to increase the air distance a jump would need to make.

I'm going to assume "high voltage" is anything above 50v dc or 36v ac. Certainly 120vac and even more certainly 240vac are high voltage.

So at 24vac, I think we agreed we are ok, right?

I don't have any high voltage plans but I'll keep this all in mind as I go forward. Again -- Thanks
As promises, my explanation:
Well that not what I meant with creeping distance. I could give you a textual explanation. However, I found the picture on page 6 from this application note a better way. And beside that, they explain also more information about this topic. And also in this document IEC60601-1*
This is also a intressting document IPC-A-610D*

* however it is not the most resent version

Glad to hear you found out what the purpuse is of the "real pull up". And by the way, you led is 180 degrees rotated in you schematic ;) .
For a project I used this LED and it was powered by 3.3V with a 650r resistor. And for that project I need still to increase the value of the resistor, because it is pretty bright.
By the way, is it possible to add the schematic as a attachments here. So, I can change something so that it looks better. If you want. And if it is not possible to attache, you can open the file in notepad and copy the code here :geek:

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Wed Dec 12, 2018 11:05 pm

Brandon92 wrote:
Wed Dec 12, 2018 8:14 pm
Glad to hear you found out what the purpuse is of the "real pull up". And by the way, you led is 180 degrees rotated in you schematic ;) .
For a project I used this LED and it was powered by 3.3V with a 650r resistor. And for that project I need still to increase the value of the resistor, because it is pretty bright.
By the way, is it possible to add the schematic as a attachments here. So, I can change something so that it looks better. If you want. And if it is not possible to attache, you can open the file in notepad and copy the code here :geek:
Pesky symbols! Thanks for catching the diode direction and the tips about the led. And also the high voltage comments. If I ever go there, I'll be sure to research the details to be safe.

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Thu Dec 13, 2018 4:34 pm

I can't embed Eagle 9.0.1 source for the schematic in the message directly as the character limit is 60,000 characters and the attachment does not support a txt or sch file type

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: GPIO.input voltage levels vs edge detection

Fri Dec 14, 2018 4:15 am

Brandon92 wrote:
Wed Dec 12, 2018 8:14 pm
For a project I used this LED and it was powered by 3.3V with a 650r resistor. And for that project I need still to increase the value of the resistor,

MCP23017 Port Status LEDs

For my MCP23017 projects, I am using 3mm rectangular LEDs, with the following current limiting resistors, Red = 1k2, Yellow = 560R, Green = 4k7, Blue = 1k2.

/ to continue, ...


Appendices LED Spec

KingBright 2x5mm Through-Hole Rectangular LED
https://www.kingbright.com/content/listitem/psearch/254

Super Bright Red
https://www.kingbright.com/attachments/ ... er.9A).pdf

High Efficiency Red (Iv (mcd) @10mA = 7)
https://www.kingbright.com/attachments/ ... r.16A).pdf

Yellow (Iv (mcd) @10mA = 4)
https://www.kingbright.com/attachments/ ... r.15B).pdf

Green (Iv (mcd) @10mA = 30)
https://www.kingbright.com/attachments/ ... r.11B).pdf

Blue (Iv (mcd) @10mA = 55)
https://www.kingbright.com/attachments/ ... er.6B).pdf
...
Attachments
mcp23017_test_2018dec1401.jpg
mcp23017_test_2018dec1401.jpg (163.55 KiB) Viewed 2883 times
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: GPIO.input voltage levels vs edge detection

Fri Dec 14, 2018 5:24 am

tlfong01 wrote:
Fri Dec 14, 2018 4:15 am
Brandon92 wrote:
Wed Dec 12, 2018 8:14 pm
For a project I used this LED and it was powered by 3.3V with a 650r resistor. And for that project I need still to increase the value of the resistor,
For my MCP23017 projects, I am using 3mm rectangular LEDs, with the following current limiting resistors, Red = 1k2, Yellow = 560R, Green = 4k7, Blue = 1k2.
High Efficiency Red (Iv (mcd) @10mA = 7)
Yellow (Iv (mcd) @10mA = 4)
Green (Iv (mcd) @10mA = 30)
Blue (Iv (mcd) @10mA = 55)


The Blue LED Guy

Shuji Nakamura - Wikipedia
https://en.wikipedia.org/wiki/Shuji_Nakamura

Shuji Nakamura (中村修二 1954) is a Japanese-born American electronic engineer and inventor specializing in the field of semiconductor technology, professor at the Materials Department of the College of Engineering, University of California, Santa Barbara (UCSB), and is regarded as the inventor of the blue LED, a major breakthrough in lighting technology.Together with Isamu Akasaki and Hiroshi Amano, he is one of the three recipients of the 2014 Nobel Prize for Physics "for the invention of efficient blue light-emitting diodes, which has enabled bright and energy-saving white light sources

Nakamura has also worked on green LEDs, and is responsible for creating the white LED and blue laser diodes used in Blu-ray Discs and HD DVDs.
".

...
Attachments
the_blue_led_guy_2018dec1401.jpg
the_blue_led_guy_2018dec1401.jpg (78.55 KiB) Viewed 2878 times
I am an electronics and smart home hobbyist.

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Fri Dec 14, 2018 8:57 am

It looks like there are lots of choices for LED's. I'll keep these in mind.

My next step is to test the reed valve on the Hunter HC100FLOW meter. The cable I will use to connect to an A3700 is 100 feet of AWG 22 3 conductor shielded cable. I get the feeling that 100 feet is not a very long distance to deal with so I'm comforted by that thought.

If I can use 24 vac in the reed switch, I can connect to a free spot on my 16 channels MCP23017 via the same A3700 setup I am using for detecting which valves are on. The current needed is very low. I have not been able to get much information about the reed switch from Hunter. They only seem to know how to wire it up into their own controller. They guessed that 5vdc were used across the reed switch that closes briefly one every US gallon.

While reading about reed switch, it seems the concern is that arcing between the contacts would reduce the life of the switch. Relays would suffer from this problem as well. From what I could determine, AC is kinder to contacts than DC because the arc is self-extinguishing.

I am hoping that going from 5 vdc to 24vac (keeping the RMS factor of 1.414 in mind for a max voltage of 34 volts) and knowing that the current will be low, I will be ok.

The manufacturer has suggested that I ground (literally to earth, a copper pipe or a steel rod driven into the ground) the shielding of the cable. This is an area that I'm not sure what I am getting into. I have the cable and plan to try it out on the spool with various voltages. Perhaps I should buy some stand alone reed switches to test them to see how hardy they are. The Flowmeter is a bit expensive and I'd hate to destroy its reed switch.

This is an area, I could definitely benefit for anyone's knowledge or experience in dealing with any surprises that are likely to crop up.
Attachments
Hunter.jpg
Hunter.jpg (60.17 KiB) Viewed 2865 times

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Tue Dec 18, 2018 5:11 pm

I've been reading about reed switches and arcing. I do not know the specifications for the reed switch in the Hunter Flowmeter. I opened it up to look at it and I see that there are two reed switches so I guess one is a spare. They are sealed in epoxy so there is no hope of getting any kind of model number. The current allowed at 24vac by the A3700 is low compared to the weakest reed switch i have read about so I think I would be safe.

However, I see that getting 24vac for this purpose will not be easy as the Rachio does not have a connection for this purpose. It will be much easier to get 5vdc from the Raspberry pi. Effectively, we are looking at a normally open switch at the end of 100 ft (30 m) of shielded 3 conductor wire with the 5vdc close to the A3700. I can mock this up on my workbench but would be using the 100 ft of wire in the coil.

I would connect through appropriate resistors (values still to be calculated) to the dc pins on the A3700 (pins 2 and 3).
I'm wondering if this length of wire in a coil will have a capacitance or inductance that I should consider. Perhaps there is a need for a flyback diode here?

I will be testing this on my workbench but this is starting to get outside of the area where my intuition is useful and would appreciate any comments from others.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: GPIO.input voltage levels vs edge detection

Thu Dec 20, 2018 8:03 am

petermeigs wrote:
Tue Dec 18, 2018 5:11 pm
I've been reading about reed switches and arcing. I do not know the specifications for the reed switch in the Hunter Flowmeter. I opened it up to look at it and I see that there are two reed switches so I guess one is a spare. They are sealed in epoxy so there is no hope of getting any kind of model number. The current allowed at 24vac by the A3700 is low compared to the weakest reed switch i have read about so I think I would be safe.

However, I see that getting 24vac for this purpose will not be easy as the Rachio does not have a connection for this purpose. It will be much easier to get 5vdc from the Raspberry pi. Effectively, we are looking at a normally open switch at the end of 100 ft (30 m) of shielded 3 conductor wire with the 5vdc close to the A3700. I can mock this up on my workbench but would be using the 100 ft of wire in the coil.

I would connect through appropriate resistors (values still to be calculated) to the dc pins on the A3700 (pins 2 and 3).
I'm wondering if this length of wire in a coil will have a capacitance or inductance that I should consider. Perhaps there is a need for a flyback diode here?

I will be testing this on my workbench but this is starting to get outside of the area where my intuition is useful and would appreciate any comments from others.

Reed and A37 Testing Suggestion

You seem to be doing 2 diff things.

1. check if a reed is closed.

2. check if A37 out changes from high to low.

For both, 2N2222 can do the job.

For A37, connect to 2N2222 base resistor to A37 output.

For reed, connect 2N2222 base resistor through reed to Vcc.


(2N2222 )RE: GPIO.INPUT VOLTAGE LEVELS VS EDGE DETECTION tlfong01 2018-Dec-08
viewtopic.php?f=32&t=219744&start=375#p1401800
I am an electronics and smart home hobbyist.

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Thu Dec 20, 2018 9:52 pm

tlfong01 wrote:
Thu Dec 20, 2018 8:03 am
You seem to be doing 2 diff things.

1. check if a reed is closed.

2. check if A37 out changes from high to low.
Well, since I have 16 A3700 positions on my circuit but only need 12 of them, I thought I would convert 2 of them to handle the reed switch. Since the A3700 handles hysteresis very well, I'm hoping solve bounce and other circuit anomalies well.

Also, I have figured out how to write the python code to "see" both the irrigation valve going on and off as well as being able to count the 1 US gallon per tick.

So laziness is happening here. I can easily rework(rewire) 2 of the A3700 positions to handle 5v DC on pins 2 and 3 instead of 24v AC on pins 1 and 4. I'm hoping for your (or any other kind person's) experience here on what I might expect.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: GPIO.input voltage levels vs edge detection

Fri Dec 21, 2018 8:50 am

petermeigs wrote:
Thu Dec 20, 2018 9:52 pm
tlfong01 wrote:
Thu Dec 20, 2018 8:03 am
You seem to be doing 2 diff things.

1. check if a reed is closed.

2. check if A37 out changes from high to low.
Well, since I have 16 A3700 positions on my circuit but only need 12 of them, I thought I would convert 2 of them to handle the reed switch. Since the A3700 handles hysteresis very well, I'm hoping solve bounce and other circuit anomalies well.

Also, I have figured out how to write the python code to "see" both the irrigation valve going on and off as well as being able to count the 1 US gallon per tick.

So laziness is happening here. I can easily rework(rewire) 2 of the A3700 positions to handle 5v DC on pins 2 and 3 instead of 24v AC on pins 1 and 4. I'm hoping for your (or any other kind person's) experience here on what I might expect.
I think your project is basically in 2 parts. Part 1 is to detect AC24 volt. I tried and found everything OK. Except I can only use A37 to detect AC24V on or off, but not both, and the selection of the series experience is awkward. I originally plan to use A37 for my 220VAC pump, for which I think A37 is a good choice. But now I am using 12V/24V DC pump, so A37 is not at all suitable.

For Part 2, it a simple. You have A37 Vo pull up to check 0V 5V. That is basic logic circuit. For reed switch, you can use A37 to pull up reed in series with a 4k7, just treating read as a push button. Again basic logic circuit.

You application is very very low frequency, perhaps at most 100Hz I think. You can always use software debouncing to take care of any reed bouncing.

In short, you can already finish the hard 90%, the remaining 10% is easy.

I have no experience in 30 meter long wires carrying a push button. I guess it is simple, except not sure if the long wire, even grounded, might still catch lighting.

I am not sure if you have 16 solenoid valves all place apart, and each 30m from Rpi. I would have fun using ESP8266, and not use the boring, though may be effective long wires.

Sorry for the typos.

Update dec22

I forgot the very hard part mcp23017. But you have already written programs playing with the registers and also the interrupts, so I guess you should not have big problems in this part, unless later you want to connect more that one mcp23017, and also other i2c devices such as real time clock DS3231, then you might have data transmission problems.
I am an electronics and smart home hobbyist.

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Tue Dec 25, 2018 5:14 am

I have done a test using 100 ft (33 m) of shielded cable. I am using 5vdc from the raspberry pi connecting to a normally-open push button switch (to simulate the reed switch) at the end of the cable. I am connecting to pins 2 and 3 of the A3700 (DC+ and DC-) through a 47 Ohm resistor on each pin.

Using the same python code as I was using for detecting 24VAC on pins 1 and 4, I can reliable detect if the push button is pressed and seem to get no bounce at all.

I have attached a picture of my test setup. When I press the button, I read 3.8 mA through pins 2-3 and measure 4.89 vdc. This is much lower power than the 7.7mA (estimated as I don't have an AC ammeter) at 24vac (peaking at 34v). Since the Hunter Support team told me they guessed. that the reed switch handled 5 vdc, this leads me to prefer the 5vdc solution. It's convenient because I have 5vdc handy from the raspberry pi and 3.8 ma is easily handled on the 5vdc bus. If I had to use 24vac, I would have to find a connection point inside the Rachio controller and this would probably void my warranty.
cableTest.jpg
cableTest.jpg (71.04 KiB) Viewed 2513 times
Unless anyone suggests these is a problem with this arrangement, I think I will go forward with this solution. I plan to ground the shielding of the 100 ft (33 m) cable. I do not think it is susceptible to lightning or other external influences because the cable will be in the crawl space under my home and only exposed to the outside for less than 3 ft (1 m). I'll have to rework two of the sockets for the A3700 to accept dc input on pins 2 and 3 instead of AC input on pins 1 and 4.

By the way, my valves are in two banks, with 6 valves in each bank all very close to each other. The cables to power the valve solenoids (24 vac) are also 100 ft (33 m) long , 1 each to each of the two banks. These are 13 conductor wires, intended to be used as 12 individual wires
and 1 common wire.

The connection to the A3700 and to the raspberry pi thorough the MCP23017 is all within 1 ft ( .3 M) of the Rachio controller.

Anyway, my next step will be digging in my garden to install the flowmeter. Wish me luck!

Brandon92
Posts: 770
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: GPIO.input voltage levels vs edge detection

Wed Dec 26, 2018 2:35 pm

I think the switch will operate just fine on 5V and will not damaged itself.
When you use a shielded cable, it is importend that you connect the shield at both and to the ground. If you dont connect it, the shield doesn't work as you want. And you can use a normal cable instead.

You can add a (bidirectional) TVS diode to protect the input of the A3700. This will clamp the voltage to a certain voltage and protect the input from a over voltage.

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Mon Dec 31, 2018 5:12 pm

Brandon92 wrote:
Wed Dec 26, 2018 2:35 pm
...
You can add a (bidirectional) TVS diode to protect the input of the A3700. This will clamp the voltage to a certain voltage and protect the input from a over voltage.
...
Remember that the reed switch is at the end of a 100ft (30 m) cable. I don't expect to have any other components at that end of the cable

The A3700 will easily handle 10vdc on the DC pins 2 and 3. I am using 5vdc from the Raspberry Pi for the reed switch circuit so I am surmising that any voltage clamp that keeps the voltage lower than 10vdc but allows higher than 5vdc should be good for this circuit.

In this circuit diagram, I have added a 1N4734A which should be a 5.6v +/- 5% 1W Zener diode. I placed it directly to ground (and I hope this time I got the polarity right) but separated it by my 47 Ohm resistor from the A3700. Is this what you had in mind?

Your comment mentioned a bidirectional TVS Diode. I could not find a suitable device with leads (surface mount will be inconvenient) but I suppose I could make one out of two 5.6v zeners.

Also, I was a little worried that the 5vdc on the Raspberry Pi might need protecting as well. Would it make sense to add another zener on the 5vdc side of the reed switch?
SingleChannelRPI-MCP23017-HCPL3700wReedSwitchAndTVSdiode.PNG
SingleChannelRPI-MCP23017-HCPL3700wReedSwitchAndTVSdiode.PNG (73.07 KiB) Viewed 1787 times

Brandon92
Posts: 770
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: GPIO.input voltage levels vs edge detection

Mon Dec 31, 2018 9:10 pm

petermeigs wrote:
Mon Dec 31, 2018 5:12 pm
Remember that the reed switch is at the end of a 100ft (30 m) cable. I don't expect to have any other components at that end of the cable

The A3700 will easily handle 10vdc on the DC pins 2 and 3. I am using 5vdc from the Raspberry Pi for the reed switch circuit so I am surmising that any voltage clamp that keeps the voltage lower than 10vdc but allows higher than 5vdc should be good for this circuit.

In this circuit diagram, I have added a 1N4734A which should be a 5.6v +/- 5% 1W Zener diode. I placed it directly to ground (and I hope this time I got the polarity right) but separated it by my 47 Ohm resistor from the A3700. Is this what you had in mind?

Your comment mentioned a bidirectional TVS Diode. I could not find a suitable device with leads (surface mount will be inconvenient) but I suppose I could make one out of two 5.6v zeners.

Also, I was a little worried that the 5vdc on the Raspberry Pi might need protecting as well. Would it make sense to add another zener on the 5vdc side of the reed switch?
Well, if you are using dc you can use a normal tvs. But if you are using ac you need a bidirectional tvs. And you need to place this across the input of the a3700, close to the connector. So, that if there is a voltage spike (somewhere else) the voltage is limited by this part. And this will protect the input of the device. When I need a tvs diode I take often first a look at this manufacture: littelfuse

I would also be very careful when you take the voltage of the Rpi over a long distance. If there is something wrong with the wire for example, then your Rpi could be damaged.

By the way, are you using in software debounce? If not, you need to take a look at it. Or you can implement it into your hardware.

petermeigs
Posts: 96
Joined: Thu Mar 23, 2017 1:34 pm
Location: Los Altos, California

Re: GPIO.input voltage levels vs edge detection

Mon Dec 31, 2018 9:38 pm

Brandon92 wrote:
Mon Dec 31, 2018 9:10 pm

Well, if you are using dc you can use a normal tvs. But if you are using ac you need a bidirectional tvs. And you need to place this across the input of the a3700, close to the connector. So, that if there is a voltage spike (somewhere else) the voltage is limited by this part. And this will protect the input of the device. When I need a tvs diode I take often first a look at this manufacture: littelfuse

I would also be very careful when you take the voltage of the Rpi over a long distance. If there is something wrong with the wire for example, then your Rpi could be damaged.

By the way, are you using in software debounce? If not, you need to take a look at it. Or you can implement it into your hardware.
Thanks for the response. I'm not worried about the a3700 on the AC side as its datasheet and app notes lead me to believe that it is good for much higher voltages than the 24vac I am using.

With regard to the 5vdc, I will ponder this a bit. I could just provide 5vdc from another leftover 5vdc phone charger and let the A3700 provide the opto-isolation as it does for the 24vac. Then I would not need any part of the reed switch circuit in common with the rpi. And the more I write about it here, the more I like this idea.

The A3700 implements Schmidt triggers. I have used push-buttons for testing along with just touching wires together to get the on-off pulse I wanted. The A3700 gives a very clean output on Vo, with one and only one interrupt per pulse.

By the way, Happy New Year to All!

Brandon92
Posts: 770
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: GPIO.input voltage levels vs edge detection

Mon Dec 31, 2018 9:48 pm

A okay, a separate power supply is also a very good idea. You could also use something like this power supply. This will give you also a isolation between the two power rails.

If there is a schmidt trigger, then you are good :)

You also a happy new year.

Return to “Python”