Project tutorial
Turn Your Arduino Board Into 16-Bit IO Port

Turn Your Arduino Board Into 16-Bit IO Port © GPL3+

Give 16-bit digital output or get 16-bit digital input from any Arduino pins.

  • 34 views
  • 0 comments
  • 0 respects

Components and supplies

Necessary tools and machines

Apps and online services

About this project

Arduinolibrary for 16-bit IO port

Turnyour Arduino board into 16-bit IO port

Title sounds interesting? or no?

You all will wonder, Arduino UNO or NANO (or other such similar arduino boards)have ATMega328 onboard microcontroller and that is an 8 bit device. Then how it can generate 16-bit output or take 16-bit input?

Also we all know that, the arduino gives digital output using “digitalWrite()”function and gets digital input through “digitalRead()” function. But using these two functions, it can give output or get input from any one pin - means at a time it can give output to or take input from single pin only. Then how it can give output or take input from 16 pins simultaneously?

What if we can club (combine) 16 Arduino board pins together? Means, with onboard 8-bit microcontroller, arduino can give 16-bit output and/or can get 16-bit input.

Now I think this sounds interesting?

So, here I present 16-bit IO Port (input-output port) library for arduino. Using this library one can send direct 16 bit data to any arduino board pins configured as a combined 16-bit port or can get 16-bit input from these configured pins. This library clubs any 16 pins of arduino together to work as 16-bit IO port. Just one has to select any 16 arduino pins to be combined as 16-bit port and it has to configure its data direction as input or output. Data direction is set by character ‘O’ for output or ‘I’ for input.

The library has only 5 functions. There are two constructors that will create port object(s), one function to send 16-bit digital output to port pins, one function to get 16-bit digital input from port pins and one additional function to alter / set IO direction of port. Here all 5 functions are explained in brief and there after some examples are given with explanations.

So just use this library to interface any 16 bit device like ADC, DAC, MUX, or any digital device get 16-bit input or give 16-bit output

1. IO_Port_16bit(int pin1, intpin2, int pin3, int pin4, int pin5, int pin6, int pin7, int pin8, int pin9, intpin10, int pin11, int pin12, int pin13, int pin14, int pin15, int pin16, char dir)

This is constructor. It will create object(s) of this class and thus it will create one or many 16-bit port(s) by combining distinct arduino pins. One has to specify 16 different arduino pins to be combined as port along with data direction as input or output - means port works as either input or output. The last argument dir in this constructor defines port works as input or output. If dir='O' means port work as output and if dir='I', port works as input. The same port cannot work as input and output both simultaneously or even alternatively. Also it indicates error if data direction is not selected

2. IO_Port_16bit(int pin1, intpin2, int pin3, int pin4, int pin5, int pin6, int pin7, int pin8, int pin9, intpin10, int pin11, int pin12, int pin13, int pin14, int pin15, int pin16)

This is another constructor. It will also create object(s) of this class and thus it will create one or many 16-bit port(s) by combining distinct arduino pins. One has to specify 16 different arduino pins to be combined as port. But it does not specify the data direction as input or output. After creating port object using this constructor, one has to set the port direction using set_IO_direction function. So this constructor allows programmer to alter port data direction in run time using this constructor, the same port can work as input or output alternatively (but not simultaneously)

3. set_IO_direction(char dir)

This function specifies the input/output direction of port. It has one character argument that can be 'I' for port as input or 'O' for port as output. If data direction is not selected, it displays error on serial monitor of arduino

4. send_16bit_data(unsigned int byt)

This function sends 16 bit data to specified pins. Just give int data (must be < 65535) as an argument that is directly given to 16 different pins. If data is >65535 it displays error on serial monitor of arduino.

5. get_16bit_data(void)

This function gets 16 bit data from specified pins. It returns 16-bit unsigned int data by reading status of 16 different pins

Example1: take 16-bit input and display it on serial monitor

#include<IO_Port_16bit.h>

IO_Port_16bit my16bitport(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);

int i;

long input_double_byte;

void setup()

{

// put your setup code here, to run once:

my16bitport.set_IO_direction('I');

Serial.begin(9600);

}

void loop()

{

input_double_byte =my16bitport.get_16bit_data();

Serial.print("input data: ");

Serial.println(input_double_byte);

delay(1000);

}

Example2: 16 LED chaser program

#include <IO_Port_16bit.h>

IO_Port_16bitmy16bitport(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);

void setup()

{

// declareport direction as output specifying ‘O’

my16bitport.set_IO_direction('O');

}

void loop()

{

unsigned int i;

for(i=1;i<65535;i*=2)

{

my16bitport.send_16bit_data(i); //send data as 2, 4, 8, 16

delay(200); // 32,..,..,...65534

}

}

Code

16-bit IO port libraryC/C++
send 16-bit output or get 16-bit input from arduino board
No preview (download only).

Schematics

16-bit IO port of arduino NANO
send 16-bit output or get 16-bit input
Input port 16 bit lvcuwh5vkl

Comments

Similar projects you might like

8-Bit IO Port Library for Arduino

Project tutorial by ambhatt

  • 5,137 views
  • 7 comments
  • 11 respects

NANO I2C IO Expander

Project tutorial by Joel Soranzo

  • 3,350 views
  • 2 comments
  • 8 respects

Inexpensive Wireless Interactive Board

Project tutorial by Adellar Irankunda

  • 14,194 views
  • 4 comments
  • 19 respects

Turn On/Off TV Sound System Using the TV IR Remote Control

Project tutorial by Lugh

  • 1,456 views
  • 1 comment
  • 6 respects

Using SPI Port 2 for Nokia LCD

Project showcase by Tom van Loon

  • 1,430 views
  • 0 comments
  • 2 respects

Turn your RC Car to Bluetooth RC car

Project tutorial by Prajjwal Nag

  • 18,943 views
  • 2 comments
  • 24 respects
Add projectSign up / Login