Tools40 library, useful tool using our equipments

Tools40 library, useful tool using our equipments

This is Industrial Shields library for our different PLC’s 

Tools40 library include SimpleComm library, Filter library and Timer library.

With the SimpleComm library you can send data through any Arduino Stream: RS-485, RS-232, and Ethernet… It is enough flexible to support different kind of communication typologies: Ad-hoc, Master-Slave, Client-Server… Using an easy to use API.

Filter library includes filtering software that allow you to smooth analog inputs. This is really useful when you have an analog signal that is unstable.

With Timer library you can create 3 different timers like Ladder standard Timers:

  • PulseTimer : when there is a rising edge on input value, PulseTimer active Output during the selected time.
  • OnDelayTimer: when Input is active (HIGH) during the defined time, the related Output will be active. Output will be disabled when Input is inactive.
  • OffDelayTimer: As the same of OnDelayTimer, but when Input is inactive (LOW) during the defined time, the related Output will be active. Output will be disabled when Input is active.

Next it is explained how to use Filter library and the Timer library:

First you have to define the Timer or the Filter and give it a name. After that, you just have to create a variable and related with the wanted Input. On Timers the last step is to use this variable to selected Output. Next it is showed an example of how to use it.

Filter library:

#include <Filter.h>

// Create a filter
// Number of samples: 10
// Sample period: 5ms (setting it to 0, samples are taken as fast as possible)
AnalogFilter<10, 5> filter;

#if defined(ARDBOX_ANALOG)
int pin = I0_1;
#elif defined(ARDBOX_RELAY)
int pin = I0_4;
#elif defined(MDUINO_19R) || defined(MDUINO_38R) || defined(MDUINO_57R)
int pin = I0_2;
#elif defined(MDUINO_21) || defined(MDUINO_42) || defined(MDUINO_58)
int pin = I0_7;
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  // Init Serial port
  Serial.begin(9600L);

  // Set pin as INPUT pin
  pinMode(pin, INPUT);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // Read pin value
  int value = analogRead(pin);

  // Filter it
  int filtered = filter.update(value);

  // Print the filtered value
  Serial.println(filtered);
}

 

Timer library:

PulseTimer:

#include <Timer.h>

// Define a new OnDelayTimer with preset time of 3s
OnDelayTimer timer(3000);
int inputPin = I0_0;

#if defined(ARDBOX_ANALOG)
int outputPin = Q0_0;
#elif defined(ARDBOX_RELAY)
int outputPin = R3;
#elif defined(MDUINO_19R) || defined(MDUINO_38R) || defined(MDUINO_57R)
int outputPin = R0_1;
#elif defined(MDUINO_21) || defined (MDUINO_42) || defined(MDUINO_58)
int outputPin = Q0_0;
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  // Configure inputPin as input
  pinMode(inputPin, INPUT);

  // Configure outputPin as output
  pinMode(outputPin, OUTPUT);
  digitalWrite(outputPin, LOW);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // Read inputPin
  int input = digitalRead(inputPin);

  // Update timer using inputPin value and set outputPin associated variable value
  int output = timer.update(input);

  // Update outputPin with its associated variable value
  digitalWrite(outputPin, output);
}

 

OnDelayTimer:

#include <Timer.h>

// Define a new PulseTimer with preset time of 3s
PulseTimer timer(3000);
int inputPin = I0_0;

#if defined(ARDBOX_ANALOG)
int outputPin = Q0_0;
#elif defined(ARDBOX_RELAY)
int outputPin = R3;
#elif defined(MDUINO_19R) || defined(MDUINO_38R) || defined(MDUINO_57R)
int outputPin = R0_1;
#elif defined(MDUINO_21) || defined (MDUINO_42) || defined(MDUINO_58)
int outputPin = Q0_0;
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  // Configure inputPin as input
  pinMode(inputPin, INPUT);

  // Configure outputPin as output
  pinMode(outputPin, OUTPUT);
  digitalWrite(outputPin, LOW);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // Read inputPin
  int input = digitalRead(inputPin);

  // Update timer using inputPin value and set outputPin associated variable value
  int output = timer.update(input);

  // Update outputPin with its associated variable value
  digitalWrite(outputPin, output);
}

 

How to install Tools40 library to Arduino IDE.

  1. Download the Tools40 library from the GitHub. Click on: “Clone or download”. After that download the zip file on your desktop.
  2. Add the library on the Arduino IDE. Click on: Sketch–>Include library–>Add .ZIP library and choose “arduino-Tools40-master.zip”. After choose the arduino-Tools40-master.zip the library has to be charged. To verify the library is added correctly you can see the library on: //File–>Examples–>Tools40
  3. Now your library is correctly installed and you can see an example to how to use that library on our PLCs.

See also:

SIMPLECOMM LIBRARY

Comments are closed.