Introduction: Industrial ESP32 Controller for (0-10V) Voltage Measurement | Norvi-IIOT-AE02-V Device

About: ESP32 & STM32 based Industrial Controllers

Norvi devices are ESP32 embedded industrial controllers. These devices come with variety of features with different models which make them ideal for industrial automation and IoT solutions.

Check out our previous Instructables to know more about the Norvi devices.

Getting started with Norvi devices

Working With Built-in Display and Push Buttons of the Norvi Devices

In this instructable, we’ll be looking at the Norvi-IIOT-AE02-V model which is capable of measuring 0-10V industrial level voltages. Here, We show how to read analog inputs with this device by getting the read values using a potentiometer.

The features of Norvi-IIOT-AE02-V are,

  • 8 Digital Inputs 24V
  • 6 Analog inputs (0-10V)
  • 2 Transistor outputs, PWM compatible (36VDC max with 360mW collector power dissipation)
  • RS-485 Communication
  • WIFI & Bluetooth
  • Built-in OLED Display with 3 buttons
  • Expansion port with I2C, UART and GPIO

Check more about the model here - Norvi-IIOT-AE02-V

So what do you need to get started?

  • The Norvi IIOT-AE02-V Device
  • USB cable(Type A to Type B mini)
  • PC/Laptop
  • Potentiometer
  • Wires
  • Power supply(0-10V)

Step 1: Understanding More About the Display

  • The device has a built-in 0.96 OLED SSD1306 display of 128 x 64 resolution. Its address is 03xC. The GPIOs 16(SDA) and 17(SCL)of Esp32 in the device are used for I2C communication with this display.

Step 2: Understanding More About the Analog Inputs.

  • The device has two ADS1115 modules of addresses 0x48 & 0x49 respectively.
  • ADS1115 is a 16-bit analog to digital converter (ADC) that consists of four analog channels. Here in the device, the entire 4 channels of the first ADS1115 module and the first two channels of the next module are used as analog inputs to measure the input voltage. The same GPIOs, 16(SDA) and 17(SCL) of ESP32 in the device are used for I2C communication with the ADCs. Each ADC module is capable of measuring a maximum voltage of 4.0V. Considering this into account and to facilitate measurement of maximum 10V, the above arrangement is made inside the device using resistors, as shown in the figure.
  • Hence it is to be noted that the value read by the analog channels of the ADC is 2.5 times smaller than the actual analog input reading at the analog input pins A0-A5.

Step 3: GPIO Pins of Digital Inputs

  • GPIO pins detail of Digital Inputs are as follows,
I.0 = 18    I.1 = 39   I.2 = 34    I.3 = 35
I.4 = 19    I.5 = 21   I.6 = 22    I.7 = 23
  • Here the digital inputs are normally kept on/high (digital logic state "1") by using pull-up resistors inside the device.So when the connection is made the state changes to off/low(digital logic state "0").

To know more about how to work with the digital input side - Getting started with Norvi devices

Step 4: Analog Inputs and GPIO Pins of Transistor Outputs

  • There are 6 analog input pins starting from A0-A5 which are capable of measuring 0-10V industrial level voltages. The first four inputs (A0-A3) are connected to the four channels of the first ADS1115 module of address 0x48 and the final two inputs (A5 & A6) are connected to the first two channels of the second ADS1115 module.
  • The GPIO pins of the transistors are as follows,
T.0 = 26   T.1 = 27        PWM compatible (36VDC max with 360mW collector power dissipation)

Step 5: Programming the Device to Measure the Voltage and Displaying It on the OLED Screen

  • Install the Adafruit SSD1306, Adafruit GFX and Adafruit ADS1015 libraries in your Arduino IDE and upload the below sketch.

(For installing the ESP32 board and booting up the device, check the steps 1 and 2 of our previous instructable - Getting Started With Norvi Devices)

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_ADS1015.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)

Adafruit_ADS1115 ads1(0x48);
Adafruit_ADS1115 ads2(0x49);
float Voltage = 0.0;

void setup()
{
  Wire.begin(16, 17);
  Serial.begin(115200);
  ads1.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //starting the display
  display.display();
  delay(2000);
  display.clearDisplay();
}

void loop()
{
  float adc0;

  adc0 = ads1.readADC_SingleEnded(0);
  Voltage = (adc0 * 0.1875) / 1000;

  Serial.print("AIN0: ");
  Serial.print(adc0);
  Serial.print("\tVoltage: ");
  Serial.println(Voltage * 2.5, 3);
  delay(1000);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(15, 0);
  display.println("Voltage Value");
  display.setCursor(45, 15);
  display.println(Voltage * 2.5);
  display.display();
  delay(1000);
  display.clearDisplay();

}

Step 6: ​Understanding the Code

  • The necessary libraries are imported to use I2C (Wire library), to write the display (Adafruit_SSD1306 and Adafruit_GFX libraries) and to read the analog value by the ADCs. (Adafruit_ADS1015 library.)
#include <Wire.h>

#include <SPI.h>

#include <Adafruit_ADS1015.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>
  • Then, the width and height of our OLED display are defined.
#define SCREEN_WIDTH 128 

#define SCREEN_HEIGHT 64
  • Next, with I2C communication protocol (&Wire), a display object with the width and height defined earlier is initialized.
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
  • The below lines define the addresses of the ADCs.
Adafruit_ADS1115 ads1(0x48);

Adafruit_ADS1115 ads2(0x49);
  • A float variable is defined to store the voltage value.

float Voltage = 0.0;
  • Next, in setup(), we initialize the Serial Monitor at a baud rate of 115200.

Serial.begin(115200);
  • In the following line, you initialize I2C by setting the sda and scl GPIOs to communicate with the display.

Wire.begin(16,17);
  • Then the first ADS1115 module is initialized to begin its operation.

 ads1.begin();
  • Next, the display is initialized using its address.

display.begin(SSD1306_SWITCHCAPVCC,0x3C);
  • Using below lines, we can ensure whether our display is working correctly. Here the display check is done for 1s (1000ms) and this can be varied.

display.display();

delay(1000); 

display.clearDisplay();
  • Inside the loop() function, the float variable adc0 is initialized which is used to store the output of the analog channel of the first ADC module ads1.
float adc0;
  • The below function reads the first analog channel value of the first ADC module ads1 and stores this value in the “adc0” float variable.

adc0 = ads1.readADC_SingleEnded(0);
  • This statement converts ADC value into voltage where 0.1875mV is the resolution of ADS1115.

Voltage = (adc0 * 0.1875)/1000);
  • The below lines prints the value of ADC and voltage on the serial monitor with a delay of one second after every reading.
Serial.print("AIN0: "); 

Serial.print(adc0);

Serial.print("\tVoltage: ");

Serial.println(Voltage*2.5, 3); //the actual analog input reading is 2.5 times the value read by the ADC.

delay(1000);
  • The text size, text color and text position are defined and the voltage value read is displayed on the OLED screen.
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(15, 0);
display.println("Voltage Value");
display.setCursor(45, 15);
display.println(Voltage * 2.5);
display.display();
delay(1000);
display.clearDisplay();

Step 7: Making the Circuit Connection and Verifying the Code.

  • Complete the circuit as shown in the diagram to get the read values by varying the potentiometer value.

**Norvi-IIOT-AE02-V is capable of reading 0-10V industrial level voltages.

  • Once you upload the sketch and boot up the device you can see that the device is displaying “Voltage Value” with the analog value read at the input A0. As per the code, by using the serial monitor in Arduino IDE, this voltage value can be confirmed again.

To check more about the Norvi line up - www.norvi.lk