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 Nov 17, 2018 8:49 am

tlfong01 wrote:
Fri Nov 16, 2018 2:12 pm
Testing NodeMCU board with big 100uF 6V3 tatalum capacitor
I still find the 8 Wemos NodeMCU boards have intermittent failures
I checked the AMS1117 low drop out voltage regulator IC ... Vcc 3.25V looks good.
Update - On second thought, this might be marginal.
Anyway, I think it a good idea to test a board with a big cap
Comparing fakeNodeMCU V3, Wemos D1 Mini and Amica boards
3. Swap heated up nodeMCU boards as soon as I find more frequent intermittent errors after long hours of testing.

Wierd nodeMCU ESPlorer program execution error message

Some days ago I read a fustrated nodeMCU ESPlorer newbie complaining about intermittent program execution failures, with an error message similar to below:

> main()
stdin:1: attempt to call global 'main' (a nil value)
stack traceback:
stdin:1: in main chunk


stdin:4: attempt to call global 'togglePin01' (a nil value)
stack traceback:
stdin:4: in function 'main'
stdin:1: in main chunk


I often got this wierd error message. At first I thought it was a hardware problem, related to bad upload, or insufficient memory, or bad board, or heated up board.

But after testing two very stable versions of my newbieBlink program, I found a strange execution pattern, leading me to conclude that there is something I don't know about Lua local and global variables, and or lexical scope rules that causes the problem.

A frequent pattern is like below.

1. After some repeated testing, I confirmed that a version is stable, and I called it say, v1.0. I repeated tested v1.0 for different boards and found it very stable.

2. Then I refined my version v1.0 to v1.1, V1.2, ... to say v1.5. I also found v1.5 stable, and I took a break, closing uart connection and switching off ESPlorer and power.

3. The frequent happening weird thing appears next time I switch on power and testing the same old stable programs.


/ to continue, ...


Appendix - ESPlorer Lua execution errors etc

Lua Revisited - Scargill 2016
https://tech.scargill.net/lua-revisited-2/

Lua Problem - miker 2015 [/i][/color]
https://www.esp8266.com/viewtopic.php?p=19636

Lua update - Scargill 2014
https://scargill.wordpress.com/2014/12/ ... en-source/

ESP8266 Lua Timer on a Tight Budget - Scargill 2014
https://scargill.wordpress.com/2014/12/ ... ht-budget/
Attachments
nodemcu_wierd_error_msg_2018nov1701.jpg
nodemcu_wierd_error_msg_2018nov1701.jpg (194.63 KiB) Viewed 4801 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

Sun Nov 18, 2018 7:31 am

tlfong01 wrote:
Sat Nov 17, 2018 8:49 am
Wierd nodeMCU ESPlorer program execution error message
Some days ago I read a fustrated nodeMCU ESPlorer newbie complaining about intermittent program execution failures, with an error message similar to below:
attempt to call global 'main' [/b]
(a nil value)
stack traceback:
stdin:1: in main chunk
[/color]
stdin:4: attempt to call global 'togglePin01' (a nil value)
stack traceback:
stdin:4: in function 'main'
stdin:1: in main chunk

I often got this wierd error message. At first I thought it was a hardware problem, related to bad upload, or insufficient memory, or bad board, or heated up board.
But after testing two very stable versions of my newbieBlink program, I found a strange execution pattern, leading me to conclude that there is something I don't know about Lua local and global variables, and or lexical scope rules that causes the problem.
A frequent pattern is like below. ...
1. After some repeated testing, I confirmed that a version is stable, and I called it say, v1.0. I repeated tested v1.0 for different boards and found it very stable.[/i][/color]

Lua Global Variable Confusion - newbie clarification notes

Now I think I must dig deeper into the global variable thing, to get enough knowledge to troubleshoot the 'attempt to call global xxx' problem.

I have written a little function to list the global variables in the global table G. Now if I get the same error message, I can checkout is it really the global variable is not there.
:lol:

For the little example problem list below, the global variables after program successfully run are the following:

variable = y value = hello world
variable = x value = 123
variable = newproxy value = function: 0x3fff12a0
variable = printGlobalVar value = function: 0x3fff06b0

...

Code: Select all

-- printGlobalVariables V01.01.04 tlfong01 2018nov18hkt1517 -- 

--[[ 
Description 
  Print global variables
User Guide
Part A - Setup
1. Restart ESP (Commands > Restart ESP)
Part B - Print global variables
1. Copy program to ESP (Scripts > Open > ) 
2. Execute program (Scripts > Send to ESP))
--]]

