Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
LanmiLab
Published

Nano Screen

Nice fitting on top without wiring.

BeginnerFull instructions provided1 hour983

Things used in this project

Hardware components

ARDUINO NANO R3 WITHOUT HEADERS
×1
0.91 inch OLED I2C Display
×1
Stackable Header Kit
×1
Rotary Encoder with Push-Button
Rotary Encoder with Push-Button
×1
Resistor 10Kohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Nano Screen Kicad Design

Schematics

Nano Screen Kicad Design

Nano Screen Schematic

Code

Demo Code

C/C++
// LanmiLab 2020, https://github.com/lanmilab/misc/tree/master/Nano_Screen
// https://twitter.com/lanmiLab

#include <Arduino.h>
#include <U8g2lib.h>
#include <string.h>

int encoderA = 3;
int encoderB = 2;
int encoderButtonPin = 8;
int encoderState = 0;
int encoderALast = LOW;
int pinState = LOW;
int buttonState = HIGH;
int buttonStateLast = HIGH;

U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0); 

 void setup(void) {
    pinMode (encoderA, INPUT);
    pinMode (encoderB, INPUT);
    u8g2.begin();
    u8g2.setFont(u8g2_font_logisoso22_tr);  // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
    String out = "Level:" + String(encoderState);
    u8g2.clearBuffer();
    u8g2.drawStr(0,30,out.c_str());  
    u8g2.sendBuffer();
}

  void loop(void) {
    pinState = digitalRead(encoderA);
    if ((encoderALast == LOW) && (pinState == HIGH)) {
      if (digitalRead(encoderB) == LOW) {
          encoderState--;
      } else {
          encoderState++;
      }
      String out = "Level:" + String(encoderState);
      u8g2.clearBuffer();
      u8g2.drawStr(0,30,out.c_str());
      u8g2.sendBuffer();
    }
    encoderALast = pinState;
    
    buttonState = digitalRead(encoderButtonPin);
    if (buttonState == LOW && buttonStateLast == HIGH ) {
      // button press, do something
      encoderState = 0;
    }
    
    delay(4);
}

U8g2

Credits

LanmiLab
5 projects • 5 followers
Engineer, Researcher, Maker, Embedded Systems Consultant. If you require any help with your project or idea, feel free to contact me.

Comments