ModmataC  1.0
A C library for Arduino communication
Macros | Functions
ModmataC.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include "modbus/modbus.h"
Include dependency graph for ModmataC.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define IDLE   0
 
#define PINMODE   1
 
#define DIGITALWRITE   2
 
#define DIGITALREAD   3
 
#define ANALOGREFERENCE   4
 
#define ANALOGWRITE   5
 
#define ANALOGREAD   6
 
#define SERVOATTACH   7
 
#define SERVODETACH   8
 
#define SERVOWRITE   9
 
#define SERVOREAD   10
 
#define WIREBEGIN   11
 
#define WIREEND   12
 
#define WIRECLOCK   13
 
#define WIREWRITE   14
 
#define WIREREAD   15
 
#define SPIBEGIN   16
 
#define SPISETTINGS   17
 
#define SPITRANSFER   18
 
#define SPIEND   19
 
#define INPUT   0
 
#define OUTPUT   1
 
#define LOW   0
 
#define HIGH   1
 
#define LSBFIRST   0
 
#define MSBFIRST   1
 
#define SPI_MODE0   0x00
 
#define SPI_MODE1   0x04
 
#define SPI_MODE2   0x08
 
#define SPI_MODE3   0x0C
 

Functions

void closeConnection ()
 
void delay (int millis)
 
void delayMicroseconds (int micros)
 
int isValidPin (int pinNum)
 
int connectArduino (char *port, int baudRate, int id)
 
void pinMode (uint8_t pinNum, uint8_t mode)
 
void digitalWrite (uint8_t pinNum, uint8_t input)
 
int digitalRead (uint8_t pinNum)
 
void analogWrite (uint8_t pinNum, uint16_t input)
 
int analogRead (uint16_t pinNum)
 
void servoAttach (uint16_t pinNum)
 
void servoDetach (uint16_t pinNum)
 
void servoWrite (uint16_t pinNum, uint16_t input)
 
int servoRead (uint16_t pinNum)
 
void wireBegin ()
 
void wireEnd ()
 
void wireSetClock (uint32_t)
 
void wireWrite (uint8_t addr, uint8_t reg, uint8_t num_bytes, uint8_t *data)
 
uint8_t * wireRead (uint8_t addr, uint8_t reg, int num_bytes)
 
void spiBegin ()
 
uint8_t * spiTransferBuf (int CS_pin, uint8_t *buf, uint8_t length)
 
void spiSettings (uint32_t speed, uint8_t order, uint8_t mode)
 
void spiEnd ()
 
void transmitRegisters (uint8_t fn_code, uint8_t argc, uint8_t *argv)
 

Macro Definition Documentation

◆ ANALOGREAD

#define ANALOGREAD   6

◆ ANALOGREFERENCE

#define ANALOGREFERENCE   4

◆ ANALOGWRITE

#define ANALOGWRITE   5

◆ DIGITALREAD

#define DIGITALREAD   3

◆ DIGITALWRITE

#define DIGITALWRITE   2

◆ HIGH

#define HIGH   1

◆ IDLE

#define IDLE   0

◆ INPUT

#define INPUT   0

◆ LOW

#define LOW   0

◆ LSBFIRST

#define LSBFIRST   0

◆ MSBFIRST

#define MSBFIRST   1

◆ OUTPUT

#define OUTPUT   1

◆ PINMODE

#define PINMODE   1

◆ SERVOATTACH

#define SERVOATTACH   7

◆ SERVODETACH

#define SERVODETACH   8

◆ SERVOREAD

#define SERVOREAD   10

◆ SERVOWRITE

#define SERVOWRITE   9

◆ SPI_MODE0

#define SPI_MODE0   0x00

◆ SPI_MODE1

#define SPI_MODE1   0x04

◆ SPI_MODE2

#define SPI_MODE2   0x08

◆ SPI_MODE3

#define SPI_MODE3   0x0C

◆ SPIBEGIN

#define SPIBEGIN   16

◆ SPIEND

#define SPIEND   19

◆ SPISETTINGS

#define SPISETTINGS   17

◆ SPITRANSFER

#define SPITRANSFER   18

◆ WIREBEGIN

#define WIREBEGIN   11

◆ WIRECLOCK

#define WIRECLOCK   13

◆ WIREEND

#define WIREEND   12

◆ WIREREAD

#define WIREREAD   15

◆ WIREWRITE

#define WIREWRITE   14

Function Documentation

◆ analogRead()

int analogRead ( uint16_t  pinNum)

Reads the value of an analog pin

Parameters
(int)pin number
Returns
(int) value read from pin

Reads the value of an analog pin

Parameters
(uint8_t)address
(uint8_t)register
(uint8_t)number of bytes to read
Returns
(uint8_t*) pointer to the data that was read

◆ analogWrite()

void analogWrite ( uint8_t  pinNum,
uint16_t  input 
)

Writes an analog value to a pin

Parameters
(int)pin number
(int)value to be written
Returns
void

Writes an analog value to a pin

Parameters
(uint8_t)pin number
(uint16_t)value to write
Returns
(void)

◆ closeConnection()

void closeConnection ( )

disconnect modbus connection if the program does not have an infinite loop

Parameters
none
Returns
void

◆ connectArduino()

int connectArduino ( char *  port,
int  baudRate,
int  id 
)

Initiates connection between machine and Arduino

Parameters
(char*)path to port
(int)baud rate (9600 default)
(int)slave id
Returns
(int) 1 if connection is successful, 0 if failure

Start serial connection using specified port and baud rate

