Pymate-16ADI16DO-introduction: Difference between revisions

From pymate.io wiki
Jump to navigation Jump to search
No edit summary
Line 95: Line 95:
     print( "i10= %s" % i10.value() )
     print( "i10= %s" % i10.value() )
     time.sleep( 0.5 ) # Wait 1/2 second
     time.sleep( 0.5 ) # Wait 1/2 second
</syntaxhighlight>
== Output ==
Output will connect the high side of the load to Vin (250 mA per channel) with a PNP transistor. It can be used to control relays, pilot light, etc.
=== Wiring ===
The following example controls a 24V relay connected to output 2 and a 24V Pilot Light to output 8.
[[File:pymate-output-2.png|960px]]
=== Coding ===
The following example change the state of the relay (OUT3) every minute while the Pilot Light (OUT12) is lit when the relay is off.
<syntaxhighlight lang="python" line>from pymate.pymateio import PymateIO
from machine import Pin
import time
EXT_BOARD = 1
o3 = PymateIO( "OUT3", Pin.OUT, EXT_BOARD )
o12 = PymateIO( "OUT12", Pin.OUT, EXT_BOARD )
state = False
while True:
    # Invert the state
    state = not(state)
    # Set the relay
    print( "Relay is %s" % state )
    o3.write( state )
    # Set the Pilot Light
    o12.write( not(state) )
    # Wait a minute
    time.sleep( 60 )
</syntaxhighlight>
Which would display the following in the REPL:
<nowiki>Relay is True
Relay is False
Relay is True
Relay is False
...</nowiki>
=== MicroPython alike call ===
MicroPython coder usually use `Pin.value( new_value )` to write the state of an output.
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:
* {{fname|'''value(new_state)'''}} instead of {{fname|write()}}
* {{fname|'''on()'''}} & {{fname|'''off()'''}} instead of {{fname|write()}}
* {{fname|'''high()'''}} & {{fname|'''low()'''}} as replacement of {{fname|on()}} and {{fname|off()}}.
<syntaxhighlight lang="python" line>from pymate.pymateio import PymateIO
from machine import Pin
import time
EXT_BOARD = 1
o3 = PymateIO( "OUT3", Pin.OUT, EXT_BOARD )
o12 = PymateIO( "OUT12", Pin.OUT, EXT_BOARD )
state = False
while True:
    # Invert the state
    state = not(state)
    # Set the relay
    print( "Relay is %s" % state )
    o3.value( state )
    # Set the Pilot Light
    o12.value( not(state) )
    # Wait a minute
    time.sleep( 60 )
</syntaxhighlight>
</syntaxhighlight>


{{PYMATE-TRAILER}}
{{PYMATE-TRAILER}}

Revision as of 21:58, 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

EXT_BOARD = 1

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

while True:
    print( "i10= %s" % i10.value() )
    time.sleep( 0.5 ) # Wait 1/2 second

Output

Output will connect the high side of the load to Vin (250 mA per channel) with a PNP transistor. It can be used to control relays, pilot light, etc.

Wiring

The following example controls a 24V relay connected to output 2 and a 24V Pilot Light to output 8.

Pymate-output-2.png

Coding

The following example change the state of the relay (OUT3) every minute while the Pilot Light (OUT12) is lit when the relay is off.

from pymate.pymateio import PymateIO
from machine import Pin
import time

EXT_BOARD = 1

o3 = PymateIO( "OUT3", Pin.OUT, EXT_BOARD )
o12 = PymateIO( "OUT12", Pin.OUT, EXT_BOARD )
state = False
while True:
    # Invert the state
    state = not(state)

    # Set the relay
    print( "Relay is %s" % state )
    o3.write( state )

    # Set the Pilot Light
    o12.write( not(state) )

    # Wait a minute
    time.sleep( 60 )

Which would display the following in the REPL:

Relay is True
Relay is False
Relay is True
Relay is False
...

MicroPython alike call

MicroPython coder usually use `Pin.value( new_value )` to write the state of an output.

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(new_state) instead of write()
  • on() & off() instead of write()
  • high() & low() as replacement of on() and off().
from pymate.pymateio import PymateIO
from machine import Pin
import time

EXT_BOARD = 1

o3 = PymateIO( "OUT3", Pin.OUT, EXT_BOARD )
o12 = PymateIO( "OUT12", Pin.OUT, EXT_BOARD )
state = False
while True:
    # Invert the state
    state = not(state)

    # Set the relay
    print( "Relay is %s" % state )
    o3.value( state )

    # Set the Pilot Light
    o12.value( not(state) )

    # Wait a minute
    time.sleep( 60 )

PymateIO all right reserved © 2026 - Written by MCHobby for PymateIO