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: wiring_shift_mod.cpp
Datei 2: wiring_shift_mod.h
Datei 3: esp32_Buttons_TM1638.ino

ESP32 NodeMCU mit 8 LED & KEY

 

Description:

With this application you can operate a button input board on an ESP32 nodeMCU.

With the code example, the input board is operated in such a way that when pressing a button the appropriate LED lights up

 

Example application:

Operating a button board / module on an ESP32 nodeMCU board

 

Components:

Board: ESP32 nodeMCU DevBoard/DevKit

LED and Key: LED & KEY TM1638 Module

Arduino IDE, Arduino

 

 

https://amzn.to/2wOkFBK    8-Bit LED + 8-Bit Digital Pipe +8- Bit Key TM1638 Module + Cable (5.72 Euro)

 

 

According to the instructions of the TM1638 and ESP32 nodeMCU

Connection PINS ESP32 -> TM1638

G4->STB

G16->CLK

G17->DIO

GND->GND

3V3->VSS

 

 

 

Arduino IDE Code

Simply enter this code into the Arduion IDE, compile the code and paste it to the ESP32 nodeMCU

 

#include "wiring_shift_mod.h"

 

#define CLOCK_TYPE CLOCK_INVERT

#define CLOCK_DELAY_US 1

 

const int strobe_pin =  4;

const int clock_pin  = 16;

const int data_pin   = 17;

 

void setup()

{

  pinMode(strobe_pin, OUTPUT);

  pinMode(clock_pin, OUTPUT);

  pinMode(data_pin, OUTPUT);

 

  sendCommand(0x8f);  // activate

  reset();

}

 

void loop()

{

  uint8_t buttons = readButtons();

 

  for(uint8_t position = 0; position < 8; position++)

  {

    uint8_t mask = 0x1 << position;

 

    setLed(buttons & mask ? 1 : 0, position);

  }

}

 

void sendCommand(uint8_t value)

{

  digitalWrite(strobe_pin, LOW);

  shiftOutMod(data_pin, clock_pin, LSBFIRST, CLOCK_TYPE, CLOCK_DELAY_US, value);

  digitalWrite(strobe_pin, HIGH);

}

 

void reset()

{

  sendCommand(0x40); // set auto increment mode

  digitalWrite(strobe_pin, LOW);

  shiftOutMod(data_pin, clock_pin, LSBFIRST, CLOCK_TYPE, CLOCK_DELAY_US, 0xc0);   // set starting address to 0

  for(uint8_t i = 0; i < 16; i++)

  {

    shiftOutMod(data_pin, clock_pin, LSBFIRST, CLOCK_TYPE, CLOCK_DELAY_US, 0x00);

  }

  digitalWrite(strobe_pin, HIGH);

}

 

uint8_t readButtons(void)

{

  uint8_t buttons = 0;

  digitalWrite(strobe_pin, LOW);

  shiftOutMod(data_pin, clock_pin, LSBFIRST, CLOCK_TYPE, CLOCK_DELAY_US, 0x42);

 

  pinMode(data_pin, INPUT);

 

  for (uint8_t i = 0; i < 4; i++)

  {

    uint8_t v = shiftInMod(data_pin, clock_pin, LSBFIRST, CLOCK_TYPE, CLOCK_DELAY_US) << i;

    buttons |= v;

  }

 

  pinMode(data_pin, OUTPUT);

  digitalWrite(strobe_pin, HIGH);

  return buttons;

}

 

void setLed(uint8_t valueuint8_t position)

{

  pinMode(data_pin, OUTPUT);

 

  sendCommand(0x44);

  digitalWrite(strobe_pin, LOW);

  shiftOutMod(data_pin, clock_pin, LSBFIRST, CLOCK_TYPE, CLOCK_DELAY_US, 0xC1 + (position << 1));

  shiftOutMod(data_pin, clock_pin, LSBFIRST, CLOCK_TYPE, CLOCK_DELAY_US, value);

  digitalWrite(strobe_pin, HIGH);

}

 

 

 

Link to GitHub MartyMacGyver

TM1638-demos-and-examples

https://github.com/MartyMacGyver/TM1638-demos-and-examples/blob/master/arduino/TM1638_buttons/TM1638_buttons.ino

 

Arduino IDE

 

 

Expanding the Arduino Library

 

In order for the line to be

#include "wiring_shift_mod.h"

You have to expand the Arduino Libraries. for this you can go to Arduino IDE program ->Menu->File->Preferences

And opens the path to Sketchbook location

 

Expand Arduino Library

 

The library files are attached

Wiring_shift_mod.cpp and wiring_shift_mod.h

In the directory %Documents%"Arduino-libraries

 

Bezugsquellen:

 

https://amzn.to/3cfCZCA       3 Stück von AZDelivery 3 x ESP32 NodeMCU Module WLAN WiFi Development Board mit CP2102 (Nachfolgermodell zum ESP8266)  24,99 Euro

https://amzn.to/2wGkyYR     1x Stück: AZDelivery ESP32 NodeMCU Module WLAN WiFi Development Board mit CP2102 für 9,79 Euro

https://amzn.to/2KaC1eQ     AZDelivery HD44780 2004 LCD Display grün Bundle 4x20 Zeichen mit I2C Schnittstelle für Arduino

https://amzn.to/2wKzzJc       AZDelivery HD44780 2004 LCD Display Bundle 4x20 Zeichen mit I2C Schnittstelle für Arduino

 

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