Overview
The Communication module provides comprehensive protocol implementations for both wired (I2C, Modbus, Serial, SPI) and wireless (LoRa, ESP-NOW) connectivity in embedded systems.
I2C Communication
I2CScanner
Detect and scan I2C devices on the bus.
#define ENABLE_MODULE_I2C_SCANNER
#include "Kinematrix.h"
I2CScanner scanner;
scanner . beginTransmission ();
scanner . scanI2CAddress (); // Scans and prints all I2C devices
scanner . endTransmission ();
Initialize I2C transmission for scanning
Scan and detect all connected I2C devices on the bus
Complete I2C transmission
Modbus Protocol
modbusDevice
Industrial communication protocol implementation for RTU and ASCII modes.
#define ENABLE_MODULE_MODBUS_DEVICE
#include "Kinematrix.h"
modbusDevice device;
device . setId ( 1 ); // Set Modbus slave ID
byte id = device . getId ();
Set the Modbus device ID Device ID (1-247 for Modbus RTU)
Get the current Modbus device ID Returns the device ID as a byte
Serial Communication
EnhancedSerial
Production-grade serial communication with advanced features including buffering, error handling, and callbacks.
#define ENABLE_MODULE_SERIAL_ENHANCED
#include "Kinematrix.h"
EnhancedSerial serial ( 512 ); // 512-byte buffer
serial . begin ( & Serial1, 2000 ); // 2-second timeout
serial . setEcho ( true );
serial . addData (temperature, ';' );
serial . addData (humidity, ';' );
serial . sendData ();
Create enhanced serial instance Circular buffer size in bytes
Initialize the serial connection Pointer to hardware serial (Serial, Serial1, etc.)
timeout
unsigned long
default: "1000"
Timeout in milliseconds
Add data to send buffer with separator Data of any type (template)
Send accumulated data buffer Returns true if data sent successfully
Send data and execute callback on receive Callback function for received data
Read string until terminator character timeout
unsigned long
default: "1000"
Read timeout in milliseconds
Enable/disable echo mode for debugging
Get the last error code Returns Error enum: NONE, TIMEOUT, BUFFER_OVERFLOW, INVALID_DATA, MEMORY_ERROR
LoRa Communication
LoRaClass
Long-range wireless communication (up to 10km) for IoT and remote sensing.
#define ENABLE_MODULE_LORA_BASE
#include "Kinematrix.h"
LoRa . setPins ( 10 , 9 , 2 ); // SS, Reset, DIO0
if ( LoRa . begin ( 915 E 6 )) { // 915 MHz frequency
LoRa . setSpreadingFactor ( 7 );
LoRa . setSignalBandwidth ( 125 E 3 );
// Send packet
LoRa . beginPacket ();
LoRa . print ( "Hello LoRa" );
LoRa . endPacket ();
}
Initialize LoRa module Frequency in Hz (e.g., 433E6, 915E6)
Returns 1 on success, 0 on failure
Finish and send the packet
Check for incoming packet Returns packet size in bytes, 0 if no packet available
Set spreading factor (6-12) Spreading factor (higher = longer range, lower speed)
Set signal bandwidth Bandwidth in Hz (7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3, 41.7E3, 62.5E3, 125E3, 250E3, 500E3)
Get RSSI of last received packet Returns RSSI in dBm
Get SNR of last received packet Returns SNR in dB
ESP-NOW
ESPNow
Peer-to-peer mesh networking for ESP32/ESP8266 (no WiFi infrastructure required).
#define ENABLE_MODULE_ESP_NOW
#include "Kinematrix.h"
ESPNow espnow;
void onSend ( const uint8_t * mac , esp_now_send_status_t status ) {
Serial . println (status == ESP_NOW_SEND_SUCCESS ? "Success" : "Fail" );
}
void onReceive ( const uint8_t * mac , const uint8_t * data , int len ) {
Serial . printf ( "Received %d bytes \n " , len);
}
espnow . begin (onSend, onReceive);
espnow . addMacAddress ( "AA:BB:CC:DD:EE:FF" );
espnow . broadcastData (( uint8_t * ) "Hello" , 5 );
Initialize ESP-NOW Callback for received data
Add peer device by MAC address MAC address string (e.g., “AA:BB:CC:DD:EE:FF”)
Master flag (1 for master, -1 for slave)
Send data to specific peer
Broadcast data to all peers err_callback
void (*)()
default: "nullptr"
Optional error callback
Protocol Comparison
Protocol Range Speed Power Use Case I2C <1m 400kHz Low Sensors, displays Serial <100m 115200+ Low Debug, GPS Modbus <1000m 9600-115200 Medium Industrial control LoRa 10km+ 0.3-50kbps Low IoT, remote sensing ESP-NOW 200m 1Mbps Medium Mesh networks
ESP32 All protocols including WiFi-based
ESP8266 WiFi protocols, basic wired
AVR Wired protocols, basic LoRa