Parameters
(char*)path to the port on which Leonardo is connected
(int)baud rate
(int)slave id for Leonardo
Returns
(int) 1 if successful, 0 if unsuccessful

◆ delay()

void delay ( int  millis)

Causes the system to delay a number of miliseconds

Parameters
(int)milliseconds
Returns
void

◆ delayMicroseconds()

void delayMicroseconds ( int  micros)

◆ digitalRead()

int digitalRead ( uint8_t  pinNum)

Reads the value of a digital pin

Parameters
(int)pin number
Returns
(int) value read from pin

Reads the value of a digital pin

Parameters
(uint8_t)pin number
Returns
(int) value

◆ digitalWrite()

void digitalWrite ( uint8_t  pinNum,
uint8_t  input 
)

Writes a digital value (1 or 0) to a pin

Parameters
(int)pin number
(int)value to be written
Returns
void

Writes a HIGH or LOW value to a digital pin

Parameters
(uint8_t)pin number
(uint8_t)input, should be 1 or 0
Returns
(void)

◆ isValidPin()

int isValidPin ( int  pinNum)

Determines if a given pin number is valid (valid pins are 1-30)

Parameters
(int)pin number
Returns
(int) 1 if valid, 0 if invalid

Checks if a pin number is valid The leonardo has pins 1-30

Parameters
(int)pint number
Returns
(int) 1 if pin is valid, 0 if invalid

◆ pinMode()

void pinMode ( uint8_t  pinNum,
uint8_t  mode 
)

Sets the pin mode of a pin on the Arduino

Parameters
(int)pin number
(int)mode to set pin to
Returns
void

Sets pin mode

Parameters
(uint8_t)pin number
(uint8_t)pin mode
Returns
(void)

◆ servoAttach()

void servoAttach ( uint16_t  pinNum)

Attaches a servo to a pin

Parameters
(int)pin number
Returns
void

Attach servo to a pin

Parameters
(uint16_t)pin number
Returns
(void)

◆ servoDetach()

void servoDetach ( uint16_t  pinNum)

Detaches a servo from a pin

Parameters
(int)pin number
Returns
void

Detach servo from a pin

Parameters
(uint16_t)pin number
Returns
(void)

◆ servoRead()

int servoRead ( uint16_t  pinNum)

Reads the value last written to a servo

Parameters
(int)pin number
Returns
(int) angle value last written

Reads the last value written to a servo

Parameters
(uint16_t)pin number
Returns
(int) the last value written to the servo

◆ servoWrite()

void servoWrite ( uint16_t  pinNum,
uint16_t  input 
)

Writes an angle value to a servo

Parameters
(int)pin number
(int)angle value to write
Returns
void

Write values to a servo assigned pin

Parameters
(uint16_t)pin number
(uint16_t)angle value to be written
Returns
(void)

◆ spiBegin()

void spiBegin ( )

Begins SPI communication with default settings (4 Mbps, MSBFIRST, SPI_MODE0)

Returns
(void)

◆ spiEnd()

void spiEnd ( )

End SPI communication

Returns
(void)

◆ spiSettings()

void spiSettings ( uint32_t  speed,
uint8_t  order,
uint8_t  mode 
)

Set specific SPI settings such as communication speed, bit order, and mode

Parameters
(uint32_t)Communication speed
(uint8_t)bit order (MSBFIRST or LSBFIRST)
(uint8_t)data mode (SPI_MODE0, SPI_MODE1, SPI_MODE2, or SPI_MODE3)
Returns
(void)

◆ spiTransferBuf()

uint8_t* spiTransferBuf ( int  CS_pin,
uint8_t *  buf,
uint8_t  length 
)

Transfer an array of bytes over SPI

Parameters
(int)Chip Select pin number
(uint8_t*)Array of bytes to transfer over MOSI
(uint8_t)Array length
Returns
(uint8_t*) Array of bytes sent back over MISO

◆ transmitRegisters()

void transmitRegisters ( uint8_t  fn_code,
uint8_t  argc,
uint8_t *  argv 
)

Send bytes over Modmata. For use in custom Modmata functions

Returns
(void)

◆ wireBegin()

void wireBegin ( )

Begins an I2C connection

Returns
(void)

◆ wireEnd()

void wireEnd ( )

Terminates an I2C connection

Returns
(void)

◆ wireRead()

uint8_t* wireRead ( uint8_t  addr,
uint8_t  reg,
int  num_bytes 
)

Reads data from an I2C connection

Parameters
(uint8_t)address byte
(uint8_t)register byte
(uint8_t)number of bytes to read
Returns
(uint8_t*) array of bytes that were read

Reads data from an I2C connection

Parameters
(uint8_t)address
(uint8_t)register
(uint8_t)number of bytes to read
Returns
(uint8_t*) pointer to the data that was read

◆ wireSetClock()

void wireSetClock ( uint32_t  clock_speed)

Sets I2C clock speed

Parameters
(int)clock speed
Returns
(void)

◆ wireWrite()

void wireWrite ( uint8_t  addr,
uint8_t  reg,
uint8_t  num_bytes,
uint8_t *  data 
)

Writes data over an I2C connection

Parameters
(uint8_t)address byte
(uint8_t)register byte
(uint8_t)number of bytes to be written following the address and register
(uint8_t*)array of bytes being written
Returns
(void)

Writes data over an I2C connection

Parameters
(uint8_t)address
(uint8_t)register
(uint8_t)number of bytes to be written
(uint8_t)data being written
Returns
(void)