Project

General

Profile

Digital I/O

Introduction

Digital input/output is one of the fundamental building block of digital electronics.
Microcontrollers like the one at the heart of the ioNode allow programming the behavior of individual inputs & outputs.
This opens up the possibility of talking to many different devices simply by wiring them and toggling the appropriate signal lines.

Ports

On most microcontrollers, I/O pins are grouped together in 8-bit ports. On the ioNode, the atmega1284p microcontroller provides 4 such ports:
  • Port A
  • Port B
  • Port C
  • Port D

The dio library

The ioNode's pins are labeled sequentially from 0 to 29 (30 pins in total).
This is done to simplify both electronic design and software development.

The dio library provided as part of the Dooba SDK offers simple methods for managing these I/O pins.

Let's start by adding the library to our definition file:

# Firmware Element Configuration
# ...
deps:
  - dio

From there, we can use the void dio_output(uint8_t p) & void dio_input(uint8_t p) methods to configure a pin as output or input respectively.
Then, the void dio_hi(uint8_t p) & void dio_lo(uint8_t p) methods allow setting a pin high or low (or enabling / disabling the internal pull-up resistors when the pin is configured as an input).
Finally, the uint8_t dio_rd(uint8_t p) method allows reading the state of a pin that has been configured as an input.

void dio_output(uint8_t p)
Arguments:

  • p -> Sequential pin number

void dio_input(uint8_t p)
Arguments:

  • p -> Sequential pin number

void dio_hi(uint8_t p)
Arguments:

  • p -> Sequential pin number

void dio_lo(uint8_t p)
Arguments:

  • p -> Sequential pin number

uint8_t dio_rd(uint8_t p)
Arguments:

  • p -> Sequential pin number

Return Value:
0 -> Pin is low, 1 -> pin is high.

ioNode pin map

Below is the complete list of I/O pins available on the ioNode, in order:

  • 0 -> A7
  • 1 -> A6
  • 2 -> A5
  • 3 -> A4
  • 4 -> A3
  • 5 -> A2
  • 6 -> A1
  • 7 -> A0
  • 8 -> B0
  • 9 -> B1
  • 10 -> B2
  • 11 -> B3
  • 12 -> B4 - [ ioNode on-board LED ]
  • 13 -> B5 - [ SPI MOSI ]
  • 14 -> B6 - [ SPI MISO ]
  • 15 -> B7 - [ SPI SCK ]
  • 16 -> D2 - [ UART1 RX ]
  • 17 -> D3 - [ UART1 TX ]
  • 18 -> D4
  • 19 -> D5
  • 20 -> D6
  • 21 -> D7
  • 22 -> C0 - [ I2C SCL ]
  • 23 -> C1 - [ I2C SDA ]
  • 24 -> C2
  • 25 -> C3
  • 26 -> C4
  • 27 -> C5
  • 28 -> C6
  • 29 -> C7

Multi-purpose I/O

You might have noticed in the list above that some of the pins on these ports serve more than one purpose.
For example, the SPI Bus uses pins 13, 14 & 15.

Watch out for this: these lines can be used as general-purpose I/O, but only when their alternative function is not used.