-- Functions --
function printGlobalVar()
  for var, value in pairs(_G) 
    do
      print ('variable =', var, 'value =', value)
    end
end

-- Sample data ---
x = 123
y = 'hello world'

-- Main --
printGlobalVar()

-- End --

-- Sample Output --


PORT OPEN 115200

Communication with MCU..Got answer! Communication with MCU established.
AutoDetect firmware...

Can't autodetect firmware, because proper answer not received (may be unknown firmware). 
Please, reset module or continue.
!@#$%^&*() ...

Flash sig not correct: 0 vs fafaaf50

NodeMCU custom build by frightanic.com
	branch: master
	commit: c708828bbe853764b9de58fb8113a70f5a24002d
	SSL: false
	modules: dht,ds18b20,file,gpio,hdc1080,http,i2c,mqtt,net,node,ow,pcm,pwm,rtctime,spi,tmr,uart,wifi
 build created on 2018-10-25 07:35
 powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)
lua: cannot open init.lua

> -- printGlobalVariables V01.01.04 tlfong01 2018nov18hkt1517 --
> 
> --[[
>> Description
>> Print global variables
>> User Guide
>> Part A - Setup
>> 1. Restart ESP (Commands > Restart ESP)
>> Part B - Print global variables
>> 1. Copy program to ESP (Scripts > Open > )
>> 2. Execute program (Scripts > Send to ESP))
>> --]]
> 
> -- Functions --
> function printGlobalVar()
>> for var, value in pairs(_G)
>> do
>> print ('variable =', var, 'value =', value)
>> end
>> end
> 
> -- Sample data ---
> x = 123
> y = 'hello world'
> 
> -- Main --
> printGlobalVar()
variable =	module	value =	function: 0x3fff0d50
variable =	pairs	value =	function: 0x3fff11e0
variable =	__index	value =	lightfunction: 0x402543c4
variable =	package	value =	table: 0x3fff0b70
variable =	_G	value =	table: 0x3fff05f8
variable =	require	value =	function: 0x3fff0d90
variable =	ipairs	value =	function: 0x3fff1008
variable =	y	value =	hello world
variable =	x	value =	123
variable =	newproxy	value =	function: 0x3fff12a0
variable =	printGlobalVar	value =	function: 0x3fff06b0
> 
> -- End --
> 
Attachments
global_var_2018nov1802.jpg
global_var_2018nov1802.jpg (199.8 KiB) Viewed 4786 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

Sun Nov 18, 2018 8:46 am

tlfong01 wrote:
Sun Nov 18, 2018 7:31 am
Wierd nodeMCU ESPlorer program execution error message
Some days ago I read a fustrated nodeMCU ESPlorer newbie complaining about intermittent program execution failures, with an error message similar to below:
attempt to call global 'main' [/b]
(a nil value)
stdin:4:attempt to call global 'togglePin01' (a nil value)
I often got this wierd error message. At first I thought it was a hardware problem, related to bad upload, or insufficient memory, or bad board, or heated up board.
But after testing two very stable versions of my newbieBlink program, I found a strange execution pattern, leading me to conclude that there is something I don't know about Lua local and global variables, and or lexical scope rules that causes the problem.
A frequent pattern is like below. ...
Lua Global Variable Confusion - newbie clarification notes[/b][/color]
Now I think I must dig deeper into the global variable thing, to get enough knowledge to troubleshoot the 'attempt to call global xxx' problem.
[/color]

NodeMCU problem 'attempt to call global 'togglePin01' (a nil value)' solved! :mrgreen:

While refactoring my newbieBlink problems, I found out by accident that at least one of the reasons of the weird errors were:

caused by comment blocks which are either too long, or contains characters such as '<', or '<<', or '*' (to be confirmed).

When I added long comments to a working program, it then gives the weird message. When I removed the long comment block, the weird message disappeared. I tried back and forth a couple of times and confirmed that is really the case.

I also found that if I have filenames too long, much longer than the official ESP8266 SDK limit of 31 (I am using as long as 45 characters for my programs!), then there also might be a problem. I found this out because I am writing a little program to print out the filenames in the flash store.

The program with the trouble making long comment block is listed below.
..

Code: Select all

-- printFlashFiles V01.01.04 tlfong01 2018nov18hkt1553 -- 

--[[ 
Description 
  Print files in flash
User Guide
Part A - Setup
1. Restart ESP (Commands > Restart ESP)
2. Format flash (Output window > Format > )
3. Upload sample file to flash (Scripts > Upload >)
4. Get flash info (Output winddow > Flash Id)
Part B - Print flash file names
1. Copy program to ESP (Scripts > Open > ) 
2. Execute program (Scripts > Send to ESP))
--]]

