fbpx

HITIPanel


Video tutorials

Welcome to this series of tutorials to quickly get started with HITIPanel. Each tutorial takes about 5 minutes to complete.

BEFORE STARTING

REQUIRED COMPONENTS AND WIRING

You will need an Arduino Uno and several components to complete these tutorials. You can find these components in the Arduino Starter Kit (it is not a big deal if you don’t have all of them). Before starting, please perform the following wiring :

  • Schematic
  • Pin 3, 6, 8 : Switch, LED, Servo
  • Pin A0, A1, A2 : Potentiometer, Temperature sensor, Photoresistor

1. INSTALLATION

1. INSTALLATION

See how to install HITIPanel and the Arduino libraries (HITIComm and HITICommSupport).

2. BASICS

2. Control and monitoring

Learn how to get your Arduino sketch and HITIPanel project ready for I/O control and monitoring, and how to use the Control Panels to monitor the switch on pin 3 and to control the on-board LED on pin 13.

Sketch

#include <HITIComm.h>

// pins assignment
const int pin_Switch = 3;
const int pin_LED = LED_BUILTIN;

void setup()
{
    // initialize HITIComm library
    HC_begin(); 

    // pins mode
    pinMode(pin_Switch, INPUT);  // pin 3  -> INPUT
    pinMode(pin_LED, OUTPUT);    // pin 13 -> OUTPUT

    // switch the on-board LED ON
    digitalWrite(pin_LED, HIGH);
}

void loop()
{
    // communicate with HITIPanel
    // => to place at the beginning of the loop()
    HC_communicate(); 
}

3. Data acquisition and export

Discover how to use the Chart to acquire, plot and export your data to Excel and Text files.

4. Analog inputs, PWM and Servos

See how to control and monitor an analog input (potentiometer on pin A0), a PWM output (LED on pin 6) and a Servo (on pin 8).

Sketch

// include HITIComm library
#include <HITIComm.h>

// pins assignment
const int pin_Switch  = 3;
const int pin_BlueLED = 6;
const int pin_Servo   = 8;
const int pin_LED     = LED_BUILTIN;

void setup()
{
    // initialize HITIComm library
    HC_begin();

    // pins mode
    pinMode(pin_Switch, INPUT);     // pin 3  -> INPUT
    pinMode(pin_BlueLED, OUTPUT);   // pin 6  -> OUTPUT
    pinMode(pin_LED, OUTPUT);       // pin 13 -> OUTPUT

    // pwm
    HC_outputType(pin_BlueLED, PWM);  // pin 6  -> PWM

    // servo
    HC_attachServo(pin_Servo);        // pin 8  -> SERVO OUTPUT

    // initialize output values
    analogWrite(pin_BlueLED, 127);
    HC_servoWrite(pin_Servo, 120500); // 120.5°
    digitalWrite(pin_LED, HIGH);
}

void loop()
{
    // communicate with HITIPanel
    // => to place at the beginning of the loop()
    HC_communicate();
}

5. Program values (HITI Data)

Discover how to control and monitor Arduino program values. For this purpose, HITIPanel exchange data with your Arduino that we call HITI Data :

Sketch

// include HITIComm library
#include <HITIComm.h>

// pins assignment
const int pin_Switch  = 3;
const int pin_BlueLED = 6;
const int pin_Servo   = 8;
const int pin_LED     = LED_BUILTIN;
const int pin_Potentiometer     = A0;
const int pin_TemperatureSensor = A1;

// digital data assignment
const int dd_VirtualSwitch  = 0;
const int dd_BooleanWatcher = 1;

// analog data assignment
const int ad_ControlValue          = 0;
const int ad_Temperature_voltage   = 1;
const int ad_Temperature_celsius   = 2;

void setup()
{
    // initialize HITIComm library
    HC_begin();

    // pins mode
    pinMode(pin_Switch, INPUT);     // pin 3  -> INPUT
    pinMode(pin_BlueLED, OUTPUT);   // pin 6  -> OUTPUT
    pinMode(pin_LED, OUTPUT);       // pin 13 -> OUTPUT

    // pwm
    HC_outputType(pin_BlueLED, PWM);  // pin 6  -> PWM

    // servo
    HC_attachServo(pin_Servo);        // pin 8  -> SERVO OUTPUT

    // initialize output values
    analogWrite(pin_BlueLED, 127);
    HC_servoWrite(pin_Servo, 120500); // 120.5°
    digitalWrite(pin_LED, HIGH);
}

