FLEXBOOL programming iseasyintuitiveopen...
FLEXBOOL INPUTS
Analog Inputs: AI[0] - AI[7]
Functions: AI_GET (channel_No)
Examples: float volt = AI_GET (3), or
float volt = AI_GET (AI[3])
The AI_GET() function returns the value of the input voltage (float in Volts). FLEXBOOL Analog Inputs are processed by a 12-bit ADC.
** When necessary, all Analog Inputs can be used as an additional Digitall Inputs.
*** Depending on your project needs, the PLC panel LED indicator corresponding to each analog input can be configured to be active when the measured value is higher, or lower than a specified limit. See the Panel LED functions for more information.
Current Inputs: CI[0] - CI[7]
Functions: CI_GET (channel_No)
Examples: float mA = CI_GET (3), or
float mA = CI_GET (CI[3])
The CI_GET() function returns the value of the input current (float in mA). FLEXBOOL Current Inputs are processed by a 12-bit ADC.
** Depending on your project needs, the PLC panel LED indicator corresponding to each current input can be configured to be active when the measured value is higher, or lower than a specified limit. See the Panel LED functions for more information.
Functions: DI_GET (channel_No)
Examples: bool state = DI_GET (3), or
bool state = DI_GET (DI[3])
The DI_GET() function returns 0 for an open input (LOW) and 1 for a closed input (HIGH).
* All Digital Inputs are over-voltage and over-current protected.
** When necessary, all Analog Inputs can be used as additional Digitall Inputs.
*** Depending on your project needs, the PLC panel LED indicator corresponding to each digital input can be configured to be active at open or closed input. See the Panel LED functions for more information.
When it is necessary to interrupt the main program at a DI state change, the interrupt must be defined in the setup section of your code, as shown in the example below:
defineInterrupt (DI[0], UserFunc, RISING);
The defineInterrupt() function has 3 arguments - channel number (DI[0] - DI[7]), the User function name, and the type of the interrupt (RISING, FALLING, CHANGE). To avoid delays in the main loop, the User function executed in the interrupt must be as short as possible.
Functions:
RTD_CONFIG (channel_No, RTD_Type, Sensor_Wires)
RTD_GET (channel_No)
Examples:
RTD_CONFIG (1, PT100, 2); or
RTD_CONFIG (RTD[1], PT100, 2);
RTD_CONFIG (2, PT100, 3);
RTD_CONFIG (4, PT46, 2);
RTD_CONFIG (5, CU100, 2);
float airTemperature1 = RTD_GET (0), or
float airTemperature1 = RTD_GET (RTD[0]);
The RTD_GET() function returns the value of the measured temperature (float in °C). FLEXBOOL RTD inputs are processed by a 16-bit ADC. All RTD inputs are over-voltage and over-current protected.
** Depending on your project needs, the PLC panel LED indicator corresponding to each temperature input can be configured to be active when the measured value is higher, or lower than a specified limit. See the Panel LED functions for more information.
Functions:
NTC_GET (channel_No)
NTC_CONFIG_B (channel_No, Rnom, B_Coef)
NTC_CONFIG_R (channel_No, R1, T1, R2, T2, R3, T3)
Examples:
NTC_CONFIG_B (0, 10000, 3380), or
NTC_CONFIG_B (NTC[0], 10000, 3380)
NTC_CONFIG_R (1, 5000, 25, 2850, 40, 752, 80), or
NTC_CONFIG_R (NTC[1], 5000, 25, 2850, 40, 752, 80)
float airTemperature = NTC_GET (1), or
float airTemperature = NTC_GET (NTC[1])
float oilTemperature = NTC_GET (2);
The NTC_GET() function returns the value of the measured temperature (float in °C). FLEXBOOL NTC inputs are processed by a 12-bit ADC. All NTC inputs are over-voltage and over-current protected.
There are two ways to configure the NTC temperature sensor, depending on the information provided in the sensor datasheet: If you have the BETA-constant of the sensor you can use the NTC_CONFIG_B() function. In case the maker provided the Temperature/Resistance table, you can use the NTC_CONFIG_R() function.
The NTC_CONFIG_B() function has 3 arguments: channel number (NTC[0] - NTC[7]), NTC sensor's nominal resistance (integer in Ohms at T=25 °C), and NTC sensor's BETA-constant (integer in Degrees Kelvin).
The NTC_CONFIG_R() function has 7 arguments: channel number (NTC[0] - NTC[7]), and 3 Resistance/Temperature couples from the sensor datasheet as folows R1, T1, R2, T2, R3, T3, where temperatures are integers in °C, resistances are integers in Ohms, and T1 < T2 < T3.
Whichever CONFIG function you use, it must be included into the setup() section of your code.
* Depending on your project needs, the PLC panel LED indicator corresponding to each temperature input can be configured to be active when the measured value is higher, or lower than a specified limit. See the Panel LED functions for more information.
FLEXBOOL OUTPUTS
Digital Outputs: DO[0] - DO[7]
Functions:
DO_SET (channel_No, state)
DO_GET (channel_No)
Examples:
DO_SET (3, 1), or
DO_SET (DO[3], 1)
bool state = DO_GET (3), or
bool state = DO_GET (DO[3])
The DO_GET() function has 1 argument: the channel number (DO[0] - DO[7]). It returns the current state of the output (0, 1).
* FLEXBOOL Digital Outputs are rated for 200mA and over-current protected.
** Depending on your project needs, the PLC panel LED indicator corresponding to each digital output can be configured to be active when the output value is High, or Low. See the Panel LED functions for more information.
Functions:
REL_SET (channel_No, state)
REL_GET (channel_No)
Examples:
REL_SET (3, 1), or
REL_SET (R[3], 1)
bool state = REL_GET (3), or
bool state = REL_GET (R[3])
The REL_GET() function has 1 argument: the channel number (R[0] - R[7]). It returns the current state of the relay output (0, 1).
* FLEXBOOL relay outputs are rated for 5A.
** Depending on your project needs, the PLC panel LED indicator corresponding to each relay output can be configured to be active when the relay is switched ON or OFF. See the Panel LED functions for more information.
Functions:
PWM_SET (channel_No, value)
PWM_GET (channel_No)
PWM_FREQ_SET (frequency)
Examples:
PWM_SET (3, 37), or
PWM_SET (PWM[3], 37)
int value = PWM_GET (3), or
int value = PWM_GET (PWM[3])
PWM_FREQ_SET (500);
The PWM_GET() function returns the last setpoint of the channel in % (integer 0 - 100).
The PWM_FREQ_SET() configures the PWM outputs frequency function (common setting for all PWM channels). The function has one argument - the frequency in Hz. Allowed values are integers, from 50 to 1500 Hz. If not configured, the PWM outputs are working on the default frequency of 200 Hz.
* The PWM outputs amplitude is 10VDC.
** All PWM Outputs of FLEXBOOL PLC are over-current protected (10mA).
*** Depending on your project needs, the PLC panel LED indicator corresponding to each PWM output can be configured to be active when the output pulse width is higher, or lower than a specified limit. See the Panel LED functions for more information.
Functions:
AO_SET (channel_No, value)
float value = AO_GET (channel_No)
Examples:
AO_SET (3, 7.4), or
AO_SET (AO[3], 7.4)
AO_GET (3), or
AO_GET (AO[3])
The AO_GET() function returns the last setpoint of the output in Volts. It has one argument - the channel number (AO[0] - AO[7]).
FLEXBOOL Analog Outputs are processed by a 12-bit DAC.
* All Analog Outputs are over-current protected (10mA).
** Depending on your project needs, the PLC panel LED indicator corresponding to each analog output can be configured to be active when the output value is higher, or lower than a specified limit. See the Panel LED functions for more information.
COMMON FUNCTIONS
RTC_GET (time_parameter)
RTC_SET (time_parameter, value)
The RTC_SET() function has 2 arguments: time parameter and value. Available time parameters are as follows: Year, Month, Date, WeekDay, Hour, Minute, Second. as Allowed integer values are as follows: numbers 1-12 (for month), 1-31 (for date) 0-24 (for hour), 0-60 (for minutes and seconds), 1-7 (for weekdays).
The RTC_GET() function returns the value of the requested time parameter.
RTC_SET (Month, 8);
RTC_SET (Date, 29);
RTC_SET (WeekDay, 1); // 1 - MON, 2 - TUE, ... 7 - SUN
RTC_SET (Hour, 16);
RTC_SET (Minute, 10);
RTC_SET (Second, 0);
myTime[0] = RTC_GET (Year);
myTime[1] = RTC_GET (Month);
myTime[2] = RTC_GET (Date);
myTime[3] = RTC_GET (WeekDay);
myTime[4] = RTC_GET (Hour);
myTime[5] = RTC_GET (Minute);
myTime[6] = RTC_GET (Second);
listDir()
createDir()
removeDir()
writeFile()
appendFile()
readFile()
renameFile()
testFileIO()
deleteFile()
listDir (SD, "/", 2);
createDir (SD, "/sample");
removeDir (SD, "/sample");
writeFile (SD, "/hello.txt", "Hello");
appendFile (SD, "/hello.txt", "World!\n");
readFile (SD, "/hello.txt" );
renameFile (SD, "/hello.txt", "/foo.txt");
testFileIO (SD, "/foo.txt");
deleteFile (SD, "/foo.txt");
The createDir() function creates a new directory. Pass as an argument the SD filesystem and the directory name path.
The removeDir() function removes an existing directory. Pass as an argument the SD filesystem and the directory name path.
The writeFile() function creates a file and writes content to it. Pass as an argument, the SD filesystem, the file path and the content.
The appendFile() function appends content to a file (without overwriting previous content).
The readFile() function reads the content of a file and prints the content in the Serial Monitor. As with previous functions, pass as an argument the SD filesystem and the file path.
The renameFile() function changes the existing file name. Pass as arguments the SD filesystem, the original filename, and the new filename.
The testFileIO() function shows how long it takes to read the content of a file (ms).
The deleteFile() function to delete a file. Pass as an argument the SD filesystem and the file path of the file you want to delete.
* Before using the SD card, insert it into your computer and format it in FAT32 file system.
The nominal battery voltage and the maximum charging current are user-configurable. Depending on the specific needs of your project, a 12, or 24 VDC lead-acid, AGM battery (battery group) up to 10 Ah can be used.
PSU_SET_MAX_VCHARGE (value)
PSU_SET_MAX_ICHARGE (value)
PSU_SET_TCOMP (state)
Monitoring Functions:
PSU_GET_VIN() PSU_GET_VOUT() PSU_GET_IIN() PSU_GET_TDIE() PSU_CHARGE_STATUS() PSU_CHARGER_STATE() |
PSU_GET_ICHARGE_SP() PSU_GET_VBAT() PSU_GET_IBAT() PSU_GET_TBAT() |
Examples
PSU_SET_MAX_VCHARGE (27.3);
PSU_SET_MAX_ICHARGE (0.3);
PSU_SET_TCOMP (1);
Monitoring:
float V1 = PSU_GET_VIN();
float V2 = PSU_GET_VOUT();
float I1 = PSU_GET_IIN();
float Tchip = PSU_GET_TDIE();
float Vbatt = PSU_GET_VBAT();
float Isp = PSU_GET_ICHARGE_SP();
float Ib = PSU_GET_IBAT();
float Tbat = PSU_GET_TBAT();
int STATUS = PSU_CHARGE_STATUS();
int STATE = PSU_CHARGER_STATE();
PSU Diagram
Protection
Reverse BATT Polarity
Supply Over-Voltage
Supply Over-Current
BATT Over-Voltage
BATT Over-Current
BATT Over-Temperature
PSU Over-Temperature
Wrong BATT configuration
Charging Modes
Constant Voltage (CV)
Absorb Charge
Equalize Charge
The charging mode is automatically controlled depending on the battery condition and temperature.
Do not connect/disconnect the UPS Battery while the PLC is in operation!
Do not connect any external loads directly to the UPS Battery!
Function Description
PSU_SET_MAX_ICHARGE() function configures the maximum charging current of the connected battery (battery group). Allowed values are floats, from 0.1 to 1.0. Default: 0.1A.
When using the battery charger and the UPS functionality, both above functions must be included in the setup() section of your code.
PSU_GET_VIN() returns the value of the PSU input voltage (Vin) in Volts.
PSU_GET_VOUT() returns the value of the PSU ouput voltage (Vout) in Volts.
PSU_GET_IIN() returns the value of the PLC input current (see the PSU diagram) in Amperes.
PSU_GET_VBAT() returns the battery voltage in Volts.
PSU_GET_IBAT() returns the actual battery current in Amperes. Depending on the charger state, the value may be positive (charge), or negative (discharge).
PSU_GET_TBATT() function returns the battery temperature in degrees C. The battery temperature sensor (included) is 10 kOhm NTC with a B-coeficient 3490.
PSU_GET_TDIE() function returns the PSU temperature in degrees C (the temperature of the charger IC).
PSU_CHARGE_STATUS() function returns an integer, which value represents the following charge statuses:
0 - Charger Off
1 - Constant Voltage Charging (CV)
2 - Constant Current Charging (CC)
4 - High Input Current (Iin). Limitation active.
8 - Low Input Voltage (Vin). Limitation active.
16 - PSU Over-Temperature. Limitation active.
32 - High Charging Current. Limitation active.
PSU CHARGER_STATE() function returns an integer, which value represents the following charger states:
1 - Battery Fault
2 - Battery Missing
64 - Normal Charging (CC/CV)
256 - Charger Suspended
512 - Absorb Charge
1024 - Equalize Charge
2048 - Battery Detection
4096 - Battery Detection Failed
LED_MODE = 0; // User-controlled indicators
LED_MODE = 1; // Normal Panel LEDs (active on DI High, DO High, Relay ON)
LED_MODE = 2; // Reversed Panel LEDs (active on DI Low, DO Low, Relay OFF)
Analog I/O, Current Inputs, Temperature Inputs, and PWM Output's Indicators are always user-controlled (in all operatiom modes).
LED_SET (channel_No, LED_Brightness)
PLED_SET (process_No, LED_Brightness, LED_Color)
Examples:
LED_SET (DI[2]); LED_SET (DI[2], 3); LED_SET (RTD[3], 0); |
PLED_SET (13); PLED_SET (13, 7); PLED_SET (13, 7, Red); PLED_SET (24, 0); |
FLEXBOOL 3 Panel
FLEXBOOL Lite Panel
Function Description
The LED_SET() function has 2 arguments - channel number (DI[0], AI[2], R[5] and so on), and LED Brightness level (integer from 0 to 10). When the default LED brightness is used, only one argument can be passed to the function - the channel number. For example:
LED_SET (DI[3]) will switch ON the panel indicator of digital input DI[3] at default brightness level (3).
LED_SET (DI[3], 5) will switch ON the panel indicator of digital input DI[3] at brightness level 5.
LED_SET (AI[7], 0) will switch OFF the panel indicator of the AI[7].
The PLED_SET() function can be used when controlling the Process Indicators of FLEXBOOL Lite. It has 3 arguments - the process indicator number (1, 11, 12, 13, 14, 15, 2, 21, 22, 23, and so on), the brightness level (integer from 0 to 10) and the Color of the indicator (Green, or Red). When the default LED brightness and default LED color are used, only one argument can be passed to the function - the indicator number. For Example:
PLED_SET (24) will switch ON the Process Indicator 2.4 at default brightness level (5) and default color (Green).
PLED_SET (24, 3) will switch ON the Process Indicator 2.4 at brightness level 3, in default color (Green).
PLED_SET (1, 7, Red) will switch ON the Process Indicator 1 at brightness level 7, in Red color.
PLED_SET (13, 7, Green) will switch ON the Process Indicator 1.3 at brightness level 7, in Green color.
PLED_SET (24, 0) will switch OFF the Process Indicator 2.4 (both colors).
tft.fillScreen (TFT_BLACK);
tft.fillScreen (0x0000);
drawSdJpeg ("/arrow.jpg", 120, 155);
tft.setCursor (5, 15);
tft.setFreeFont (&FreeSans18pt7b);
tft.setTextColor (TFT_WHITE, TFT_BLACK);
tft.setTextSize (1);
tft.print ("Your text");
tft.print (float_var, 2);
tft.fillRect (0, 0, 238, 35, TFT_YELLOW);
tft.drawRoundRect (1, 1, 238, 238, 5, TFT_RED);
tft.fillRoundRect (1, 1, 238, 238, 5, TFT_BLUE);
tft.fillRectHGradient (1, 1, 238, 238, TFT_RED, TFT_WHITE);
tft.fillRectVGradient (1, 1, 238, 238, TFT_RED, TFT_BLACK);
tft.fillTriangle (1, 1, 238, 1, 118, 238, TFT_BLACK);
tft.drawCircle (120, 120, 100, TFT_RED);
tft.fillCircle (120, 120, 100, TFT_WHITE);
tft.drawLine (5, 5, 235, 235, TFT_WHITE);
tft.drawFastVLine (5, 5, 200, TFT_GREEN);
tft.drawFastHLine (5, 5, 200, TFT_CYAN);
Function Description
The drawSdJpeg() function draws a JPEG image stored on the FLEXBOOL SD Card starting form display point with defined coordinates. The function is included in the example code and uses the JPEGDecoder Library (both Bodmer libraries - TFT_eSPI and JPEGDecoder, must be installed and added in the Setup section of your code). Syntax:
drawSdJpeg(const char *filepath, uint8_t x0, uint8_t y0);
The drawRect() function draws rectangle from point with coordinates x0, y0. The next arguments are the rectangle width and heigth (in pixels) and the line color. Optionally, you can draw a rounded-corner rectangles, as well as color-, or gradient-filled rectangles. Syntax:
tft.drawRect (uint16_t x0, uint16_t y0, uint16_t width, uint16_t heigth, uint16_t color);
tft.fillRect (uint16_t x0, uint16_t y0, uint16_t width, uint16_t heigth, uint16_t color);
tft.drawRoundRect (uint16_t x0, uint16_t y0, uint16_t width, uint16_t heigth, uint16_t radius, uint16_t color);
tft.fillRoundRect (uint16_t x0, uint16_t y0, uint16_t width, uint16_t heigth, uint16_t radius, uint16_t color);
tft.fillRectHGradient (uint16_t x0, uint16_t y0, uint16_t width, uint16_t heigth, uint16_t color1, uint16_t color2);
tft.fillRectVGradient (uint16_t x0, uint16_t y0, uint16_t width, uint16_t heigth, uint16_t color1, uint16_t color2);
The drawTriangle() function draws a triangle with vertexes at points x0, y0, x1, y1, x2, y2, and specified line color. Similarly, the fillTriangle() function draws a filled triangle with the specified fill color. Syntax:
tft.drawTriangle (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
tft.fillTriangle (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
The drawCircle() function draws a circle with center located in coordinates x0, y0, and specified radius and line color.
tft.drawCircle (uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color);
tft.fillCircle (uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color);
The drawLine() function draws a line from point with coordinates x0, y0 to point x1, y1, with a specified color. For horizontal, or vertical lines, there are optimized line-drawing functions that avoid the angular calculations. In this case, initial point coordinates and line lenght (in pixels) are used as arguments:
tft.drawLine (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
tft.drawFastVLine (uint16_t x0, uint16_t y0, uint16_t lenght, uint16_t color);
tft.drawFastHLine (uint8_t x0, uint8_t y0, uint8_t lenght, uint16_t color);
The tft.print() function prints text, or variable value on the display with the pre-defined font, size, color and position.
tft.setCursor (uint16_t x, int16_t y);
tft.print ("Your text");
tft.print (your_variable);
You can set the cursor at the desired position and define text font, size and color, as well as the background color, which is very useful when you need to dynamically update the displayed data with a measured system parameters.
tft.setFreeFont (&FreeSans18pt7b);
tft.setTextSize (uint8_t text_size);
tft.setTextColor (uint16_t text_color, uint16_t background_color);
There are many pre-defined fonts and colors in the library, but you can also define your own color, or just pass a 16-bit value as an argument for the text color. If you are using one and same font (or text size), you can define it only ones in your code.
defineInterrupt (BTN[0], UserFunc, RISING);
The defineInterrupt() function has 3 arguments - button number (BTN[0] - BTN[2]), the User function name, and the type of the interrupt (RISING, FALLING, CHANGE).
Functions:
EXTIO_CONFIG (channel_No, channel_Type)
EXTIO_GET (channel_No, state)
EXTIO_SET (channel_No)
Examples:
EXTIO_CONFIG (EXTIO[0], 0);
EXTIO_CONFIG (EXTIO[1], 1);
EXTIO_SET (EXTIO[0], 1);
bool state = EXTIO_GET (EXTIO[1]);
The EXTIO_CONFIG() function defines the type of the selected EXTIO (0 for Output, or 1 for Input).
The EXTIO_GET() function returns the EXTIO state - Low (0), or High (1).
* There are no LED indicators on the panel dedicated to the status of the external IO. However, when necessary you can visualize their status on the PLC display, or you can use any panel LED (all panel indicators can be individually controlled by the developer program).
When it is necessary to interrupt the main program at EXTIO state change, the interrupt must be defined in the setup section of your code, as shown in the example below:
defineInterrupt(EXTIO[0], UserFunc, RISING);
The defineInterrupt() function has 3 arguments - channel number (EXTIO[0], or EXTIO[1]), the User function name, and the type of the interrupt (RISING, FALLING, CHANGE).
** When applied to an EXTIO pin, the defineInterrupt() function automatically configures the pin as an Input.
*** To avoid delays in the main loop, the User function executed in the interrupt must be as short as possible.
COMMUNICATION
The RS485 communication port of FLEXBOOL PLC is routed to the upper left pluggable terminal (see the pinout diagram) as well as to the front panel EXT connector. The port is surge protected and internally terminated by a 120 Ohm resistor.
RS485.begin (BaudRate);
RS485.end();
Note that serial communication Receive and Transmit pins are hardcoded in the FLEXBOOL core and should not be defined when the RS485 communication is started.
Example:
RS485.begin (9600);
byte RS485_DATA_SENT = 0x11;
RS485.write (RS485_DATA_SENT);
Serial.print ("Sent data over RS485: ");
Serial.println (RS485_DATA_SENT);
Serial.print ("Received data on RS485: ");
if (RS485.available()) {
byte RS485_DATA_RECEIVED = RS485.read();
Serial.println (RS485_DATA_RECEIVED);
UART.begin (BaudRate, SerialMode);
UART.end();
Note that serial communication Receive and Transmit pins are hardcoded in the FLEXBOOL core and should not be defined when the UART communication is started.
Example:
UART.begin (9600, SERIAL_8N1);
byte UART_DATA_SENT = 0x22;
UART.write (UART_DATA_SENT);
Serial.print ("Sent data over UART: ");
Serial.println (UART_DATA_SENT);
Serial.print ("Received data on UART: ");
if (UART.available()) {
byte UART_DATA_RECEIVED = UART.read();
Serial.println(UART_DATA_RECEIVED);
bool ethConnected = 0;
WiFi.onEvent (eventHandler); // network Event Handler
ETH.begin (FLEXBOOL_ETH);
where FLEXBOOL_ETH includes all necessary configuration setting for the communication between ESP32 and the physical ethernet tranceiver.
For static IP address, the following configuration function can be used:
ETH.config (device_IP, gateway, subnet, primaryDNS, secondaryDNS);
Configuration example:
ETH.config (IPAddress(192, 168, 1, 42), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0), IPAddress(192, 168, 1, 1), IPAddress(8, 8, 8, 8));
bool wifiConnected = 0;
WiFi.onEvent (eventHandler); // network Event Handler
const char * ssid = "Your Wifi SSID";
const char * password = "Your WiFi Password";
WiFi.begin (ssid, password);
For static IP address, the following configuration function can be used:
WiFi.config (device_IP, gateway, subnet, primaryDNS, secondaryDNS);
Configuration example:
WiFi.config (IPAddress(192, 168, 88, 47), IPAddress(192, 168, 88, 1), IPAddress (255, 255, 255, 0), IPAddress(192, 168, 88, 1), IPAddress(8, 8, 8, 8));
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
unsigned long BT_TIMER = 0;
float TEST_TEMP_1;
float TEST_TEMP_2;
String BT_DATA = "";
void TEST_BLUETOOTH(){
if (millis() - BT_TIMER > 1000){
TEST_TEMP_1 = (float) random (320, 340)/10;
TEST_TEMP_2 = (float) random (470, 490)/10;
BT_DATA = "Temperature 1: " + String ( TEST_TEMP_1, 1 ) + "°C";
SerialBT.println (BT_DATA);
BT_DATA = "Temperature 2: " + String ( TEST_TEMP_2, 1 ) + "°C";
SerialBT.println (BT_DATA);
BT_TIMER = millis();
}
if (SerialBT.available()) {
Serial.write (SerialBT.read());
}
}
byte SPI_SEND_DATA = 0xC7;
byte SPI_RECEIVED_DATA;
SPISettings mySetting (1000000, MSBFIRST, SPI_MODE0);
For this example EXTIO[1] pin will be used as chip Select (CS), so it must be configured as output and set initially High:
EXTIO_CONFIG (EXTIO[1], 0);
EXTIO_SET (EXTIO[1], 1);
SPI.beginTransaction (mySetting);
EXTIO_SET (EXTIO[1], 0); // set CS low
SPI_RECEIVED_DATA = SPI.transfer (SPI_SEND_DATA);
EXTIO_SET (EXTIO[1], 1); // set CS High
SPI.endTransaction();
Serial.print ("Sent data over SPI: ");
Serial.println (SPI_SEND_DATA, HEX);
Serial.print ("Received data on SPI: ");
Serial.println (SPI_RECEIVED_DATA, HEX);
#define DEVICE_ADDR 0x1B
byte MY_I2C_DATA = 0xC7;
byte I2C_RECEIVED_DATA_1;
byte I2C_RECEIVED_DATA_1;
xSemaphoreTake (share_i2c, portMAX_DELAY);
Wire.beginTransmission (DEVICE_ADDR);
Wire.write (MY_I2C_DATA);
bool I2C_success = !Wire.endTransmission();
if (I2C_success){
Wire.requestFrom (DEVICE_ADDR, 2);
I2C_RECEIVED_DATA_1 = Wire.read();
I2C_RECEIVED_DATA_2 = Wire.read();
}
xSemaphoreGive (share_i2c);
* The I2C communication is also internally used in FLEXBOOL PLC, so the WIRE.h library is included in FLEXBOOL core and the communication automatically starts during the PLC initialization. To prevent any communication problems, when connecting external I2C devices, always use the xSemaphore as shown in the above example. Pay attention to the configured device address and avoid conflict with addresses that are in use internally:
FLEXBOOL Lite: 0x20, 0x22, 0x3C, 0x3F, 0x48, 0x50, 0x68, 0x6F.
FLEXBOOL 2: 0x20, 0x21, 0x22, 0x3C, 0x3F, 0x48, 0x50, 0x68, 0x6F.
FLEXBOOL 3: 0x14, 0x20, 0x21, 0x22, 0x3C, 0x3F, 0x40, 0x48, 0x49, 0x4B, 0x50, 0x68, 0x6F.
SERVICE FUNCTIONS
bool SYS_STATE = HW_CHECK();
In case a hardware problem is detected, the individual health status of the internal ICs can be additionally checked as shown in the code example.
SYS_HEALTH[1] - Real Time Clock
SYS_HEALTH[2] - System EEPROM
SYS_HEALTH[3] - Panel LED Drivers
SYS_HEALTH[4] - Panel buttons & EXTIO Driver
SYS_HEALTH[5] - Analog Inputs ADC
SYS_HEALTH[7] - Current Inputs ADC
SYS_HEALTH[8] - RTD Inputs ADC
SYS_HEALTH[9] - NTC Inputs ADC
SYS_HEALTH[10] - Digital Outputs Driver
SYS_HEALTH[11] - PWM Driver
SIGNAL_CONDITIONER (Channel_No, Gain, Offset)
The signal conditioning is applicable for all analog inputs of FLEXBOOL PLC - AI[0] - AI[7], current inputs CI[0] - CI[7], temperature inputs RTD[0] - RTD[7] and NTC[0] - NTC[7].
Examples:
SIGNAL_CONDITIONER (AI[2], 1.01, -0.2);
SIGNAL_CONDITIONER (CI[0], 1.03, 0.15);
SIGNAL_CONDITIONER (RTD[1], 1.0, -0.2);
SIGNAL_CONDITIONER (NTC[7], 1.02, 0.2);
The default value of Gain parameter for all Input channels is 1.00.
The default value of Offset parameter for all Input channels is 0.