Browsed by
Category: How to use

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

How to connect and configure a load cell using HX711 transmitter with Arduino based PLC

How to connect and configure a load cell using HX711 transmitter with Arduino based PLC

In this post is showed how to use a load cell transductor with our equipment’s for example an Ardbox analog. Load cell is a transductor that generate an electrical signal directly proportional to the measured force.

On market there are different transmitters that can convert this analog signal to digital. In this example is used the HX711 that is very used in industrial applications. HX711 get and convert the analog signal from the load cell to digital with his intern converter A/D of 24 bits.

How to connect the different devices?

Read More Read More

How to generate a different PWM’s signals with Arduino based PLC

How to generate a different PWM’s signals with Arduino based PLC

On this example is explained how to generate a PWM with M-DUINO  and ARDBOX 

In our equipment’s you can generate a PWM on Digital/Analog Ports. But most of these ports have a limitation of frequency (500 Hz approx.). PIN3 for ARDBOX and PIN3 and PIN2 for M-DUINO don’t have limitation and they can generate a PWM between 100Hz (even less) and 8MHz.

PIN3 for ARDBOX can work as an external output for the Timer/Counter0 Output Compare B (OC0B). And the same on M-DUINO: PIN3 can work as an external output for the Timer/Counter3 Output Compare C (OC3C) and PIN2 can work as an external output for the Timer/Counter3 Output Compare B (OC3B).

But how can we set up the frequency needed?

Read More Read More

SimpleComm library to send data through any Arduino Stream

SimpleComm library to send data through any Arduino Stream

This is Industrial Shields library for different PLC’s 

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

Reference:

SimplePacket encapsulates the data into a packet and provides these functions:

setData(data)

Fill up the packet with the desired data to send or the received data from a remote device. It is possible to fill up the packet with different types of data: bool, char, unsigned char, int, unsigned int, long, unsigned long, double, const, const char, const void.

Read More Read More