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

Re: GPIO.input voltage levels vs edge detection

Tue Jan 01, 2019 6:53 pm

Brandon92 wrote:
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.
Thanks for the tip. It turns out I am using a power supply with two usb sockets https://www.ebay.com/itm/232126014258 anyway so the extra 5v power is easy to come by. I haven't cracked one of these open but one hopes that a circuit failure of some sort on one USB side won't be able to cause any damage (other than perhaps loss of power) on the other.

I started using these power supplies after reading that 5v for the Raspberry Pi power supply might be a little low. I have observed the lightening bolt (and dmesg messages) for undervoltage at boot time on the raspberry pi.

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

Re: GPIO.input voltage levels vs edge detection

Tue Jan 01, 2019 8:21 pm

For the Rpi you also need a usb cable that can carry the current that is required for the Rpi. If the wires are to thin in that cable it will cause a to large voltage drop across that wire. And this will trigger that warning on your screen. Assuming that the power supply has a stable output voltage arcross the full output range.

Anyway, those power supply's share often on main power supply and the usb outputs are probably parallel to each other. So, if there is one short on the output. The other one is also "disabled" by that.

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

Re: GPIO.input voltage levels vs edge detection

Mon Jan 14, 2019 12:14 pm

Brandon92 wrote:
Tue Jan 01, 2019 8:21 pm
1. Anyway, those power supply's share often on main power supply and the usb outputs are probably parallel to each other.
2. So, if there is one short on the output. The other one is also "disabled" by that.

PSU and Back EMF etc

1. If you already have a transformer based 24VAC power available, one way is to rectify and filter it to DC24V, then use a DC to DC short circuit protected regulated power supply module to step it down to 5V, then this PSU is floating and its ground is not connected to any other PSU's ground. I think this way your Rpi has the lowest risk.

2. And if you don't use wall warts, but 110VAC to 5V PSU modules with short circuit protection, then one short circuit would not shut down everything.

3. I am playing with 5~12V, 0.5~2A solenoids. I am worrying the high current back EMF is strong. So I am checking it out. You might take a look if interested.

Back EMF picture - Solenoid Lock - tlfong01 2019jan10
viewtopic.php?f=91&t=230325&start=25#p1414587

220VAC in 12VDC 1A out PSU Wiring Notes
viewtopic.php?f=91&t=230325#p1412068

...
Attachments
psu_scheme_2019jan1401.jpg
psu_scheme_2019jan1401.jpg (191.19 KiB) Viewed 1554 times
I am an electronics and smart home hobbyist.

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

Re: GPIO.input voltage levels vs edge detection

Tue Jan 15, 2019 2:21 pm

tlfong01 wrote:
Mon Jan 14, 2019 12:14 pm
Brandon92 wrote:
Tue Jan 01, 2019 8:21 pm
1. Anyway, those power supply's share often on main power supply and the usb outputs are probably parallel to each other.
2. So, if there is one short on the output. The other one is also "disabled" by that.

PSU and Back EMF etc

1. If you already have a transformer based 24VAC power available, one way is to rectify and filter it to DC24V, then use a DC to DC short circuit protected regulated power supply module to step it down to 5V, then this PSU is floating and its ground is not connected to any other PSU's ground. I think this way your Rpi has the lowest risk.

2. And if you don't use wall warts, but 110VAC to 5V PSU modules with short circuit protection, then one short circuit would not shut down everything.
Well not really in this case. We are talking about a power supply like this:
Image

And depending on the type that he is using. The power for both ports is coming from one internal power supply. So they are not separated. And depending on the implementation of the over-current protection. It could shut down one USB port, but it is also possible that the main power supply has the protection. And the other port is also powered down.

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

Re: GPIO.input voltage levels vs edge detection

Tue Jan 15, 2019 3:18 pm

Brandon92 wrote:
Tue Jan 15, 2019 2:21 pm
And depending on the type that he is using. The power for both ports is coming from one internal power supply. So they are not separated. And depending on the implementation of the over-current protection. It could shut down one USB port, but it is also possible that the main power supply has the protection. And the other port is also powered down.

