top of page

AIRHMI - ARDUINO - ESP32 LIBRARY

Updated: Jan 5



AIRHMI - ARDUINO- ESP32 LIBRARY



You can use Airhmi Displays comfortably with Arduino and ESP32 ... etc. boards.




CONNECTION TYPE





According to the circuit diagram, the purpose of the circuit is to display the value measured with the potentiometer on the ProgressBar on the screen and to turn on and off the led on the breadboard from a button on the screen.


Using the ADC pins of the ESP32, the value read from the potentiometer is sent to the screen and displayed with the progressbar. In order to prevent it from sending data continuously, it sends in case of a certain rate of change.


At the same time, the led installed on the breadboard is managed with the buttons on the screen and it is turned on and off.


On the screen side, we create the objects we will use on the screen using AirHMI Visual Creator and adjust their positions. We do not write any code inside the objects. Our screen is designed to recognize objects when it is initialized by Arduino - Esp32.


On the Arduino -Esp32 side, the objects we define on the screen are included in our code with the names of the objects we use on the screen. After that we can control the objects completely on the Arduino side.



#include <Airhmi.h>

//We define the objects on our screen
AirButton b0 = AirButton("EButton1");
AirButton b1 = AirButton("EButton2");
AirProgressBar p0 = AirProgressBar("ProgressBar1");

//from here on we will not need the name of the object defined on the screen, we will use the name we defined directly in Arduino

//Defining Led and Adc pins
const int ledPin = 5;
const int adcPin = 34;

//variable to hold adc
int adc_val;

//what to do in case EButton1, which we defined on the screen, is touched.
void b0PushCallback(void *ptr)
{
      digitalWrite(ledPin, HIGH);
}

//what to do if the EButton2 we defined on the screen is touched.
void b1PushCallback(void *ptr)
{
      digitalWrite(ledPin, LOW);
}   

//List of objects that we will listen to update on the AirHMI side
AirTouch *air_listen_list[] = {
  &b0,
  &b1,
  NULL
};

void setup()
{
  Serial.begin(115200);
  airInit(); //init our screen
  pinMode(ledPin, OUTPUT);

// Add a listener to the push event of the button
  b0.attachPush(b0PushCallback, &b0);
  b1.attachPush(b1PushCallback, &b1);
}

void loop()
{
   airLoop(air_listen_list);

  //read the value from the adc pin
  int adc = analogRead(adcPin);

  // the new value is 100 lower than the last saved value or we update the progress bar on the screen
  if(adc > (adc_val + 100) || adc < (adc_val - 100))
  {
    int yuzde = (adc / 4095.0) * 100.0;
    p0.Set_Value(yuzde);
    adc_val = adc;
  }

}

On the screen side we just create the objects and their locations and set the Baudrate value of the project in the Tools/Options option as shown in the bottom image.





NOTE: Your AirHMI Display Firmware version must be v3.14 and above.

. If you have a lower version, you can contact us via whatsapp for update.


Download the AirHMI and Arduino projects below.


Pot Read & Led OnOff
.zip
Download ZIP • 406KB





52 views0 comments

Recent Posts

See All
bottom of page