void loop()
{
    // communicate with HITIPanel
    // => to place at the beginning of the loop()
    HC_communicate();

    // read threshold value from HITIPanel
    float threshold = HC_analogDataRead(ad_ControlValue);

    // check if potentiometer value has reached threshold value
    bool reached = (analogRead(pin_Potentiometer) > threshold);

    // send boolean value to HITIPanel
    HC_digitalDataWrite(dd_BooleanWatcher, reached);

    // read temperature sensor raw values
    int rawTemp = analogRead(pin_TemperatureSensor);

    // convert to voltage V (using 5V power supply)
    float voltage = ((float)rawTemp / 1024) * 5.0;

    // convert to degrees °C
    // (TMP36 sensor => +/-10mV/°C, 750mV at 25°C)
    float celsius = (voltage - 0.5) * 100;

    // send analog values to HITIPanel
    HC_analogDataWrite(ad_Temperature_voltage, voltage);
    HC_analogDataWrite(ad_Temperature_celsius, celsius);
}

3. ADVANCED

6. Smoothing AND FILTERING sensor data

Learn how to apply digital filters (average + median) on your sensor data to remove noise and improve sensor resolution. Filtering is particularly interesting for sensors with poor resolution or placed in environments with strong electrical noise.

Note: Median filter will be available from HITIComm v1.5.2

Sketch

// include HITIComm library
#include <HITIComm.h>
#include <HC_SignalFilter.h>

// pins assignment
const int pin_Switch  = 3;
const int pin_BlueLED = 6;
const int pin_Servo   = 8;
const int pin_LED     = LED_BUILTIN;
const int pin_Potentiometer     = A0;
const int pin_TemperatureSensor = A1;

// digital data assignment
const int dd_VirtualSwitch  = 0;
const int dd_BooleanWatcher = 1;

// analog data assignment
const int ad_ControlValue          = 0;
const int ad_Temperature_voltage   = 1;
const int ad_Temperature_celsius   = 2;
const int ad_Temperature_celsius_f = 3;

// signal filter
HC_SignalFilter filter_average;
HC_SignalFilter filter_median;

void setup()
{
    // initialize HITIComm library
    HC_begin();

    // pins mode
    pinMode(pin_Switch, INPUT);     // pin 3  -> INPUT
    pinMode(pin_BlueLED, OUTPUT);   // pin 6  -> OUTPUT
    pinMode(pin_LED, OUTPUT);       // pin 13 -> OUTPUT

    // pwm
    HC_outputType(pin_BlueLED, PWM);  // pin 6  -> PWM

    // servo
    HC_attachServo(pin_Servo);        // pin 8  -> SERVO OUTPUT

    // initialize output values
    analogWrite(pin_BlueLED, 127);
    HC_servoWrite(pin_Servo, 120500); // 120.5°
    digitalWrite(pin_LED, HIGH);

    // increase the buffer size to improve filtering
    // (default: 10, max: 255)
    filter_average.setBufferSize(50);
    filter_median.setBufferSize(5);
}

void loop()
{
    // communicate with HITIPanel
    // => to place at the beginning of the loop()
    HC_communicate();

    // read threshold value from HITIPanel
    float threshold = HC_analogDataRead(ad_ControlValue);

    // check if potentiometer value has reached threshold value
    bool reached = (analogRead(pin_Potentiometer) > threshold);

    // send boolean value to HITIPanel
    HC_digitalDataWrite(dd_BooleanWatcher, reached);

    // read temperature sensor raw values
    int rawTemp = analogRead(pin_TemperatureSensor);

    // convert to voltage V (using 5V power supply)
    float voltage = ((float)rawTemp / 1024) * 5.0;

    // convert to degrees °C
    // (TMP36 sensor => +/-10mV/°C, 750mV at 25°C)
    float celsius = (voltage - 0.5) * 100;

    // apply average + median filter on °C values
    float celsius_f = filter_average.average(filter_median.median(celsius));

    // send analog values to HITIPanel
    HC_analogDataWrite(ad_Temperature_voltage, voltage);
    HC_analogDataWrite(ad_Temperature_celsius, celsius);
    HC_analogDataWrite(ad_Temperature_celsius_f, celsius_f); 
}

7. Controlling tasks duration in your program

Discover how to use our non-blocking Timing library to control the duration of tasks in your program, as a replacement for the blocking function delay(). Indeed, a blocking function placed inside the loop() prevents your program from doing anything else in parallel, including control and monitoring with HITIPanel.

Sketch