Just a short reply.

Ah yes, I misunderstood your configuration. In your case, I guess it is just like a usb hub, where all wires inside are connected in parallel. But I am not sure. Actually I always wondered how the neutral line is connected inside the plug. Perhaps I should tear down one, ... :)

Update 2019jan16hkt1005

And it is like the official Rpi PSU

https://shop.pimoroni.com/products/rasp ... wer-supply

...
Attachments
rpi_psu_official_2019jan1601.jpg
rpi_psu_official_2019jan1601.jpg (181.96 KiB) Viewed 1503 times
I am an electronics and smart home hobbyist.

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

Re: GPIO.input voltage levels vs edge detection

Wed Jan 16, 2019 10:38 pm

My two port power supply looks similar to the Sweex Brandon92 is showing except mine had US plugs (although it is rated 100-240VAC 50-60Hz) so with a plug adapter it will work anywhere. It has not Ground pin.

I guess I am missing the concern here. If either socket goes down, it does not matter to me that the other is also down. This is because without power to my water meter reed switch, there is nothing I can measure and without power to the Raspberry Pi, the ticking of the reed switch will go unrecorded. Both are necessary for the system to work.

As a result of everyone's help, (thank you for your insights) I see the point of separating the power used for the raspberry pi and the 24vac detection circuit from the power used for the reed switch at the end of a 30m cable. This will help protect the raspberry pi (a 35USD item).

I'm not too worried about protecting the A3700 as they are not too expensive and I can easily replace one in the socket it it goes bad. The A3700 is an opto-coupler so it should protect the low voltage dc side from the higher voltage AC side if there are spikes.

We have discussed a lot of concerns about connection to ground but the two port USB power supply has no ground pin anyway and I'm not sure how having one would affect (either for good or harm) the 5vdc circuit.

Even the Sweex Brandon92 shows us has no ground. BTW, looking at the picture of the "Official" RPI powersupply, the US plugs have no grounds either and for the UK/Hong Kong plug, the pin that goes into the socket hole for ground looks like it is a non-conductor there for the purpose of unlocking the powered holes in the socket.

I think I am missing something here.

PS. Went skiing in Park City, Utah for a week (Near Salt Lake City). We had great weather except for a worrisome storm while driving the 13 hours to get there. I've been away from my project. I'm back now and when the winter rains here calm down a little, I'll go out and start digging to install the first water meter.

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 Jan 17, 2019 7:24 am

petermeigs wrote:
Wed Jan 16, 2019 10:38 pm
1. My two port power supply, ... It has not Ground pin.
2. If either socket goes down, ... without power to my water meter reed switch, there is nothing I can measure and without power to the Raspberry Pi, the ticking of the reed switch will go unrecorded.
3. Separating the power used for the raspberry pi and the 24vac detection circuit from the power used for the reed switch at the end of a 30m cable. This will help protect the raspberry pi (a 35USD item).
4. I'm not too worried about protecting the A3700 as they are not too expensive and I can easily replace one in the socket it it goes bad. The A3700 is an opto-coupler so it should protect the low voltage dc side from the higher voltage AC side if there are spikes.
5. We have discussed a lot of concerns about connection to ground but the two port USB power supply has no ground pin anyway and I'm not sure how having one would affect (either for good or harm) the 5vdc circuit.

System Power Monitoring and System Ground Discussion

1, 2, 3. I agree you need both PSU working to do the job. So as you mentioned long time ago, perhaps we need a UPS (based on Li ion cell 18650 or National lead battery).

As I concluded long time ago, after playing with A3700, that it is very good for detect main power 110/220VAC. For for low voltage 12/24V AC/DC, I would prefer other devices, such the one below.


Microcontroller [Power] Supervisort Circuit
http://ww1.microchip.com/downloads/en/d ... 11187f.pdf