-- Functions --
function printFlashFiles()
  fileList = file.list()
  for name, size in pairs(fileList) 
    do
      print('name =', name, 'size =', size)
  end  
end

-- Main --
printFlashFiles()
-- End --

--[[
-- Sample Output --

> -- printFlashFiles V01.01.04 tlfong01 2018nov18hkt1549 --
> 
> 
>> Description
>> Print files in flash
>> User Guide
>> Part A - Setup
>> 1. Restart ESP (Commands > Restart ESP)
>> 2. Format flash ?]Output window > Format > )
>> 3. Upload sample file to flash (Scripts > Upload >)
>> 4. Get flash info (Output winddow > Flash Id)
>> Part B - Print flash file names
>> 1. Copy program to ESP (Scripts > Open > )
>> 2. Execute program (Scripts > Send to ESP))
>> 
> 
> -- Functions --
> function printFlashFiles()
>> fileList = file.list()
>> for name, size in pairs(fileList)
>> do
>> print('name =', name, 'size =', size)
>> end
>> end
> 
> -- Main --
> printFlashFiles()
name =	nb_15_01_01_ok_2018nov1701.lua	size =	3480
> -- End --
> -- printFlashFiles V01.01.04 tlfong01 2018nov18hkt1553 --
> 
> --[[
>> Description
>> Print files in flash
>> User Guide
>> Part A - Setup
>> 1. Restart ESP (Commands > Restart ESP)
>> 2. Format flash ?]Output window > Format > )
>> 3. Upload sample file to flash (Scripts > Upload >)
>> 4. Get flash info (Output winddow > Flash Id)
>> Part B - Print flash file names
>> 1. Copy program to ESP (Scripts > Open > )
>> 2. Execute program (Scripts > Send to ESP))
>> 
> 
> -- Functions --
> function printFlashFiles()
>> fileList = file.list()
>> for name, size in pairs(fileList)
>> do
>> print('name =', name, 'size =', size)
>> end
>> end
> 
> -- Main --
> printFlashFiles()
name =	nb_15_01_01_ok_2018nov1701.lua	size =	3480
> -- End --
--]]
Attachments
print_flash_files_2018nov1802.jpg
print_flash_files_2018nov1802.jpg (192.57 KiB) Viewed 4782 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

Sun Nov 18, 2018 3:05 pm

tlfong01 wrote:
Sun Nov 18, 2018 8:46 am
NodeMCU problem 'attempt to call global 'togglePin01' (a nil value)' solved!
While refactoring my newbieBlink problems, I found out by accident that at least one of the reasons of the weird errors were:
caused by comment blocks which are either too long, or contains characters such as '<', or '<<', or '*'(to be confirmed)
I also found that if I have filenames too long, much longer than the official ESP8266 SDK limit of 31 (I am using as long as 45 characters for my programs!), then there also might be a problem. I found this out because I am writing a little program to print out the filenames in the flash store.

First Time Using ESPlorer Snippets

After playing with ESPlorer for 2 long months, it is only now the newbie, ie, me, appreciate the useful tool of snippet for testing and debugging. Now I have saved 3 snippets in the ESPlorer:

0. Printing global variables in RAM.
1. Printing names of files stored in flash.
2. Stable version of newblink


A log file of running the first 2 snippets is listed below.
...

Code: Select all

Snippet Execution Log - tlfong01 2018nov18hkt2254

Snippet 0 = printGlobalVar()
Snippet 1 = printFlashFiles()

PORT OPEN 115200

Communication with MCU..Got answer! Communication with MCU established.
AutoDetect firmware...

Can't autodetect firmware, because proper answer not received (may be unknown firmware). 
Please, reset module or continue.

!@#$%^&*()

Flash sig not correct: 0 vs fafaaf50

NodeMCU custom build by frightanic.com
	branch: master
	commit: c708828bbe853764b9de58fb8113a70f5a24002d
	SSL: false
	modules: dht,ds18b20,file,gpio,hdc1080,http,i2c,mqtt,net,node,ow,pcm,pwm,rtctime,spi,tmr,uart,wifi
 build created on 2018-10-25 07:35
 powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)
lua: cannot open init.lua

> function printGlobalVar()
>> for var, value in pairs(_G)
>> do
>> print ('variable =', var, 'value =', value)
>> end
>> end
> 
> -- Sample data ---
> x = 123
> y = 'hello world'
> 
> -- Main --
> printGlobalVar()

