Arduino Nano SPWM generator w/ LCD 16×2

Connecting the Arduino Nano SPWM generator to the LCD requires an additional connection on the PCB to the LCD. This additional connection is two wires for I2C communication and two more wires for the power source

Added connection for Arduino Nano SPWM generator PCB

added connection

I forgot to add an RC filter to reduce the noise on the voltage feedback, and also a voltage divider resistor for the NTC.

Here I add the circuit is the circuit in the green box. There are several additional components as shown above. To reduce noise I added an RC filter for Voltage feedback, and also added a voltage divider resistor for the NTC.

Add a little circuit like in the picture above, on the PCB. It is an RC filter circuit to reduce noise and another is a voltage divider resistor for the NTC sensor. Apart from that, I also installed a SIP header on the PCB to connect to the LCD.

The picture above is a picture of an LCD with an I2C circuit. The LCD circuit and the I2c circuit are basically two separate circuits, some sell them as one part but some sell them separately. Connect the pins on this I2c PCB to the pins on the Arduino as in the circuit above.

Added code for LCD function

Addition of header files for LCD and I2c, then make sure the I2C address matches the installed I2C hardware. Notice the Pad says A0 A1 A2 on the I2C PCB, if all are open then the address is 0x27.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

In the void setup section add the following code as a welcome screen while waiting for the soft start to finish

  lcd.init();              // initialize the lcd
  lcd.backlight();         // baclight ON
  lcd.setCursor(3, 0);
  lcd.print("Yopie DIY");  // Welcome screen
  lcd.setCursor(0, 1);
  lcd.print("Arduino SPWM Gen");

and after the soft-start add the following code to remove the welcome display and replace it with measurement type

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Batt--Vout--Temp");

In the void alarmIndication as follows

  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("WARNING!");
  lcd.setCursor(0, 1);
  if (alarm == 2) lcd.print(" UNDER VOLTAGE");
  if (alarm == 3) lcd.print("  OVER VOLTAGE");
  if (alarm == 4) lcd.print("OVER TEMPERATURE");
  if (alarm == 5) lcd.print("  LOW BATTERY");

When an alarm occurs, the buzzer still sounds according to the type of alarm and the type of alarm also appears on the LCD.

Last, on void feedBackTest add three float variables to store the calculation whose result will be displayed. This variable is specifically only to display the measurement results that are understood by the operator, the original value is in integer ADC reading results. For example, for battery readings, the floating value of 12.0V will be easier to understand than integer 522.

  float dis1;
  float dis2;
  float dis3;

The values ​​for dis1, dis2 and dis3 are the product of the ADC readings with a constant. And the result is a number as we usually read.

As an example of battery voltage:

with a 2k7 and 10k voltage divider resistor, the input BATT voltage is 2.55V

BATT = 12.0V * 2k7/(2k7+10k)

then the ADC changes it to 522

battIn = 2.55V/5V * 1023

So in order for this 522 value to return to 12.0V, multiply it by the constant 0.02299 which is the opposite result of the calculation above.

And the following code to display the measurement results. Every 50 times the testFeedback function is executed once the display is updated, with the intention that the display does not flicker.

  if (dispCnt >= 50) {        // display updated every 50 cycle to avoid flickering
    dis1 = battIn * 0.02299;  // constant is the result of reversing the above calculation
    dis2 = vfbIn * 0.3568;
    dis3 = ((tfbIn - 512) / 11.0) + 25.0;
    lcd.setCursor(0, 1);
    lcd.print(String(dis1, 1) + "  " + String(dis2, 0) + "   " + String(dis3, 1));
    dispCnt = 0;
  }
  dispCnt++;

That’s all I can write in the post about adding a 16 x 2 LCD. Hopefully, this is useful, see you next time…

The Code you need is here

View Post related to this post