* Precision monitoring of 3V, 3V3, and 5V0 power
* 7 Voltage trip apoints available.


4. I agree.

5. I have never understood the grounding problem. I have Googled and Wikied many times and still found things confusing. I need to google harder again. One of my problems is that I have a 220VAC fish tank pump, submerged in water. This pump has no ground pin at the mains. So should I submerge a ground line into the fish tank? Need to do some research later. :mrgreen:
I am an electronics and smart home hobbyist.

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

Re: GPIO.input voltage levels vs edge detection

Sun Feb 17, 2019 5:46 am

Well, I'm back working on my irrigation sensor. I have reworked my board a bit, removing the connections an d resistors for the last two positions. I only needed 12 and I have room for 16 so I am converting two to use for my reed switch. From our discussion earlier, I've decided to use a separate 5 vdc circuit for the reed switch and so have removed the resistors to pins 1 and 4 of the A3700 that were to detect 24 vac. I have tested two 47 ohm resistors to pins 2 and 3 and they detect 5vdc just fine. The reed switch is at the end of a 100 ft (30m) shielded cable.
reedSwitch.png
reedSwitch.png (56.92 KiB) Viewed 1154 times
In the diagram, the reed switch is connected to the 5v from the Raspberry pi but in my circuit, I will have it on a separate 5vdc power supply. This is not relevant for my question though. There is also a 5.6v zener diode to serve as an overload protection.

I am wondering if I should put the reed switch between the 5vdc source and the positive pin of the A3700 or if I should put it between the negative pin of the A3700 and ground. In the normal operation, it seems like it would make no difference but perhaps there is a convention or best practice that would prefer it on one side or another.

BTW, my two port 5 vdc power supply has no ground with regard to its 120 vac plugin. I will run the Raspberry Pi on one port and have the other port provide voltage to two reed switch circuits. The two reed switch will never be counting pulses at the same time but I suppose they could be left in a closed state when the circuit switches from one bank of 6 water valves to another.

If anyone has a comment on this I would be grateful to hear it.

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

Re: GPIO.input voltage levels vs edge detection

Mon Feb 18, 2019 1:56 am

After mentioning it as a possibility in the last post, I got to worrying about what it would mean if we were unlucky and the water flow stopped such that the reed switch was in a closed position. In an earlier post, I read 3.8 mA through pins 2-3 on the A3700 and measured 4.89 vdc. This would mean a load of about 18.6 mWatts. I will have two flow meters running off one of the two ports of the 5.1 vdc/3.0A power supply so if I'm very unlucky, there could be a 37 mWatt drain on my power supply. I wonder if its ok to just ignore this?

Alternatively, I could consider a simple circuit that shuts off the current flow through pins 2-3 after a short while (say 1/2 Sec). In normal operation, that should be longer than the time the reed switch is closed so most of the time, this timeout is not used. Does anyone have any ideas about a simple circuit that I could use to accomplish this task.

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

Re: GPIO.input voltage levels vs edge detection

Mon Feb 18, 2019 5:45 am

I just found a reference to a 555 timer. Perhaps this will work for me:
http://www.learningaboutelectronics.com ... ircuit.php

User avatar
rpdom
Posts: 13750
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO.input voltage levels vs edge detection

Mon Feb 18, 2019 7:26 am

The 555 is a very old chip design. It could use a fair amount of current itself. There is a 7555 which is the CMOS version of the same chip with greater voltage range and much lower current consumption.

Alternatively you could look into using something like a basic PIC microcontroller chip and program that to do what you want. Those chips are very cheap and take a tiny amount of current (a few microamps when idle), you just need to learn to program them.
Signature is on holiday.

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

Re: GPIO.input voltage levels vs edge detection

Tue Feb 19, 2019 6:39 am

Thanks for the tip. The 7555 is much cheaper too. Of course, I only need two so far and in one case I get 12 for $7.00 USD and in the other I get 30. My wife is starting to notice my parts drawer.