variable =	module	value =	function: 0x3fff0d50
variable =	pairs	value =	function: 0x3fff11e0
variable =	__index	value =	lightfunction: 0x402543c4
variable =	package	value =	table: 0x3fff0b70
variable =	_G	value =	table: 0x3fff05f8
variable =	require	value =	function: 0x3fff0d90
variable =	ipairs	value =	function: 0x3fff1008
variable =	y	value =	hello world
variable =	x	value =	123
variable =	newproxy	value =	function: 0x3fff12a0
variable =	printGlobalVar	value =	function: 0x3fff06b0

> function printFlashFiles()
>> fileList = file.list()
>> for name, size in pairs(fileList)
>> do
>> print('name =', name, 'size =', size)
>> end
>> end
> 
> -- Main --
> printFlashFiles()

name =	pg05.lua	size =	2228
name =	pf05.lua	size =	644
name =	nb121514t.lua	size =	3449
> 

.END
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 Nov 20, 2018 6:32 pm

I finally got my Rachio Logger wired up and tested. I only use 12 of the 16 channels so have not populated the places for 4 A3700 AC/DC to Logic Interface Optocouplers. One thing I learned was that when using breadboards and soldering point to point, each hole should be able to accommodate at least 3 wires at the same time. This will save a lot of breadboard real estate and reduce soldering. I also added insulation to the leads on my capacitors and resistors to avoid unintended connections.

I did have a problem with some of my A3700's. Of 20 that I ordered, 6 of them were bad. The Amazon vendor kindly replaced the bad ones. They were bad in one of 2 ways: when an AC voltage was applied across the AC pins they did nothing or they generated non-stop interrupts until the AC was turned off.

It turns out the circuit draws very little current so I can power it all from the 3.3v of the Raspberry Pi. I have a jumper so I can use 5v dc and regulate it down to 3.3v using a LD117V33 but have not needed that part of the circuit.

The circuit for a single A3700 connected through a MCP23017 has already been posted so would redo that if anyone asks for it.

I am now moving to a software development phase so that I can build a database of events (time, duration, which valve). It turns out that I never get multiple valves on at the same time. The shutoff of one valve happens cleanly before the next valve comes on. This will simplify the software portion but I will add warnings in case this ever happens. If I see this, I'll deal with it then.

Once I get the software in good enough shape, I'll add flow meters to the mix.

Meanwhile, I see a lot of interesting posts while I was away and will want to read through these.
Attachments
RachioLogger.JPG
RachioLogger.JPG (114.88 KiB) Viewed 4693 times

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

Re: GPIO.input voltage levels vs edge detection

Tue Nov 20, 2018 9:52 pm

petermeigs wrote:
Tue Nov 20, 2018 6:32 pm
I finally got my Rachio....
Good to see your still working on this project and that it comes together now. Your pcb looks also good. But keep in might that it is not suitable for high voltage ;) But you did not design for that, so all good.
I'm looking forward for your code.

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

Re: GPIO.input voltage levels vs edge detection

Fri Nov 23, 2018 2:01 am

Brandon92 wrote:
Tue Nov 20, 2018 9:52 pm
... But keep in might that it is not suitable for high voltage but you did not design for that, so all good. ...
I agree that it is not suitable for high voltage if for no other reason, the resistors I chose for the AC pins 1 and 4 are to make the A3700 operate to suit my purposes at 24VAC. The capacitor across pins 2 and 3 would need to be rated for a higher voltage as well, taking into account that 240VAC peaks at 1.414 times 240. I might need resistors of a higher wattage as well. However, I'm wondering about other possible reasons. The datasheet says the A3700 is suitable for up to 240v DC/AC.

I know that voltages above 50v are not considered safe https://electronics.stackexchange.com/q ... -dangerous (even that has more detail to be considered) and I certainly would not want to start start a fire or damage other electrical components. If I were to want to detect higher voltages (say 120 or 240), I would choose appropriate resistors for pins 1 and 4 and I would arrange the physical layout of the circuit board so that the higher voltages are cleanly physically separate from the logic side of the A3700 as well as other logic components. For safely, I would also want to place a layer of insulation over any of the high voltage exposed connections. There won't be much current drawn on pins 1 and 4 so I don't think I would need to worry about wire gauge but I might need resistors of a higher wattage.

So have I missed anything that I should be considering for higher voltage circuits? I don't plan to do anything like this but it will be nice to learn
safely and smokelessly and the principles may have other applicability.

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 Nov 23, 2018 7:01 am

petermeigs wrote:
Fri Nov 23, 2018 2:01 am
... So have I missed anything that I should be considering for higher voltage circuits? I don't plan to do anything like this but it will be nice to learn safely and smokelessly and the principles may have other applicability.

