Pymate-16ADI16DO-introduction: Difference between revisions
(→Wiring) |
(→Coding) |
||
| Line 49: | Line 49: | ||
=== Coding === | === Coding === | ||
The following example query the state if imput | The following example query the state if imput 10 (on Board_ID 1) and displays the results on the REPL session. | ||
<syntaxhighlight lang="python" line>from pymate.pymateio import PymateIO | <syntaxhighlight lang="python" line>from pymate.pymateio import PymateIO | ||
| Line 55: | Line 55: | ||
import time | import time | ||
EXT_BOARD = 1 | |||
i10 = PymateIO( "IN10", Pin.IN, EXT_BOARD ) | |||
while True: | while True: | ||
print( " | print( "i10= %s" % i10.read() ) | ||
time.sleep( 0.5 ) # Wait 1/2 second | time.sleep( 0.5 ) # Wait 1/2 second | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 65: | Line 68: | ||
<nowiki>1 | <nowiki>1 | ||
1 | |||
1 | 1 | ||
0 | 0 | ||
0 | 0 | ||
1</nowiki> | |||
Where: | Where: | ||
Revision as of 19:39, 23 June 2026
Important note
Charts and graphics are made to be easy to follow.
The Pymate boards are drawed without connectors to avoids parallax shift. The real board are fitted with the connectors.
Board_ID
It is essential to identify the Board_ID of the 16ADI16DO expansion.
Here a reminder of few tutorials around the "Board_ID".
Input
Input are high when voltage on the Input is higher than 8V.
Input return to low state when the voltage drops under 5V
Wiring
Coding
The following example query the state if imput 10 (on Board_ID 1) and displays the results on the REPL session.
from pymate.pymateio import PymateIO
from machine import Pin
import time
EXT_BOARD = 1
i10 = PymateIO( "IN10", Pin.IN, EXT_BOARD )
while True:
print( "i10= %s" % i10.read() )
time.sleep( 0.5 ) # Wait 1/2 secondWhich would display the following in the REPL:
1 1 1 0 0 1
Where:
- 0 is at LOW state, meaning that low voltage is applied on the input (< 5 Volts).
- 1 is at HIGH state, meaning that high voltage is applied on the input (> 8 Volts).
MicroPython alike call
MicroPython coder usually use Pin.value() to read the state of an input.
Such method is also available on the PymateIO class to act like an usual `Pin` class.
The script above could also be written by using value() instead of read() as follow:
from pymate.pymateio import PymateIO
from machine import Pin
import time
i3 = PymateIO( "IN3", Pin.IN )
while True:
print( "i3= %s" % i3.value() )
time.sleep( 0.5 ) # Wait 1/2 second