// include HITIComm library
#include <HITIComm.h>
#include <HC_SignalFilter.h>
//#include <HC_MultiTimer.h>

// pins assignment
const int pin_Switch  = 3;
const int pin_BlueLED = 6;
const int pin_Servo   = 8;
const int pin_LED     = LED_BUILTIN;
const int pin_Potentiometer     = A0;
const int pin_TemperatureSensor = A1;

// digital data assignment
const int dd_VirtualSwitch  = 0;
const int dd_BooleanWatcher = 1;

// analog data assignment
const int ad_ControlValue          = 0;
const int ad_Temperature_voltage   = 1;
const int ad_Temperature_celsius   = 2;
const int ad_Temperature_celsius_f = 3;

// signal filter
HC_SignalFilter filter_average;
HC_SignalFilter filter_median;

// timer
HC_Timer timer;
//HC_MultiTimer timers(4);  // include 4 Timers

// variable
bool led_state = false;

void setup()
{
    // initialize HITIComm library
    HC_begin();

    // pins mode
    pinMode(pin_Switch, INPUT);     // pin 3  -> INPUT
    pinMode(pin_BlueLED, OUTPUT);   // pin 6  -> OUTPUT
    pinMode(pin_LED, OUTPUT);       // pin 13 -> OUTPUT

    // pwm
    HC_outputType(pin_BlueLED, PWM);  // pin 6  -> PWM

    // servo
    HC_attachServo(pin_Servo);        // pin 8  -> SERVO OUTPUT

    // initialize output values
    analogWrite(pin_BlueLED, 127);
    HC_servoWrite(pin_Servo, 120500); // 120.5°
    digitalWrite(pin_LED, HIGH);

    // increase the buffer size to improve filtering
    // (default: 10, max: 255)
    filter_average.setBufferSize(50);
    filter_median.setBufferSize(5);

    // timer must be reset manually
    //timer.manualReset();
}

void loop()
{
    // communicate with HITIPanel
    // => to place at the beginning of the loop()
    HC_communicate();

    // read threshold value from HITIPanel
    float threshold = HC_analogDataRead(ad_ControlValue);

    // check if potentiometer value has reached threshold value
    bool reached = (analogRead(pin_Potentiometer) > threshold);

    // send boolean value to HITIPanel
    HC_digitalDataWrite(dd_BooleanWatcher, reached);

    // read temperature sensor raw values
    int rawTemp = analogRead(pin_TemperatureSensor);

    // convert to voltage V (using 5V power supply)
    float voltage = ((float)rawTemp / 1024) * 5.0;

    // convert to degrees °C
    // (TMP36 sensor => +/-10mV/°C, 750mV at 25°C)
    float celsius = (voltage - 0.5) * 100;

    // apply average + median filter on °C values
    float celsius_f = filter_average.average(filter_median.median(celsius));

    // send analog values to HITIPanel
    HC_analogDataWrite(ad_Temperature_voltage, voltage);
    HC_analogDataWrite(ad_Temperature_celsius, celsius);
    HC_analogDataWrite(ad_Temperature_celsius_f, celsius_f); 

    delayed_task_1();
    //delayed_task_2();
}

void delayed_task_1()
{
    // every 500ms, when timer ends
    if(timer.delay(500))
    {
        // toggle on-board LED state
        digitalWrite(pin_LED, led_state);
        led_state = ! led_state;
    }
}

/*
void delayed_task_1()
{
    // when timer starts
    if(timer.isStarting())
        digitalWrite(pin_LED, HIGH);

    // every 2s, when timer ends
    if(timer.delay(2000))
        digitalWrite(pin_LED, LOW);

    // when virtual switch is actuated from HITIPanel
    if(HC_digitalDataRead(dd_VirtualSwitch))
    {
        // deactivate switch
        HC_digitalDataWrite(dd_VirtualSwitch, LOW);

        // reset and restart timer
        timer.reset();
    }
}
*/

/*
void delayed_task_2()
{
    // when multitimer starts
    if(timers.isStarting())
        analogWrite(pin_BlueLED, 100);

    // after 500ms
    if(timers.delay(0, 500))
        analogWrite(pin_BlueLED, 30);

    // after 250ms
    if(timers.delay(1, 250))
        analogWrite(pin_BlueLED, 250);

    // after 1000ms
    if(timers.delay(2, 1000))
        analogWrite(pin_BlueLED, 0);

    // after 1500ms
    timers.delay(3, 1500);
        // do nothing
}
*/