I'm not too worried about the 5 vdc current draw for the circuit itself as the power supply can handle it easily. I was just worried about a current flowing through my water meter reed switch if I was unlucky enough that the meter rotor came to rest with the reed switch closed. It closes once per gallon of flow.

I have this nagging feeling I needn't worry about any of this as the power going through the reed switch in pretty low. The water meters are the most expensive part of my whole project at more than $100 USD per meter. Some folks commenting have pointed out less expensive ones but being a lazy guy, I don't want to be digging in my garden replacing failed meters so I'd like the one I use to be pretty hefty and the Hunter fits that bill.

I'm pretty new to a lot of this and don't have a good feel about best practice design considerations.

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

Re: GPIO.input voltage levels vs edge detection

Sun Feb 24, 2019 2:41 am

Here is my circuit that includes a timer to shut off the reed switch after about .5 secs if we are unlucky and the water meter comes to rest with the reed switch closed.
Reed switch with shutoff after .5 secs.png
Reed switch with shutoff after .5 secs.png (55.78 KiB) Viewed 1045 times
For the time calculation I read https://www.instructables.com/id/555-Timer/#step3. I built this circuit and tested it.
For the circuit itself, I used http://www.learningaboutelectronics.com ... ircuit.php I used a 10uF capacitor instead of the 100uF one used in the sample bringing the time down to .5 secs from about 5.

The idea behind this circuit is that in normal operation, the reed switch will go on and off once per gallon as the water flows though the meter. Normally the reed switch will open before the timer elapses, cancelling the timer. and making the OUT signal pin 3 go low. The A3700 will detect this and signal the MCP23017, generating an interrupt in the RPI and we will be able to count a tick in our python code.

If we are unlucky, and the water stops flowing with the reed switch closed, the timer will expire and will drive the OUT signal low on pin 3. As in the case above, the A3700 will detect this and signal the MCP23017, generating an interrupt in the RPI and we will be able to count a tick in our python code.

If we did not have the timer, pin 2 on the A3700 would stay high, possibly for days, with current flowing through the reed switch, with unknown consequences with regard to wear on the reed switch.

I'm interested in any comments about adding this circuit. Is this a useful addition or is this overkill? Would it provide additional protection against transient voltages on my 100 ft cable?

The NE555 draws only a few milliamps out of 3.0 amps available so power consumption is not an issue here.

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

Re: GPIO.input voltage levels vs edge detection

Sun Feb 24, 2019 5:13 pm

It occurs to me that the A3700 in this last circuit perhaps is not needed at all. The NE555 would be operating at 5vdc but we could use a 3.3v zener to drag its voltage down to 3.3v. Then we can connect the OUT pin 3 directly to GPA0 on the MCP23017. We would have to deal with the polarity of the pin (i.e, previously a low value meant a voltage was present across pins 2-3 of the A3700 ) but that can be done in software. A pull-up/pull down resistor may still be needed. I'm not sure if the .01uF capacitor across pins 5 and 8 of the A3700 is still needed in the circuit.

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

Re: GPIO.input voltage levels vs edge detection

Tue Feb 26, 2019 2:36 pm

Personally I think that your solution with the external timer is overkill and not needed. You could use better one of this protection circuit : https://www.digikey.com/en/articles/tec ... lectronics And connect it directly to the MCP with figure 11 ;) .

And if they designed you water meter correctly. The reed switch is designed to "carry" a small current and switch "all" the time. For example take a look at the how they measure the speed of a bike. With a reed switch and a magnet :)

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

Re: GPIO.input voltage levels vs edge detection

Tue Feb 26, 2019 5:27 pm

Thanks. I was hoping someone with more experienced eyes would offer an opinion and the benefit of that experience here.

Having stared at the NE555 in front of the A3700, I recently got the idea that perhaps the A3700 is not even needed at all in the reed switch case. The A3700 was originally there to make 24 vac on/off detection possible by the MCP23017 and the A3700 dealt with both the ac and with making nice edges so the MCP23017 could detect it properly. It had the added advantage that it meant only a small adjustment to the python code handling the MCP23017 to count the 1 gallon "ticks" of the water meter reed switch.

