nanoI2CSlaveExpander
ARDUINO Nano v3 used as I2C slace digital and analog io expander for ESP8266 and others...
nanoI2CIOExpander.ino File Reference
#include <Wire.h>
#include "debugSerialPort.h"
#include "config.h"

Go to the source code of this file.

Functions

void setup ()
 ARDUINO setup function. More...
 
void loop ()
 ARDUINO loop, cyclicly update analog registers and digital. More...
 
void receiveEvent (int howMany)
 i2c receiver handler More...
 
void requestEvent ()
 I2C transmit handler for Read request. More...
 
void regInit ()
 initialisation of the register bank More...
 
int i2cBuildAddress ()
 Build i2c slave address with base ored with D12..D10 pin state. More...
 
void updateAnalogs ()
 as its name tells us update analog registers with analog inputs values More...
 
void updateDigitals ()
 update digital registers and digital outputs More...
 

Variables

byte registers [MAXREG]
 Main registers bank. See config.h MAXREG macro for full mapping;. More...
 
int octetsRec = 0
 number of i2C received bytes More...
 
int reg = 1
 global variable to track the registers address for i2c requests More...
 

Function Documentation

◆ i2cBuildAddress()

int i2cBuildAddress ( )

Build i2c slave address with base ored with D12..D10 pin state.

Returns
the builded address

Definition at line 205 of file nanoI2CIOExpander.ino.

◆ loop()

void loop ( )

ARDUINO loop, cyclicly update analog registers and digital.

Returns
no return and no input parameter

The cyclical update of the registers is not very fast. We could do this in a better way

Todo:
improve the speed by updating i/o in a better way.

Definition at line 111 of file nanoI2CIOExpander.ino.

◆ receiveEvent()

void receiveEvent ( int  howMany)

i2c receiver handler

Parameters
howMany: nomber of received bytes (dosen't work if there is a Serial.print in the handler)
Returns
nothing
Todo:
check for wrong parameters number

Definition at line 133 of file nanoI2CIOExpander.ino.

◆ regInit()

void regInit ( )

initialisation of the register bank

Works on global registers array.

Definition at line 178 of file nanoI2CIOExpander.ino.

◆ requestEvent()

void requestEvent ( )

I2C transmit handler for Read request.

Definition at line 167 of file nanoI2CIOExpander.ino.

◆ setup()

void setup ( )

ARDUINO setup function.

Returns
no return value and no parameters

Prepare i2c slave address

Set debug port speed if DEBUG is enabled in the config.handler

Display Startup screen with build i2c add

Register 2 i2c event functions

Initialize registers

Display initialized registers

Definition at line 73 of file nanoI2CIOExpander.ino.

◆ updateAnalogs()

void updateAnalogs ( )

as its name tells us update analog registers with analog inputs values

Returns
nothing and no input parameters

Works on global registers arrays

Definition at line 227 of file nanoI2CIOExpander.ino.

◆ updateDigitals()

void updateDigitals ( )

update digital registers and digital outputs

Returns
nothing and no input parameters

Works on global registers arrays

Definition at line 246 of file nanoI2CIOExpander.ino.

Variable Documentation

◆ octetsRec

int octetsRec = 0

number of i2C received bytes

Definition at line 97 of file nanoI2CIOExpander.ino.

◆ reg

int reg = 1

global variable to track the registers address for i2c requests

Definition at line 98 of file nanoI2CIOExpander.ino.

◆ registers

registers

Main registers bank. See config.h MAXREG macro for full mapping;.

Definition at line 54 of file nanoI2CIOExpander.ino.