AC Mains Earthing Reminder

Have you placed all the mains related things in a earthed metal box and also earthed the metal part of the 24V AC transformer?

(24VAC Transformer Grounding) RE: RELAY MODULE KY-019 5V y tlfong01 2018-Jun-30
viewtopic.php?f=37&t=77158&start=100#p1334948
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 Nov 23, 2018 7:06 am

petermeigs wrote:
Fri Nov 23, 2018 2:01 am
... So have I missed anything that I should be considering for higher voltage circuits? I don't plan to do anything like this but it will be nice to learn safely and smokelessly and the principles may have other applicability.

AC Mains Earthing Reminder

Have you placed all the mains related things in a earthed metal box and also earthed the metal part of the 24V AC transformer?

(24VAC Transformer Grounding) RE: RELAY MODULE KY-019 5V - tlfong01 2018-Jul-01 Sun
viewtopic.php?f=37&t=77158&start=100#p1335254
...
Attachments
earthing_2018nov2301.jpg
earthing_2018nov2301.jpg (191.43 KiB) Viewed 4442 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 Nov 23, 2018 6:17 pm

I am using the 120vac to 24vac power supply that comes with my Rachio. It's much simpler that what you show and just looks like a phone charger wall wart.

Here is a URL to a replacement https://www.amazon.com/NiceTQ-Replaceme ... B074ZC92FV. It has only two spades on the plug so it has no independent ground(earth). Often these spades are keyed with one being a little wider than the other so they will only go in the socket one way. One side of the socket goes back to my homes ground and there is a cable that is literally earthed (i.e. there is an iron rod driven into the earth to which one side of the connection is connected) . That is all power company stuff.

My conclusion is that in my case I don't need to worry about power earth/ground very much. If I'm wrong, I'd like to know. --

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 Nov 24, 2018 7:36 am

petermeigs wrote:
Fri Nov 23, 2018 6:17 pm
My conclusion is that in my case I don't need to worry about power earth/ground very much. If I'm wrong, I'd like to know. --

Wall Wart with a Ground Pin

Well, I think your 18 dollar adapter is OK, comparing to my 2 dollar no name cheapie. On the other hand, my tuhao friends do have wall warts with a silver ground pin, ... :mrgreen:

Macbook charger teardown - Ken Shirriff 2015nov25
http://www.righto.com/2015/11/macbook-c ... ising.html

For the teardown I started with a Macbook 85W power supply, model A1172, which is small enough to hold in your palm, ...

with a metal ground pin, ...

including a microprocessor, ...

cheap no-name chargers cut corners and often have safety issues, making them risky, both to you and your computer.


Tuhao - Wikipedia,

Tuhao is a Chinese term referring to people of wealth. The term has several related and differing definitions throughout time. In its original literary form, it refers to those of prominent and wealthy backgrounds. In modern use, the term has also became a popular slang used to describe the nouveau riche. Pejoratively, the internet slang can be understood to carry on the meaning of "uncouth nouveau riche", "tacky" or "extravagant".

Origin and transformation in uses

The term 'tuhao' was originally used in ancient China, dating back to the Northern and Southern Dynasties around 1,500 years ago. The term originally referred to those of prominent origin, especially people of influential and wealthy backgrounds. During the Republic period and the Cultural Revolution from 1920 to early 1950, it was used to describe and refer to landlords or landholders who bullied those beneath them in the social class, known as the countrymen.

Before August 2013, 'Tuhao' was a popular internet slang used to describe irrational and over-consumed online game players, who were also called "RMB warriors" as they use renminbi to purchase in-game items and suppress regular players who did not have the ability to purchase as many items. They won by their purchasing power, rather than their online game techniques or tactics. Its usage has now extended to daily life. People who purchase a large amount of figures, models and luxury goods are also given the nickname 'Tuhao'. ...

...
Attachments
mac_book_charger_2018nov2401.jpg
mac_book_charger_2018nov2401.jpg (158.36 KiB) Viewed 4411 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

Mon Nov 26, 2018 2:32 am

Some further results with the rachio logger in the earlier picture:

1. I am getting very clear results. I think this is thanks to the Rachio implementation. One and only one valve is energized at a time.

2. When one valve is energized and then it switches it off and energizes the next one, there is no overlap. In other works, there is time to get the "off" callback and then get an "on" call back. I was worried this valve switch might happen so quickly, I'd get the "off" for one line in the same interrupt as the "on" for the next. That would make the coding a bit more tricky. BTW, remember that the A3700 is high when there is no AC voltage across pins 1 and 4 so when I say "off" and "on" I mean the logical "off" and "on" as related to the valve being energized or not.

