Preparing your Arduino Sketch

1:24

 

1) Writing the code

Communicating with HITIPanel

It only requires adding 3 lines of code to establish communication between your Arduino and HITIPanel. Thanks to these 3 lines, HITIPanel automatically discusses with HITIComm and retrieves data in the background.

Naming convention : all HITIComm functions and variables starts with HC_.

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


// run once at power on
void setup()
{
    // 2) initialize library (default baudrate: 250000)
    // => use HC_begin(baudrate) to specify a different baudrate
    HC_begin(); 
}


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

Controlling digital input and output

Let’s complete the above code to:

  • monitor a digital input (a switch on pin 3)
  • control a digital output (the on-board LED on pin 13)

In the Arduino IDE, open this example: File\Examples\HITIComm\1_Basics\1_DigitalInputOutput.

menu-examples-hiti-comm-basics-digital-input-output.png

Example : 1_Basics \ 1_DigitalInputOutput

In this example, a few lines are added to configure the pins with the standard pinMode() function, and to switch on the on-board LED at start using the standard digitalWrite() function.

#include <HITIComm.h>


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


// run once at power on
void setup()
{
    // initialize library
    HC_begin(); 

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

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


// run repeatedly after Setup()
void loop()
{
    // communicate with HITIPanel
    HC_communicate(); 
}

 

2) Uploading the code

  1. In the Arduino IDE, select your board (menu Tools\Boards).

    menu-tools-selection-board-arduino-uno.png

  2. Select the correct COM port (menu Tools\Port).

    menu-tools-select-com-port.png

  3. Finally, click on Upload to compile and upload the program to your Arduino.

    upload-program-to-arduino.png

 

3) Performing the electrical wiring

Connect a switch on pin 3 with a pull-down resistance.

connect-switch-pin-3-arduino-uno.png

 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.