Output Devices

Week 12

Introduction

In this output week, we configure and program our board to work with an input and output device. Building over our progress from the past week.

128x64 LCD Screen

Liquid crystal display screen comes in varying dimensions and sizes. It makes up as part of many electronics we come across and use on a daily basis. It is the screen used in most 3D printers, etc. In this week, our output device is the 128x64 LCD screen which would display the distance data obtained with flight sensor from previous week. It is important to refer to the device's datasheet.

Output Device Wiring

To wire the output device with the microcontroller, it is important to refer to both microcontroller's and output device datasheet. The microcontroller pinout and LCD screen pin description table can be found below.


U8glib - Library

The library used for programming the output device was obtained from u8glib.

Output Device Programming

The programming included the u8glib library and the code was built on on last week's progress. The code is as follows:


#include <U8glib.h> //include u8glib library

U8GLIB_ST7920_128X64 u8g(13, 11, 12, U8G_PIN_NONE); //initialize pins 13,11,12 of ATMEGA328p

byte PWM_PIN = 6; //initialize flight sensor pwm pin with pwm pin 6 of ATMEGA328p
int pwm_value;

char pwmValue_test[6]; //character array for flight sensor input

void draw(void) {
  u8g.setFont(u8g_font_unifont); //configure font
  u8g.drawStr( 32, 24, "distance"); // write the following at position 32x24

  memset(pwmValue_test,'\0',5); // overwrite the previous value of pwmValue_test
  dtostrf(pwm_value,5,0,pwmValue_test); //convert ASCII to character array
  u8g.drawStr(22+1, 42, pwmValue_test); //write flight sensor data at position 23x43
  u8g.drawStr(72+1, 42, "mm"); //write mm at 73x42
}

void setup() {
  if( u8g.getMode() == U8G_MODE_R3G3B2 )
  u8g.setColorIndex(255);
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
  u8g.setColorIndex(3);
  else if ( u8g.getMode() == U8G_MODE_BW )
  u8g.setColorIndex(1);
  
  pinMode(PWM_PIN, INPUT);
  Serial.begin(115200);
}
 
void loop() {
   u8g.firstPage();
  do {
    draw();
  } while( u8g.nextPage() );
  delay(500);
  
  pwm_value = pulseIn(PWM_PIN, HIGH);
  pwm_value = (pwm_value)/10;
  Serial.println(pwm_value);
}        

The code reads sensor data and displays them on the LCD screen


128x64 LCD Screen - Issues

This week I had issues wit my 128x64 LCD screen, as it was a generic non-branded model I had issues turning on the LED backlight of the screen. It was solved by reversing the backlight pins.

Assignment Files:

128x64 LCD Screen Datasheet