I'm looking at the idea of using the NE555 instead of the A3700 rather than "in addition to". I would use a 3.3v Zener diode to get the output voltage of the NE555 down from 5v to 3.3v. I plan to do a little testing to see if the NE555 has nice edges with no bounce.

Meanwhile, I'll look over the digikey article and see how it would fit into the picture. Perhaps as you suggest I won't need either NE555 or A3700.

I don't really want to go digging in my garden to install the meter until the rains stop. In our area, our rains come mostly November through March. It rarely gets below freezing but dealing with the mud is more off-putting. I won't be able to do it in April so this means installing the meter in early May. Anyway, I have time to continue to research to try to get this right.

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

Re: GPIO.input voltage levels vs edge detection

Tue Feb 26, 2019 10:34 pm

If you want to use a NE555 take the 7555 version of it. That one will work fine on a lower voltage level.

I don't know exact how the you water sensor will make one pulse per x liter. So, if it is a very short pulse and your Rpi is working on something else you could miss that pulse. (But this depants on the sensor). You could use a (7) 555 to make the pulse longer. In the so called monostable 555 Timer configuration.

A other option would be to use the 555 as a "Bistable 555 Timer (flip-flop)". As showed in the same link. But this require two pins of the MCP. One to read the output of the 555 and the other to reset the 555.

You could make this as difficult and advance as you want :) But you could see it as a simple push button.

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

Re: GPIO.input voltage levels vs edge detection

Wed Feb 27, 2019 7:23 am

A 7555 was mentioned before but I had ordered the NE555 before I knew about the 7555 so I thought I just test with the parts I had.
I am using a Hunter HC-100-FLOW Meter https://www.hunterindustries.com/irriga ... flow-meter and it has a maximum flow rate of 34 US Gallons per minute and the ticks are 1 per US Gallon (3.79 liters). I think they are slow enough so there won't be any issues missing ticks on the Raspberty Pi

The on/off of the reed switch through an MCP23017 and I have that set up to be interrupt driven using callbacks. I've done simulations of a raspberry pi zero driving the MCP23017 to test if ticks would be dropped. Assuming my tests were valid, I think I can sustain a much higher tick rate. I tested pulse width as well in my simulation and found that the MCP23017 definitely needed a wide enough pulse. I did not check to see how wide the flow meter pulse is but I will definitely check that now. Thanks for the suggestion.

As it turns out, I have only 12 valves but room for 16. This means I have 4 free MCP GPIO pins available. I was going to use two to listen to the ticks but if I need to, I can use the last remaining two for a reset. I doubt it will be necessary because I think I recall the reed switch is closed for an adequate amount of time. Again, I'll be checking to make sure.

With regard to a lower voltage level: I would like to run the reed switch at 5dvc because then I can have a separate power supply for the water meter. I have been running into the problem that if I do that, I need to reduce the voltage to 3.3v for the MCP23017. The A3700 effectively does that for me and provides opto-isolation. With a x555, I won't have the opto-isolation if its output goes directly to the MCP23017 and I'll need 3.3v on its GPIO pins.

In the end, I think, I'll be using the A3700 without any timers but since I embarked on this path, it turns out to be an interesting learning experience.

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

Re: GPIO.input voltage levels vs edge detection

Wed Feb 27, 2019 1:20 pm

I was able to get some more clarity on the way the water meter ticks work. Every 1 US gallon, the reed switch closes and stays closed for 0.3 gallons. It then opens again for .7 gallons. If water is flowing at the maximum of 34 US gallons per minute. Then the reed switch closes once per 1.74 times per second. ( 60 / 34 ) and the switch is closed 30% of that time or 0.53 seconds and open 70% or 1.23 seconds.

This means that there will be no problem in counting the ticks but it also means there is a 30% probability that when the water flow stops, it will stop with the switch closed. I though at first glance, it would rarely happen but now I see it will be not unusual at all.

