Commit 6fdc4d77 authored by alaskalinuxuser's avatar alaskalinuxuser
Browse files

Sketch for screen and lte shield together, with battery indication.

parent 5d8ff1f0
This diff is collapsed.
......@@ -31,7 +31,9 @@ Last modification: 04/02/2019
// Create display and set pins:
U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // (CLK=13, DIN=11, CE=10, DC=9, RST=8)
// U8GLIB_PCD8544 u8g(3, 4, 13, 5, 12); // (CLK=13, DIN=11, CE=10, DC=9, RST=8)
// Alternate wiring:
U8GLIB_PCD8544 u8g(3, 4, 13, 5, 12); // (CLK=3, DIN=4, CE=13, DC=5, RST=12)
int Variable1; // Create a variable to have something dynamic to show on the display
int fadeAmount = 1; // how many points to change by
......
language: c
branches:
only:
- master
sudo: false
dist: trusty
env:
- ARDUINO_VERSION=1.8.5
before_install:
- curl -sSL http://downloads.arduino.cc/arduino-${ARDUINO_VERSION}-linux64.tar.xz | tar Jxf -
- sudo mv arduino-${ARDUINO_VERSION} /usr/local/share/arduino
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
install:
- ln -s $PWD /usr/local/share/arduino/libraries/PCD8544
script:
- arduino --verify --board arduino:avr:uno $PWD/examples/HelloWorld/HelloWorld.ino
- arduino --verify --board arduino:avr:uno $PWD/examples/Thermometer/Thermometer.ino
The MIT License (MIT)
Copyright (c) 2013 Carlos Rodrigues <cefrodrigues@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
/*
* PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs.
*
* Copyright (c) 2010 Carlos Rodrigues <cefrodrigues@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "PCD8544.h"
#include <Arduino.h>
#if defined (__XTENSA__)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
#define PCD8544_CMD LOW
#define PCD8544_DATA HIGH
/*
* If this was a ".h", it would get added to sketches when using
* the "Sketch -> Import Library..." menu on the Arduino IDE...
*/
#include "charset.cpp"
PCD8544::PCD8544(uint8_t sclk, uint8_t sdin, uint8_t dc, uint8_t reset, uint8_t sce):
pin_sclk(sclk),
pin_sdin(sdin),
pin_dc(dc),
pin_reset(reset),
pin_sce(sce)
{}
void PCD8544::begin(uint8_t width, uint8_t height, uint8_t model)
{
this->width = width;
this->height = height;
// Only two chip variants are currently known/supported...
this->model = (model == CHIP_ST7576) ? CHIP_ST7576 : CHIP_PCD8544;
this->column = 0;
this->line = 0;
// Sanitize the custom glyphs...
memset(this->custom, 0, sizeof(this->custom));
// All pins are outputs (these displays cannot be read)...
pinMode(this->pin_sclk, OUTPUT);
pinMode(this->pin_sdin, OUTPUT);
pinMode(this->pin_dc, OUTPUT);
pinMode(this->pin_reset, OUTPUT);
pinMode(this->pin_sce, OUTPUT);
// Reset the controller state...
digitalWrite(this->pin_reset, HIGH);
digitalWrite(this->pin_sce, HIGH);
digitalWrite(this->pin_reset, LOW);
delay(100);
digitalWrite(this->pin_reset, HIGH);
// Set the LCD parameters...
this->send(PCD8544_CMD, 0x21); // extended instruction set control (H=1)
this->send(PCD8544_CMD, 0x13); // bias system (1:48)
if (this->model == CHIP_ST7576) {
this->send(PCD8544_CMD, 0xe0); // higher Vop, too faint at default
this->send(PCD8544_CMD, 0x05); // partial display mode
} else {
this->send(PCD8544_CMD, 0xc2); // default Vop (3.06 + 66 * 0.06 = 7V)
}
this->send(PCD8544_CMD, 0x20); // extended instruction set control (H=0)
this->send(PCD8544_CMD, 0x09); // all display segments on
// Clear RAM contents...
this->clear();
// Activate LCD...
this->send(PCD8544_CMD, 0x08); // display blank
this->send(PCD8544_CMD, 0x0c); // normal mode (0x0d = inverse mode)
delay(100);
// Place the cursor at the origin...
this->send(PCD8544_CMD, 0x80);
this->send(PCD8544_CMD, 0x40);
}
void PCD8544::stop()
{
this->clear();
this->setPower(false);
}
void PCD8544::clear()
{
this->setCursor(0, 0);
for (uint16_t i = 0; i < this->width * (this->height/8); i++) {
this->send(PCD8544_DATA, 0x00);
}
this->setCursor(0, 0);
}
void PCD8544::clearLine()
{
this->setCursor(0, this->line);
for (uint8_t i = 0; i < this->width; i++) {
this->send(PCD8544_DATA, 0x00);
}
this->setCursor(0, this->line);
}
void PCD8544::setPower(bool on)
{
this->send(PCD8544_CMD, on ? 0x20 : 0x24);
}
inline void PCD8544::display()
{
this->setPower(true);
}
inline void PCD8544::noDisplay()
{
this->setPower(false);
}
void PCD8544::setInverse(bool enabled)
{
this->send(PCD8544_CMD, enabled ? 0x0d : 0x0c);
}
void PCD8544::setInverseOutput(bool enabled)
{
this->inverse_output = enabled;
}
void PCD8544::setContrast(uint8_t level)
{
// The PCD8544 datasheet specifies a maximum Vop of 8.5V for safe
// operation in low temperatures, which limits the contrast level.
if (this->model == CHIP_PCD8544 && level > 90) {
level = 90; // Vop = 3.06 + 90 * 0.06 = 8.46V
}
// The ST7576 datasheet specifies a minimum Vop of 4V.
if (this->model == CHIP_ST7576 && level < 36) {
level = 36; // Vop = 2.94 + 36 * 0.03 = 4.02V
}
this->send(PCD8544_CMD, 0x21); // extended instruction set control (H=1)
this->send(PCD8544_CMD, 0x80 | (level & 0x7f));
this->send(PCD8544_CMD, 0x20); // extended instruction set control (H=0)
}
void PCD8544::home()
{
this->setCursor(0, this->line);
}
void PCD8544::setCursor(uint8_t column, uint8_t line)
{
this->column = (column % this->width);
this->line = (line % (this->height/9 + 1));
this->send(PCD8544_CMD, 0x80 | this->column);
this->send(PCD8544_CMD, 0x40 | this->line);
}
void PCD8544::createChar(uint8_t chr, const uint8_t *glyph)
{
// ASCII 0-31 only...
if (chr >= ' ') {
return;
}
this->custom[chr] = glyph;
}
size_t PCD8544::write(uint8_t chr)
{
// ASCII 7-bit only...
if (chr >= 0x80) {
return 0;
}
const uint8_t *glyph;
uint8_t pgm_buffer[5];
if (chr >= ' ') {
// Regular ASCII characters are kept in flash to save RAM...
memcpy_P(pgm_buffer, &charset[chr - ' '], sizeof(pgm_buffer));
glyph = pgm_buffer;
} else {
// Custom glyphs, on the other hand, are stored in RAM...
if (this->custom[chr]) {
glyph = this->custom[chr];
} else {
// Default to a space character if unset...
memcpy_P(pgm_buffer, &charset[0], sizeof(pgm_buffer));
glyph = pgm_buffer;
}
}
// Output one column at a time...
for (uint8_t i = 0; i < 5; i++) {
this->send(PCD8544_DATA, this->inverse_output ? ~glyph[i] : glyph[i]);
}
// One column between characters...
this->send(PCD8544_DATA, this->inverse_output ? 0xff : 0x00);
// Update the cursor position...
this->column = (this->column + 6) % this->width;
if (this->column == 0) {
this->line = (this->line + 1) % (this->height/9 + 1);
}
return 1;
}
void PCD8544::drawBitmap(const uint8_t *data, uint8_t columns, uint8_t lines)
{
uint8_t scolumn = this->column;
uint8_t sline = this->line;
// The bitmap will be clipped at the right/bottom edge of the display...
uint8_t mx = (scolumn + columns > this->width) ? (this->width - scolumn) : columns;
uint8_t my = (sline + lines > this->height/8) ? (this->height/8 - sline) : lines;
for (uint8_t y = 0; y < my; y++) {
this->setCursor(scolumn, sline + y);
for (uint8_t x = 0; x < mx; x++) {
this->send(PCD8544_DATA, data[y * columns + x]);
}
}
// Leave the cursor in a consistent position...
this->setCursor(scolumn + columns, sline);
}
void PCD8544::drawColumn(uint8_t lines, uint8_t value)
{
uint8_t scolumn = this->column;
uint8_t sline = this->line;
// Keep "value" within range...
if (value > lines*8) {
value = lines*8;
}
// Find the line where "value" resides...
uint8_t mark = (lines*8 - 1 - value)/8;
// Clear the lines above the mark...
for (uint8_t line = 0; line < mark; line++) {
this->setCursor(scolumn, sline + line);
this->send(PCD8544_DATA, 0x00);
}
// Compute the byte to draw at the "mark" line...
uint8_t b = 0xff;
for (uint8_t i = 0; i < lines*8 - mark*8 - value; i++) {
b <<= 1;
}
this->setCursor(scolumn, sline + mark);
this->send(PCD8544_DATA, b);
// Fill the lines below the mark...
for (uint8_t line = mark + 1; line < lines; line++) {
this->setCursor(scolumn, sline + line);
this->send(PCD8544_DATA, 0xff);
}
// Leave the cursor in a consistent position...
this->setCursor(scolumn + 1, sline);
}
void PCD8544::send(uint8_t type, uint8_t data)
{
digitalWrite(this->pin_dc, type);
digitalWrite(this->pin_sce, LOW);
shiftOut(this->pin_sdin, this->pin_sclk, MSBFIRST, data);
digitalWrite(this->pin_sce, HIGH);
}
/* vim: set expandtab ts=4 sw=4: */
/*
* PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs.
*
* Copyright (c) 2010 Carlos Rodrigues <cefrodrigues@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef PCD8544_H
#define PCD8544_H
#include <Arduino.h>
// Chip variants supported (ST7576 is experimental)...
#define CHIP_PCD8544 0
#define CHIP_ST7576 1
class PCD8544: public Print {
public:
// All the pins can be changed from the default values...
PCD8544(uint8_t sclk = 3, /* clock (display pin 2) */
uint8_t sdin = 4, /* data-in (display pin 3) */
uint8_t dc = 5, /* data select (display pin 4) */
uint8_t reset = 12, /* reset (display pin 8) */
uint8_t sce = 13); /* enable (display pin 5) */
// Display initialization (dimensions in pixels)...
void begin(uint8_t width=84, uint8_t height=48, uint8_t model=CHIP_PCD8544);
void stop();
// Erase everything on the display...
void clear();
void clearLine(); // ...or just the current line
// Control the display's power state...
void setPower(bool on);
// For compatibility with the LiquidCrystal library...
void display();
void noDisplay();
// Activate white-on-black mode...
void setInverse(bool enabled); // ...whole display
void setInverseOutput(bool enabled); // ...future writes
// Set display contrast level (0-127)...
void setContrast(uint8_t level);
// Place the cursor at the start of the current line...
void home();
// Place the cursor at position (column, line)...
void setCursor(uint8_t column, uint8_t line);
// Assign a user-defined glyph (5x8) to an ASCII character (0-31)...
void createChar(uint8_t chr, const uint8_t *glyph);
// Write an ASCII character at the current cursor position (7-bit)...
virtual size_t write(uint8_t chr);
// Draw a bitmap at the current cursor position...
void drawBitmap(const uint8_t *data, uint8_t columns, uint8_t lines);
// Draw a chart element at the current cursor position...
void drawColumn(uint8_t lines, uint8_t value);
private:
uint8_t pin_sclk;
uint8_t pin_sdin;
uint8_t pin_dc;
uint8_t pin_reset;
uint8_t pin_sce;
// Chip variant in use...
uint8_t model;
// The size of the display, in pixels...
uint8_t width;
uint8_t height;
// Current cursor position...
uint8_t column;
uint8_t line;
// Current output mode for writes (doesn't apply to draws)...
bool inverse_output = false;
// User-defined glyphs (below the ASCII space character)...
const uint8_t *custom[' '];
// Send a command or data to the display...
void send(uint8_t type, uint8_t data);
};
#endif /* PCD8544_H */
/* vim: set expandtab ts=4 sw=4: */
What is it?
===========
**PCD8544** is a library for the [Arduino](http://arduino.cc/) to interface with LCDs based on the
Philips PCD8544 controller ([datasheet](https://github.com/carlosefr/pcd8544/blob/docs/docs/pcd8544.pdf?raw=true))
or compatibles. These displays are commonly found on older monochrome mobile phones, such as the
[Nokia 3310](http://en.wikipedia.org/wiki/Nokia_3310) or [5110](http://en.wikipedia.org/wiki/Nokia_5110),
so if you have one of these stuck in a drawer, take it out and start hacking away! :)
This library is meant to have a minimal memory footprint. If you need graphics and other features and can spare the resources, check out the [library](https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library) from Adafruit.
![PCD8544.png](https://raw.githubusercontent.com/carlosefr/pcd8544/gh-pages/PCD8544.jpg)
Installation
============
Download the latest zip file from the [releases](https://github.com/carlosefr/pcd8544/releases) section. Then open it from the `Sketch > Include Library > Add .ZIP Library...` menu inside the Arduino IDE and a new "PCD8544" entry should appear in the `Sketch > Include Library` and `File > Examples` menus.
![Arduino IDE](https://raw.githubusercontent.com/carlosefr/pcd8544/gh-pages/screenshot-01.png)
How it Works
============
To use this library, you must first connect your LCD to the proper pins on the Arduino.
For a Nokia 3310 display the connections would be the following:
Display Pin | Arduino Pin
------------------|------------
Pin 1 | +3.3V Pin
Pin 2 (SCLK) | Digital Pin 3
Pin 3 (SDIN/MOSI) | Digital Pin 4
Pin 4 (D/C) | Digital Pin 5
Pin 5 (SCE) | Digital Pin 7
Pin 6 | Ground Pin
Pin 7 | 10uF capacitor to Ground Pin
Pin 8 (RST) | Digital Pin 6
For this display model, "Pin 1" is the leftmost pin when facing the back of the display with the connector on top.
Nokia 5110 displays are slightly different. They have an external oscillator pin between pins 5 and 6 which should
be connected to +3.3V. I haven't used one of these myself, so please see the diagrams on
[this page](http://serdisplib.sourceforge.net/ser/pcd8544.html) for more details.
Since these LCDs are **3.3V** devices, you should add
[extra components](http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=65) to
connect it to the digital pins of the Arduino (not necessary if you are using a 3.3V variant
of the Arduino, such as the [Arduino Pro](http://www.arduino.cc/en/Main/ArduinoBoardPro)). However, the I/O pins
are supposed to be 5V tolerant, so you can get by with 1K resistors in series with each pin if you like to live
dangerously.
Now, take a moment and read through the included [`HelloWorld.ino`](examples/HelloWorld/HelloWorld.ino) example.
It shows how to use the basic features of the library. There is also another
[`Thermometer.ino`](examples/Thermometer/Thermometer.ino) example that demonstrates bitmapped graphics and charts.
Custom Symbols
==============
The library allows the use of custom bitmap symbols (5x8), defined by an array of five bytes.
To make it easy to create custom symbols, there's a graphical glyph editor
[available online](http://carlosefr.github.io/pcd8544/).
/*
* PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs.
*
* Copyright (c) 2010 Carlos Rodrigues <cefrodrigues@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,