3. I don't see any strange effects from the valve solenoid being turned on and off by the Rachio controller. We worried about a current being induced when shutting off the voltage to the coil. Either the AC part of the A3700 can handle it or it is not a factor for AC. I don't know enough about this effect to say much more. In my case, the interrupt (call back) processing is quite clean.

4. I did see some startup issues with the MCP23017. I was getting interrupts that I was not expecting before anything had really gotten initialized. With a little SWAG (scientific wild animal guess) tried adding some .1 sec delays in the initialization code, specifically after writing all zeros to the MCP2317 gpio pins, then reading all the pins. After another .1 sec delay, I enabled interrupts for all 16 gpio pins. My guess is that without the delays, the chip did not have time to settled down in its initial state before interrupts were enabled. Whatever the explanation, this seems to have solved the problem.

5. My next step is to buy a Hunter HC100FLOW flow-meter. This has a 1" supply line and will give 1 pulse per gallon. (You've got to love US units of volume! ) The theoretical maximum flow rate is 40 gallons per minute but I think I'll only see 2 to 4 given my homes water pressure. The manufacturer does not give much tech info about the meter because they want you to buy their controller and I am building my own. I believe the flow-meter is simply a reed switch that operates at 24 vac. If this is true, I just be able to use one of my unused A3700's for the flow tic counter. I'll have to risk 100USD to buy this item. Wish me luck.

BTW, I enjoy reading the other posts. The background information is interesting and all the comments are helpful.

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 Nov 26, 2018 4:13 am

petermeigs wrote:
Mon Nov 26, 2018 2:32 am
My next step is to buy a Hunter HC100FLOW flow-meter. This has a 1" supply line and will give 1 pulse per gallon. (You've got to love US units of volume! )

Well, you remind me many years ago I read a text book on program verification, about a very expensive software bug made by some very stubborn American engineers using very old English units, ... :mrgreen:

Metric mishap caused loss of NASA orbiter - CNN 1999sep23
http://edition.cnn.com/TECH/space/9909/ ... metric.02/

Mars Landing - NASA 2018nov26
https://mars.nasa.gov/insight/timeline/landing/summary/
https://mars.nasa.gov/insight/timeline/ ... t-landing/

One Day from Mars Landing - NASA JPL 2018nov25 and streaming live!
https://www.youtube.com/watch?time_cont ... WhjDBmlcqg

Countdown to Mars: NASA sweating 'seven minutes of terror' - CNN Updated 0153 GMT (0953 HKT) November 26, 2018
https://edition.cnn.com/2018/11/25/opin ... index.html
...
Attachments
mars_landing_2018nov2602.jpg
mars_landing_2018nov2602.jpg (169.76 KiB) Viewed 4329 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

Mon Nov 26, 2018 7:46 am

petermeigs wrote:
Mon Nov 26, 2018 2:32 am
1. My next step is to buy a Hunter HC100FLOW flow-meter.
2. I believe the flow-meter is simply a reed switch
3. I'll have to risk 100USD to buy this item. Wish me luck.

Hall Sensor vs Reed Switch

2. Are you sure it is a reed switch?

(Hall Sensor)
viewtopic.php?]f=37&t=77158&start=425#p1381407

(Reed Switch)
viewtopic.php?f=37&t=77158&start=450#p1384933

3. My high class, elegant, stylistic, transparent flow switch only costs ¥12!
...
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

Mon Nov 26, 2018 4:36 pm

I'm pretty sure it is a reed and not Hall. It only has two wires but I am guessing. I need a pipe diameter of 1" (2.54 cm), max flow of 75 l/min, and pressure of 75 psi (5 atm). I'd like it to be reasonably accurate. It turns out that we pay taxes on the amount of our sewer use. The water company measures that by estimating. They calculate the volume of water used during the month of January when it rains the most. The idea is that the difference between that amount and the amount used in July, for example, must be used for irrigation. So we are billed for 12 months at the January level for sewer use.

If I have an accurate meter on the amount used for irrigation for the year, I can submit those numbers to calculate sewer use.
Attachments
HunterHC100FlowLabel.JPG
HunterHC100FlowLabel.JPG (91.23 KiB) Viewed 4292 times
HunterHC100Flow.JPG
HunterHC100Flow.JPG (91.78 KiB) Viewed 4292 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

Wed Nov 28, 2018 6:36 am

