Schlagwort-Archive: HD44780

BitBastelei #368 – ESP LCD-Adapter

BitBastelei #368 - ESP LCD-Adapter

(391 MB) 00:11:11

2020-01-19 11:00 🛈

Vor einiger Zeit hatte ich gezeigt wie man ein HD44780-Display mit Arduino an einen ESP8266 anbinden kann. Diese Konstruktion nutze ich noch immer um einen schnellen Überblick zu bekommen. Leider war die Verkabelung etwas wacklig, sodass ich immer wieder nachstecken und neu starten musste. Da noch etwas Platz in einem Paket war soll es nun dank KiCAD eine separate Platine richten. Kleine Arbeit, großer Stabilitätsgewinn.

BitBastelei #305 – EC-Karten-Terminal-Recycling: LCD&Keypad an ESP8266

BitBastelei #305 - EC-Karten-Terminal-Recycling: LCD&Keypad an ESP8266

(318 MB) 00:30:29

2018-10-21 10:00 🛈
Vor einiger Zeit hatte ich ein altes EC-Kartenterminal zerlegt und schon angemerkt, dass man viele der Bauteile recyclen kann. Dieses mal geht es um das Display sowie die Tastatur – eigentlich eine einfache Aufgabe. Eigentlich.

Links

Quellcode Testsoftware

#include <Arduino.h>
#include <SPI.h>
#include <MCP23S17.h>
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>

extern "C" {
    #include "user_interface.h"
}

const char* kbdmap = "K##.0CRE321MSO654FTe987U";
const char* cmdmap = " +-*/";

#define ROWS 4
#define COLS 6

LiquidCrystal_PCF8574 lcd(0x27);
MCP gpio(0, 15);
int8_t last = 0;

String num1, num2;
byte cmd = 0;

void setPinMode(void) {
    uint16_t out = 0xFFFF;
    out <<= (ROWS);
    gpio.pinMode(out);
    gpio.pullupMode(out);
    gpio.inputInvert(out);
    out = ~out;
    gpio.digitalWrite(out);
}

void startLCD(void) {
    int error;
    Serial.println("LCD...");
    Wire.begin(D1, D2);
    Wire.beginTransmission(0x27);
    error = Wire.endTransmission();
    Serial.print("Return: ");
    Serial.print(error);

    if (error == 0) {
        Serial.println(": LCD found.");
    } else {
        Serial.println(": LCD not found.");
    }

    lcd.begin(20, 2); // initialize the lcd
    lcd.home();
    lcd.clear();
    lcd.print("BitBa // POS-Matrix");
}

void setup() {
    Serial.begin(115200);
    Serial.print("\nInit...");
    gpio.begin();

    setPinMode();

    Serial.println("OK");

    startLCD();
}

int8_t checkKeys(void) {
    byte row, col;
    int input;
    for(row = 0; row < ROWS; row++) {
        gpio.digitalWrite(row, LOW);
        delay(1);
        input = gpio.digitalRead();
        gpio.digitalWrite(row, HIGH);
        for(col=0; col < COLS; col++) {
            if(input & (1<<(ROWS + col))) {
                return (byte)(COLS * row + col);
            }
        }
    }
    return -1;
}

void loop() {
    int8_t input = checkKeys(); 
    int8_t check = 0xFF;
    float result = num2.toFloat();
    bool change = false;
    if(result == 0) result = num1.toFloat();

    if(input < (COLS*ROWS) && input >= 0 && last != input) {
        Serial.print(input);
        Serial.print(": ");
        last = input;
        if(input >= 0) {
            check = kbdmap[input];
            Serial.print(check);
        }else{
            check = 0xFF;
        }
        Serial.println();
        delay(15); //Poor maker debounce
    }else{
        check = 0xFF;
    }

    if(check != 0xFF) {
        switch(check) {
            //K##.0CRE321MSO654FTe987U
            case 'K':
                cmd = 4;
                change = true;
                break;
            case 'R':
                cmd = 3;
                change = true;
                break;
            case 'S':
                cmd = 2;
                change = true;
                break;
            case 'T':
                cmd = 1;
                change = true;
                break;
            case 'C':
                cmd = 0;
                num1 = "";
                num2 = "";
                change = true;
                break;
            case 'U':
                cmd = 0;
                num2 = "";
                change = true;
                break;
            case 'F':
                if(cmd == 0) {
                    if(num1.length() > 0) num1.remove(num1.length()-1);
                }else{
                    if(num2.length() > 0) num2.remove(num2.length()-1);
                }
                change = true;
                break;
            case '#':
                switch(cmd) {
                    case 1:
                        result = num1.toFloat() + num2.toFloat();
                        break;
                    case 2:
                        result = num1.toFloat() - num2.toFloat();
                        break;
                    case 3:
                        result = num1.toFloat() * num2.toFloat();
                        break;
                    case 4:
                        result = num1.toFloat() / num2.toFloat();
                        break;
                }
                cmd = 0;
                num1 = result;
                num2 = "";
                change = true;
                break;
            case '.':
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                if(cmd == 0) {
                    num1 += (char)check;
                }else{
                    num2 += (char)check;
                }
                change = true;
        }

        if(change) {
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print(num1);
            if(cmd > 0) {
                lcd.setCursor(18, 0);
                lcd.print(" ");
                lcd.print(cmdmap[cmd]);
                lcd.setCursor(0, 1);
                lcd.print(num2);
            }
        }
    }
}

 

 

Hinweis: Der bei 19:40 gezeigter GPIO-Expander wurde mir seinerzeit von ICStation.com zur Verfügung gestellt.