So I am left wondering if it's ok to leave a current flowing through the A3700 (and the reed switch) or if I should take steps to cut it off with the timer. I measured the current earlier and I recall it to be around 3.8 mA at 4.8 vdc.

I can definitely only consider the edge when the reed switch first closes and ignore when it opens. The partial gallon in question will be counted in its entirety for a particular valve and not some other but I suppose I can say that statistically, the counts will average out and its the best I can do with a 1 gallon measurement granularity.

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

Re: GPIO.input voltage levels vs edge detection

Thu Feb 28, 2019 12:49 pm

petermeigs wrote:
Wed Feb 27, 2019 1:20 pm
So I am left wondering if it's ok to leave a current flowing through the A3700 (and the reed switch) or if I should take steps to cut it off with the timer. I measured the current earlier and I recall it to be around 3.8 mA at 4.8 vdc.

I can definitely only consider the edge when the reed switch first closes and ignore when it opens. The partial gallon in question will be counted in its entirety for a particular valve and not some other but I suppose I can say that statistically, the counts will average out and its the best I can do with a 1 gallon measurement granularity.
Yes, it is fine to have a current flow through the A3700 and the reed switch. They are designed for this, to give the user a indication if the there is a input voltage or a magnet (in case of the reed switch). So, you don't need to worry about it. And the "cheapest" reed relay at farnell can switch 500mA.

And if you are using a additional power supply in combination with the A3700 is a good choise. But you might need to connect the switch to the DC input of the A3700 and not to the AC input. This is because the voltage drop inside the full bridge rectifiers might be to much to trigger the output.

As you said, you are only interested when the switch is closing and you don't care about the other state of the switch.

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

Re: GPIO.input voltage levels vs edge detection

Thu Feb 28, 2019 8:09 pm

Thanks for the comments. It is really helpful to have extra eyes looking at my project. I will be using the dc inputs as you suggested. I have drawn it this way in my schematic of Sat Feb 23, 2019 6:41 pm. However, I won't bother with the NE555. I was just getting ready to test how "bouncy" that item was but since its not needed, I'll skip that.

I will also leave out any over/under voltage protection and leave that job to the A3700. The Hunter specs do not even require shield cable for the 100 ft (30m) lengths I'm using and I have tested with the whole reel on my desk. Admittedly, it is coiled up here and in the implementation it will be stretched out but I would think that would make any transient voltage issues worse so I am testing a harder case that will be implemented.

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

Re: GPIO.input voltage levels vs edge detection

Mon Mar 04, 2019 6:31 am

I got interested in how the NE555 timer would behave if I used it so I put together a test circuit. I twas pretty easy to do because its similar to other tests I have been doing all along. In this one I have two usb ports, one supplying power to the Raspberry pi, and another supplying 5vc to the NE555 time. The idea is to frequently measure the output voltage of the timer from the time it turns on to the time it expires and the timer turns off. I use a MCP3008 to measure the voltage.

The first issue I ran into was that I'm measuring 0-5vdc but since I'm running the MCP3008 on a rpi, I must connect it at 3.3 vdc and the MCP3008 can only measure voltages from 0-Vdd (i.e 3.3v). I did a bunch of reading and even though there is a Vref, it cannot be greater than Vdd.

I used two methods to get the voltage into the right range. The first was to use a 3.3v zener diode. While this truncated voltages higher than 3.3v, it gave a very clean graph.

The second method was to use a voltage divider with r1 = 10000 and r2 = 20000 making a 1.5 ratio voltage divider. My power supply puts out about 5.1 v so the max possible output of the divider is 3.4v and measuring it with a voltmeter, I never saw the NE555 ever put out more than 4.5v.

The graph here was not as clean when turning on. I would see a little stutter when coming on but then it would settle down. Perhaps I need a capacitor to smooth out the voltage.

I deleted the divider version so do not have the graph for that.

I have attached the graph and the circuit using the 3.3v zener diode

