Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

Knowledge Base

IO Zero 32 Node JS Library

IO Zero 32 Node JS Library Installation and Usage

Created 29/07/2024 | Last Updated: 30/07/2024

Node.js Library to use with IO Zero 32 Raspberry Pi development board.

Install

To download to your Raspberry Pi type in the terminal:

git clone https://github.com/abelectronicsuk/ABElectronics_NodeJS_Libraries.git

The IO Zero 32 library is located in the /lib/iozero32/ directory

The example files are located in the /examples/iozero32/ directory

The IO Zero 32 library requires the i2c-bus library to run.

Install from npm package repository i2c-bus with

npm install i2c-bus

Classes:

IOZero32(address)

Parameters:
address: (number) i2c address for the target device. 0x20 to 0x27

Functions:


setPinDirection(pin, direction):

Sets the IO direction for an individual pin
Parameters:
pin: (number) 1 to 16
direction: (number) 1 = input, 0 = output
Returns: null


getPinDirection(pin)

Get the IO direction for an individual pin
Parameters:
pin: (number) pin to read, 1 to 16
Returns: (number) 1 = input, 0 = output


setPortDirection(port, direction): 

Sets the IO direction for the specified IO port
Parameters:
port: (number) 0 = pins 1 to 8, 1 = pins 9 to 16
direction: (number) between 0 and 255 or 0x00 and 0xFF. Each bit in the 8-bit number represents a pin on the port. 1 = input, 0 = output
Returns: null


getPortDirection(port): 

Get the direction from an IO port
Parameters:
port: (number) 0 = pins 1 to 8, 1 = pins 9 to 16
Returns: (number) between 0 and 255 (0xFF)


setBusDirection(direction): 

Sets the IO direction for all pins on the bus
Parameters:
direction: (number) 16-bit number 0 to 65535 (0xFFFF). For each bit 1 = input, 0 = output
Returns: null


getBusDirection()

Get the direction for an IO bus
Returns: (number) 16-bit number 0 to 65535 (0xFFFF). For each bit 1 = input, 0 = output


writePin(pin, value)

Write to an individual pin 1 - 16
Parameters:
pin: (number) 1 to 16
value: (number) 1 = logic high, 0 = logic low
Returns: null


writePort(port, value)

Write to all pins on the selected port
Parameters:
port: (number) 0 = pins 1 to 8, 1 = pins 9 to 16
value: (number) between 0 and 255 or 0x00 and 0xFF. Each bit in the 8-bit number represents a pin on the port. 1 = logic high, 0 = logic low
Returns: null


writeBus(value)

Write to all pins on the selected bus
Parameters:
value: (number) 16-bit number 0 to 65535 (0xFFFF). For each bit 1 = logic high, 0 = logic low
Returns: null


readPin(pin)

Read the value of an individual pin 1 - 16
Parameters:
pin: (number) 1 to 16
Returns: (uint8_t) 0 = logic low, 1 = logic high


readPort(port)

Read all pins on the selected port
Parameters:
port: (number) 0 = pins 1 to 8, 1 = pins 9 to 16
Returns: (number) between 0 and 255 or 0x00 and 0xFF. Each bit in the 8-bit number represents a pin on the port. 0 = logic low, 1 = logic high


readBus()

Read all pins on the bus
Returns: (number) 16-bit number 0 to 65535 (0xFFFF) Each bit in the 16-bit number represents a pin on the port. 0 = logic low, 1 = logic high


setPinPolarity(pin, polarity)

Set the polarity of the selected pin
Parameters:
pin: (number) 1 to 16
polarity: (number) 0 = same logic state of the input pin, 1 = inverted logic state of the input pin
Returns: null


getPinPolarity(pin)

Get the polarity of the selected pin
Parameters:
pin: (number) pin to read, 1 to 16
Returns: (number) 0 = same logic state of the input pin, 1 = inverted logic state of the input pin


setPortPolarity(port, polarity)

Set the polarity of the pins on a selected port
Parameters:
port: (number) 0 = pins 1 to 8, 1 = pins 9 to 16
polarity: (number) between 0 and 255 or 0x00 and 0xFF. Each bit in the 8-bit number represents a pin on the port. 0 = same logic state of the input pin, 1 = inverted logic state of the input pin
Returns: null


getPortPolarity(port): 

Get the polarity for the selected IO port
Parameters:
port: (number) 0 = pins 1 to 8, 1 = pins 9 to 16
Returns: (number) between 0 and 255 (0xFF)


setBusPolarity(polarity)

Set the polarity of the pins on the bus
Parameters:
polarity: (number) 16-bit number 0 to 65535 (0xFFFF). For each bit 0 = same logic state of the input pin, 1 = inverted logic state of the input pin
Returns: null


getBusPolarity()

Get the polarity of the pins on the bus
Returns: (number) 16-bit number 0 to 65535 (0xFFFF). For each bit 0 = same logic state of the input pin, 1 = inverted logic state of the input pin

Usage

To use the IO Zero 32 library in your code you must first import the library:

var IOZero32 = require('../../lib/iozero32/iozero32');

Next, you must initialise the IOZero32 object

var bus1 = new IOZero32(0x20);

We will read the inputs 1 to 8 from bus 1 so set port 0 to be inputs

bus1.setPortDirection(0, 0xFF);

You can now read pin 1 with:

console.log('Pin 1: %d', bus1.readPin(1));

Home

Shop

Learn

Forum

FAQ

Contact

0 item

Your cart is empty

Please browse our shop to order from the wide range of Raspberry Pi boards and accessories.

Subtotal:£0.00
View Basket Continue to Checkout