Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

Download:

Datei 1: esp32_Puls_LCD.ino

 Arduino ESP32 Code: Create variable pulses with

20 pulses with multiple lengths of 150ns nanoseconds (minimum GPIO time at Arduino/ESP32)

 

Application:

As you can see here, an ESP32 is used to generate very fast pulses.

The control serves as a control signal for a MosFet circuit.

 

Over pins 12 to 34 on the upper side, the pulse length is extended from 150ns to 1-9 times length to about 1660ns, which corresponds to a frequency of 0.60 MHz or 600 kilohertz

 

 

The code was written in the Arduino IDE

 

 

 

ESP32 nodeMCU connection

On the developer board ESP32 nodeMCU

If on the left the 5 Volt Vss and GND swayvoltage sares are used for the I2C interface of the LCD.

On the right, the red block on GPIO-IN pins is chosen at 3.3 volts (far right)

 

 

LCD Display

A 16x2 LCD display is used as an indication, which is addressed via an I2C bus line (master slave)

 

I2C interface

On the back of the LCD displays, the interface is already pre-soldered

Here only the SCL, SDA, 5V VSS and GND must be pulled correctly to the ESP32 nodeMCU board

 

Sample code

Arduino

/*Variable Puls Output with LCD */

 

 

 

#include <LiquidCrystal_I2C.h>

 

//====< VARIABLES >====

//< Setup: LCD >

int lcdColumns = 16;

int lcdRows = 2;

//LCD Adress on 0x27

LiquidCrystal_I2C lcd(0x27lcdColumnslcdRows);  

//</ Setup: LCD >

 

//< GPIO >

int OUT_PIN = 15;

 

int IN1=12;

int IN2=14;

int IN3=27;

int IN4=26;

int IN5=25;

int IN6=33;

int IN7=32;

int IN8=35;

int IN9=34;

//</ GPIO >

 

int min_Pulswidth_ns=166;

 

String lcd_Text="";

int actInput=0;

int lastInput=-1;

//====</ VARIABLES >====

 

void setup(){

  //--------< setup() >--------

  //< GPIO >

  pinMode(OUT_PIN, OUTPUT);

 

  pinMode(IN1, INPUT); 

  pinMode(IN2, INPUT); 

  pinMode(IN3, INPUT); 

  pinMode(IN4, INPUT); 

  pinMode(IN5, INPUT); 

  pinMode(IN6, INPUT); 

  pinMode(IN7, INPUT); 

  pinMode(IN8, INPUT); 

  pinMode(IN9, INPUT); 

  //</ GPIO >

  

  // initialize LCD

  lcd.init();

  // turn on LCD backlight                      

  lcd.backlight();

  //--------</ setup() >--------

}



void loop(){

  //--------< Main Loop() >--------

  //--< Read IN >--

  long nHighCyles=0;

  int valIN =0;

  actInput=0;

  valIN=digitalRead(IN1);

  if(valIN>0){actInput=1;}

  valIN=digitalRead(IN2);

  if(valIN>0){actInput=2;}

  valIN=digitalRead(IN3);

  if(valIN>0){actInput=3;}

  valIN=digitalRead(IN4);

  if(valIN>0){actInput=4;}

  valIN=digitalRead(IN5);

  if(valIN>0){actInput=5;}

  valIN=digitalRead(IN6);

  if(valIN>0){actInput=6;}

  valIN=digitalRead(IN7);

  if(valIN>0){actInput=7;}

  valIN=digitalRead(IN8);

  if(valIN>0){actInput=8;}

  valIN=digitalRead(IN9);

  if(valIN>0){actInput=9;}

  //--</ Read IN >--

 

  nHighCyles=actInput+1;

 

  //---< Signal OUT >---

  //*Square Signal with n-times ON

  //*short Impuls 1-20 ON=> 100ns-2us

  //1 x GPIO-Updae-Cycle=166ns nanoseconds

 

  //----< @Loop: nPulses >----

  int nPulses =20;

  for (int iPulse=0;iPulse<=nPulses;iPulse++)

  {

    //--< @loop: HIGH-Cycles >--

    for(long iHIGH=0;iHIGH<nHighCyles;iHIGH++)

    {

      digitalWrite(OUT_PIN, HIGH);   //PULS_ON

    }

    //--</ @loop: HIGH-Cycles >--

    

    //--< @loop: LOW-Cycles >--

    for(long iHIGH=0;iHIGH<nHighCyles;iHIGH++)

    {

      //< OFF >

      digitalWrite(OUT_PIN, LOW);    // PULS_OFF

      //</ OFF >

    }

    //--</ @loop: LOW-Cycles >--

  }

  //----</ @Loop: nPulses >----

 

  //*Service-Works in long Off-time

  //*long time

  delayMicroseconds(100);              // wait for a second

  //--< OFF-Signal >--

  //---</ Signal OUT >---

  

 

  //< calculate >

  String lcd_Text0= "Pulswidth Frequency:";

  

  long nsPulswidth=0;

  nsPulswidth = nHighCyles * min_Pulswidth_ns;

 

  float frequency= float1000.0 / nsPulswidth );

 

  

  String lcd_Text1= String("") + String(nsPulswidth)  + " ns " + String(frequency) + " MHz" ;

  //</ calculate >

  

  //----< LCD Output >----

  if (actInput != lastInput)

  {

    //save lcd

    lastInput=actInput;

    

    //< display info on LCD >

    lcd.clear(); 

    int row0=0;

    int row1=1;

    int col0=0;

    int col1=0;

  

    

    lcd.setCursor(col0, row0);

    lcd.print(lcd_Text0);

    lcd.setCursor(col0,row1);

    lcd.print(lcd_Text1);

 

    //</ display info on LCD >

  }

  //----</ LCD Output >----

  //--------</ Main Loop() >--------

}

 

 

 

 

 

Mobile
»
ESP32 Code: Create an output pulse with adjustable pulse width via button and display on LCD and digits
»
8 Charater LED anzeigen an einer ESP32 mit TM1638 Led Buttons
»
ESP32 NodeMCU mit TM1838 Buttons
»
Arduino Code: Create variable pulses with ESP32 DevKit
»
Arduino: view float with 2 commas
»
Connect an LCD display on ESP32

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de