I don't think I'll use the NE555 timer at this time but I think its a clean operating device so perhaps I'll have a use for it in the future.
Attachments
NE555voltageTest.png
NE555voltageTest.png (25.34 KiB) Viewed 817 times
NE555voltageTestGraph.PNG
NE555voltageTestGraph.PNG (11.63 KiB) Viewed 817 times

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

Re: GPIO.input voltage levels vs edge detection

Thu Mar 07, 2019 12:25 pm

Hello,

First of all, I would advice you to draw a schematic in such a way that the power rail is at the top and the ground is at the ground of the schematic. For example see this simple schematic. This make it more readable.

And in your current diagram you could eliminate the zenerdiode. Because it will not operate as you want in this case. Lets say that the NE555 has a output voltage of 5V (what is not true in the real world) the 5V goes direcly into the MCP by the 10k resistor. And the zenerdiode will not clamp the voltage here. Yes, there is indeed 3.3V across the zenerdiode and the rest is across the resistor. So, the MCP will see the 5V. Here is a link to the correct connection.

And you should be able the use a voltage divider at the output of the NE555, maybe you need to lower the resistor value. So that you will load load the output of the NE555. This could give a better result. When you compare the two methods the current with the zenerdiode is 12mA while with the voltage divider is 0.15mA.

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

Re: GPIO.input voltage levels vs edge detection

Thu Mar 07, 2019 4:57 pm

Thanks for the comment. I'll use your suggestion for schematics in the future.

With regard to the zener: I'll need to study your comments. You are correct that the output voltage of the NE555 running at 5.2v is lower than Vcc. I manually measured it at 4.x with my voltmeter. However, I did test this circuit. As a first step, I manually measured the output voltage with my voltmeter again and saw that it was 3.3v (the zener voltage).

I then ran my code to capture MCP3008 values. It:

1. Sets up GPIO and I2c.
2. Closes relay for 5 seconds.
3. While relay is closed, measures MCP3008 Ch0 in a loop with small delay between measurements. Timestamp and voltage Measurements are captured to an array.
4. Once the time is up, it writes the array to a file.

My manual measurements were with an inexpensive digital multimeter. The point of the manual tests were to make sure I do not damage my rpi nor my other devices. This is also why I use the relay: so that the circuit is never on for very long.

What I do not understand is that if 5v is presented to the ch0 via the 10k resistor, why do I get readings from the MCP3008 corresponding to 3.3v?

My explanation to myself was that the zener drained off voltages above 3.3v and only left 3.3v for MCP3008 ch0 but perhaps I am not thinking about this correctly.

Anyway, I recently purchased an Arduino which is capable of reading 5vdc. I plan to use UUGear Daemon in the rpi to control voltage measurements with the Arduino Nano. See http://www.uugear.com/uugear-rpi-arduino-solution/ At the moment, I am embroiled in issues running the Arduino IDE from raspberry pi.

With that, I should be able to get measurements of the output of the NE555 without the need for a divider nor for the zener.

By the way, when I tried a voltage divider, I did not get as clean a graph as I did with the zener. I used a 20k and a 10k resistor to take the output of the NE555 to 2/3 to get it into the right range for an MCP3008 running at 3.3v. Do you think 20k/10k resistors were an ok choice?

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

Re: GPIO.input voltage levels vs edge detection

Sun Mar 10, 2019 10:47 am

I've been looking at connection devices via i2c. It looks like if I make the raspberry pi the i2c master I can have it communicate with an arduino with a sketch that runs it at 5v as an i2c slave. Because of the way i2c works, at least in this case, I can connect the rpi to the arduino nano without level 3.3v-5v level shifters and without damaging my rpi.

If I can do the same with my MCP3008 ADC, I can run it at 5vdc as a slave and then measure the voltage from my NE555 timer output (also running at 5v) without the need for voltage dividers, zener diodes or other such complicating stuff.

I'll try this out (carefully) and report back my results

Return to “Python”