Pymate-16ADI16DO-introduction: Difference between revisions

From pymate.io wiki
Jump to navigation Jump to search
Line 49: Line 49:
=== Coding ===
=== Coding ===


The following example query the state if imput 3 and displays the results on the REPL session.  
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


i3 = PymateIO( "IN3", Pin.IN )
 
EXT_BOARD = 1
 
i10 = PymateIO( "IN10", Pin.IN, EXT_BOARD )


while True:
while True:
     print( "i3= %s" % i3.read() )
     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
1
0
0
0</nowiki>
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".

Board_ID

Tlogo-board-id.png

Identification of expansion board

CAN Scan

Tlogo-can-scan.png

Scanning the CAN bus for boards and check for CAN error.

Change Board_ID

Tlogo-board-id.png

How to change the 16ADI16DO board identification on the CAN bus.

 

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

Pymate-input-2.png

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 second

Which 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