petermeigs wrote:
Mon Nov 26, 2018 2:32 am
5. My next step is to buy a Hunter HC100FLOW flow-meter. This has a 1" supply line and will give 1 pulse per gallon. I'll have to risk 100USD to buy this item. Wish me luck.

Well, there a risk that after 2019 January, the flow-meter made in a mighty country might cost 25% more in a great country. :mrgreen:
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 Nov 28, 2018 4:38 pm

My HC100FLOW by Hunter arrived yesterday. I have still not been able to get compete specs from the manufacturer on the switch but I think I can deduce them. First of all, I can the label under the caps tells me there are in fact two reed switches one on a blue wire and another on a red wire with white being the common one. The instructions for installing the Hunter Flow meter to the Hunter Controller states that only one of the reed switches is used (the blue wire) and it doesn't matter which wire is used on which terminal. This tells me it is a simple on/off switch. More about that later.

I found an application note https://www.hsisensing.com/wp-content/u ... 100512.pdf that discusses reed switches. From this document, I see that I will have a resistive using AC current, 24 vac (I'll use the same 24vac power supply for the pulse current for the reed switch) . I'll have about 100 feet (30.5 meters) of 26 gauge copper wire between the controller and the reed switch for a resistance of about 7 ohms. In out earlier circuits we remember that we have 4.4k ohms in the AC side of the A3700, so the contribution of 7 ohms is negligible. If fact, should have already known this because the A3700s worked well detecting the on/off state of the valve relays

The 24 vac circuit will have a maximum current approximately of 3.5 milliAmps (i.e. about 84milliWatts). We know this by looking at the A3700 spec sheet. In an earlier calculation, we chose the resistance (4.4k ohms) to give the A3700 the correct current to be able to detect 24vac on or off with no bounce.

All of these values are intuitively (this can get you into trouble though, can't it?) low enough so that we should not have to be worried about arcing within the reed switch reducing its life. (If anyone has any concerns here, please let me know). The manufacturer did let me know that the sensing current in their application was DC but I don't see that this will make any difference to the operation of the switch. The fact that that peak voltage of 24vac is 34v does not strike me as a concern. (again, If anyone has any concerns here, please let me know)

Now back to the two reed switches. The dial on the meter will tell me down to .01 gallons (0.0378541 liters). The question is why are there two reed switches. With my voltmeter and a small vacuum cleaner, I can make the meter spin. I observe that the red wire will produce a pulse once every 0.1 gallons and the blue wire produces one about every .35 gallons. As this is close to a multiple of the ratio of gallons to liters, the blue wire is suspiciously metric.

I plan to connect my counting circuit to the flow-meter and then operate it over a longer interval. I can then observe the difference in start and stop gallons and compare this to the number of pulses. I should then be able to get an accurate idea of how many pulses one each wire there are in 100 gallons (for example). I'll then be able to say for sure.

Once I have the measuring characteristics of the flow-meter, I will install it. I'll then be able to run it with water flowing and compare the Hunter flow-meter measurement with the water company flow-meter to my home. Since the water company uses their meter for billing, I suppose we can assume it is accurate. We'll see...
Attachments
IMG_1067.JPG
IMG_1067.JPG (89.29 KiB) Viewed 4199 times

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

Re: GPIO.input voltage levels vs edge detection

Fri Nov 30, 2018 7:01 pm

petermeigs wrote:
Fri Nov 23, 2018 2:01 am
Brandon92 wrote:
Tue Nov 20, 2018 9:52 pm
... But keep in might that it is not suitable for high voltage but you did not design for that, so all good. ...
I agree that it is not suitable for high voltage if for no other reason, the resistors I chose for the AC pins 1 and 4 are to make the A3700 operate to suit my purposes at 24VAC. The capacitor across pins 2 and 3 would need to be rated for a higher voltage as well, taking into account that 240VAC peaks at 1.414 times 240. I might need resistors of a higher wattage as well. However, I'm wondering about other possible reasons. The datasheet says the A3700 is suitable for up to 240v DC/AC.

I know that voltages above 50v are not considered safe https://electronics.stackexchange.com/q ... -dangerous (even that has more detail to be considered) and I certainly would not want to start start a fire or damage other electrical components. If I were to want to detect higher voltages (say 120 or 240), I would choose appropriate resistors for pins 1 and 4 and I would arrange the physical layout of the circuit board so that the higher voltages are cleanly physically separate from the logic side of the A3700 as well as other logic components. For safely, I would also want to place a layer of insulation over any of the high voltage exposed connections. There won't be much current drawn on pins 1 and 4 so I don't think I would need to worry about wire gauge but I might need resistors of a higher wattage.

So have I missed anything that I should be considering for higher voltage circuits? I don't plan to do anything like this but it will be nice to learn
safely and smokelessly and the principles may have other applicability.
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 standaard. 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 you low voltage part.

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 01, 2018 2:23 pm

petermeigs wrote:
Wed Nov 28, 2018 4:38 pm
My HC100FLOW by Hunter arrived yesterday.
there are in fact two reed switches
The dial on the meter will tell me down to .01 gallons.

Rpi Tensor Flow to Recognize Water Meter's Broken Digits

Perhaps you can ask your Rpi to use Tensor Flow to read broken digits.

Appendices - Rpi Tensor Flow to Recognize Hand Written Digits

How To Build a Neural Network to Recognize Handwritten Digits with TensorFlow
https://www.digitalocean.com/community/ ... tensorflow

Google TensorFlow 1.9 Officially Supports Raspberry Pi Stretch Python 3 By Pete Warden 2018aug02
https://medium.com/tensorflow/tensorflo ... 91669b0aa0

How to install Google Tensorflow on Rpi - MagPi 2018Aug
https://www.raspberrypi.org/magpi/tenso ... pberry-pi/
There is a link to an example that uses the Pi Camera Module directly.

Reed switch - Wikipedia
https://en.wikipedia.org/wiki/Reed_switch

The reed switch is an electrical switch operated by an applied magnetic field. It was invented at Bell Telephone Laboratories in 1936 by W. B. Ellwood.
...
Attachments
tensor_flow_broken_digit_recognition_2018dec0101.jpg
tensor_flow_broken_digit_recognition_2018dec0101.jpg (197.32 KiB) Viewed 4024 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 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

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 02, 2018 9:25 am

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?

Carefree Low Voltage Applications

1. Yes, I think 50VAC or 50VDC is low voltage for humans. And a 24VAC or 24VDC wire is very safe for ordinary, healthy, humans to touch and hold.

2. The only risk is your no ground 110VAC to 24VAC non conducting plastic covered, wall wart, AND my fused, grounded, thermal and short circuit proof, bench PSU (power supply unit) 220VAC to 24VAC, 12VAC, and 12VDC.

3. To get zero risk for the humans and cats, I decided not to use 12VAC, and 24VAC all together. My pumps, solenoid valves, flow rate meters are now all 5VDC, 12VDC, and 24VDC. For 100% risk free in my rooftop garden projects where children and cats are around, I will use power supply units based on rechargeable 6V/12VDC lead batteries or rechargeable 3.7V/7.4V/14.8VDC lithium cells/modules.

4. Earlier I played with 220VAC fish tank water pumps, and 220VAC inductor motor clocks. I decided not to use them any more.

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

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.
Attachments
LED on3700.PNG
LED on3700.PNG (28.32 KiB) Viewed 3936 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

Mon Dec 03, 2018 1:13 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.
is tr1 the wallwart you just bought?
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

Mon Dec 03, 2018 1:28 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 once considered a37 because I wanted to detect 200VAC and 24vdc on my water pump, inductor motor clock, and solenoids. I am now using 24v/12v/ac/dc only. I found a37 not good for detecting 24vac, because I found the threshold setting not suitable for me.

To detect 24vc, I can just use one diode to convert it to 24vdc, then two resistors to divided it down to 5vdc, then a schmitt inverter HC14 and a cap as output to rpi.

I seem to going back to square 1. I need to go back to the post 1 to see what were the problems and why i arrived here. :mrgreen:
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

Mon Dec 03, 2018 4:29 am

petermeigs wrote:
Fri Nov 23, 2018 6:17 pm
I am using the 120vac to 24vac power supply that comes with my Rachio. It's much simpler that what you show and just looks like a phone charger wall wart.
Here is a URL to a replacement https://www.amazon.com/NiceTQ-Replaceme ... B074ZC92FV.
Ah, the Rachio 24VAC psu is not like the wallwart you mentioned, which is a 24VDC charger output, not AC! No wonder I got confused, because

I have never seen a 110/220VAC input 12/24VAC output wallwart.

NiceTQ Replacement Wall AC Power Adapter Charger Supply For Rachio Smart Sprinkler Controller, WiFi, 8 Zone / 16 Zone 2nd Generation $80
https://www.amazon.com/NiceTQ-Replaceme ... B074ZC92FV
Input: 100V -- 240V Output: DC24v, 1000mA
Build in Dynamic IC, Charger IC & Power fuse for rapid charging and over charge protection
Last edited by tlfong01 on Mon Dec 03, 2018 4:48 am, edited 1 time in total.
I am an electronics and smart home hobbyist.

Return to “Python”