1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Arduino UNO 3でキャラクター液晶、Grove Serial LCD V1.0で遊ぶ

Last updated at Posted at 2024-09-16

Arduino UNO 3でキャラクター液晶、Grove Serial LCD V1.0で遊ぶ

x 過去ログを見よ!!
x 前から持っていた。LCDです。
x 新規タブの操作がわかる人

参考

o_coq417.jpg

結果

o_coq419.jpg

o_coq418.jpg

プログラム

SerialLCD_Library_Hello_World_UNO_1.ino



/*
  SerialLCD Library - Hello World
 
 Demonstrates the use a 16x2 LCD SerialLCD driver from Seeedstudio.
 
 This sketch prints "Hello, Seeeduino!" to the LCD
 and shows the time.
 
 Library originally added 16 Dec. 2010
 by Jimbo.we 
 http://www.seeedstudio.com
 */

// include the library code:
#include "SerialLCD.h"
#include <SoftwareSerial.h> //this is a must

// initialize the library
SerialLCD slcd(19,18);//this is a must, assign soft serial pins

void setup() {
  // set up
  slcd.begin();
  slcd.backlight();
  // Print a message to the LCD.
  slcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  slcd.setCursor(0, 1);
  // print the number of seconds since reset:
  slcd.print(millis()/1000,DEC);
}



SerialLCD.cpp


/*
  SerialLCD.h - Serial LCD driver Library
  2010 Copyright (c) Seeed Technology Inc.  All right reserved.
 
  Original Author: Jimbo.We
  Contribution: Visweswara R 
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include "SerialLCD.h"

SerialLCD::SerialLCD(uint8_t rx, uint8_t tx):SoftwareSerial(rx,tx)
{

}

/********** High level commands, for the user! **********/

// Initialize the Serial LCD Driver. SerialLCD Module initiates the communication.
void SerialLCD::begin()
{
    SoftwareSerial::begin(9600);
    /*while(1)
    {
        if ( SoftwareSerial::available() > 0 &&  SoftwareSerial::read()==SLCD_INIT )
        {
            SoftwareSerial::write(SLCD_INIT_ACK);
            break;
        }
    }*/
    delay(2);
    SoftwareSerial::write(SLCD_CONTROL_HEADER);   
    SoftwareSerial::write(SLCD_POWER_OFF); 
    delay(1);
    SoftwareSerial::write(SLCD_CONTROL_HEADER);   
    SoftwareSerial::write(SLCD_POWER_ON);
    delay(1);
    SoftwareSerial::write(SLCD_INIT_ACK);
    while(1)
    {
        if (SoftwareSerial::available() > 0 &&SoftwareSerial::read()==SLCD_INIT_DONE)
            break;
    }
    delay(2);
}

// Clear the display
void SerialLCD::clear()
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);   
    SoftwareSerial::write(SLCD_CLEAR_DISPLAY);   
}

// Return to home(top-left corner of LCD)
void SerialLCD::home()
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_RETURN_HOME);  
    delay(2);//this command needs more time;  
}

// Set Cursor to (Column,Row) Position
void SerialLCD::setCursor(uint8_t column, uint8_t row)
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER); 
    SoftwareSerial::write(SLCD_CURSOR_HEADER); //cursor header command
    SoftwareSerial::write(column);
    SoftwareSerial::write(row);
}

// Switch the display off without clearing RAM
void SerialLCD::noDisplay() 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_DISPLAY_OFF);    
}

// Switch the display on
void SerialLCD::display() 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_DISPLAY_ON);    
}

// Switch the underline cursor off
void SerialLCD::noCursor() 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_CURSOR_OFF);     
}

// Switch the underline cursor on
void SerialLCD::cursor() 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_CURSOR_ON);     
}

// Switch off the blinking cursor
void SerialLCD::noBlink() 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_BLINK_OFF);     
}

// Switch on the blinking cursor
void SerialLCD::blink() 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_BLINK_ON);     
}

// Scroll the display left without changing the RAM
void SerialLCD::scrollDisplayLeft(void) 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_SCROLL_LEFT);
}

// Scroll the display right without changing the RAM
void SerialLCD::scrollDisplayRight(void) 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_SCROLL_RIGHT);
}

// Set the text flow "Left to Right"
void SerialLCD::leftToRight(void) 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_LEFT_TO_RIGHT);
}

// Set the text flow "Right to Left"
void SerialLCD::rightToLeft(void) 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_RIGHT_TO_LEFT);
}

// This will 'right justify' text from the cursor
void SerialLCD::autoscroll(void) 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_AUTO_SCROLL);
}

// This will 'left justify' text from the cursor
void SerialLCD::noAutoscroll(void) 
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);
    SoftwareSerial::write(SLCD_NO_AUTO_SCROLL);
}
void SerialLCD::Power(void)
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);   
    SoftwareSerial::write(SLCD_POWER_ON); 
}
void SerialLCD::noPower(void)
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);   
    SoftwareSerial::write(SLCD_POWER_OFF); 
}
//Turn off the backlight
void SerialLCD::noBacklight(void)
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);   
    SoftwareSerial::write(SLCD_BACKLIGHT_OFF);   
}
//Turn on the back light
void SerialLCD::backlight(void)
{
    SoftwareSerial::write(SLCD_CONTROL_HEADER);   
    SoftwareSerial::write(SLCD_BACKLIGHT_ON);   
}
// Print Commands

void SerialLCD::print(uint8_t b)
{
    SoftwareSerial::write(SLCD_CHAR_HEADER);
    SoftwareSerial::write(b);
}
void SerialLCD::print(const char b[])
{
    SoftwareSerial::write(SLCD_CHAR_HEADER);
    SoftwareSerial::write(b);
}

void SerialLCD::print(unsigned long n, uint8_t base)
{
    unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
    unsigned long i = 0;

    if (base == 0) print(n);

    else if(base!=0)
    {
        if (n == 0) {
            print('0');
            return;
        }

        while (n > 0) {
            buf[i++] = n % base;
            n /= base;
        }

        for (; i > 0; i--)
            print((char) (buf[i - 1] < 10 ?
                          '0' + buf[i - 1] :
                          'A' + buf[i - 1] - 10));
    }
}



SerialLCD.h



/*
  SerialLCD.h - Serial LCD driver Library
  2010 Copyright (c) Seeed Technology Inc.  All right reserved.
 
  Original Author: Jimbo.We
  Contribution: Visweswara R 
  
  Modified 15 March,2012 for Arduino 1.0 IDE
  by Frankie.Chu
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef SERIAL_LCD_H
#define SERIAL_LCD_H

#include <inttypes.h>
#include <Arduino.h>
#include <SoftwareSerial.h>

//Initialization Commands or Responses

#define SLCD_INIT  0xA3
#define SLCD_INIT_ACK 0xA5
#define SLCD_INIT_DONE  0xAA

//WorkingMode Commands or Responses
#define SLCD_CONTROL_HEADER 0x9F
#define SLCD_CHAR_HEADER  0xFE
#define SLCD_CURSOR_HEADER  0xFF
#define SLCD_CURSOR_ACK   0x5A

#define SLCD_RETURN_HOME  0x61
#define SLCD_DISPLAY_OFF  0x63
#define SLCD_DISPLAY_ON   0x64
#define SLCD_CLEAR_DISPLAY  0x65
#define SLCD_CURSOR_OFF   0x66
#define SLCD_CURSOR_ON    0x67
#define SLCD_BLINK_OFF    0x68
#define SLCD_BLINK_ON   0x69
#define SLCD_SCROLL_LEFT  0x6C
#define SLCD_SCROLL_RIGHT 0x72
#define SLCD_NO_AUTO_SCROLL 0x6A
#define SLCD_AUTO_SCROLL  0x6D
#define SLCD_LEFT_TO_RIGHT  0x70
#define SLCD_RIGHT_TO_LEFT  0x71
#define SLCD_POWER_ON     0x83
#define SLCD_POWER_OFF    0x82
#define SLCD_INVALIDCOMMAND 0x46
#define SLCD_BACKLIGHT_ON 0x81
#define SLCD_BACKLIGHT_OFF  0x80

class SerialLCD : public SoftwareSerial{
public:

    SerialLCD(uint8_t, uint8_t);
    void begin();
    void clear();
    void home();

    void noDisplay();
    void display();
    void noBlink();
    void blink();
    void noCursor();
    void cursor();
    void scrollDisplayLeft();
    void scrollDisplayRight();
    void leftToRight();
    void rightToLeft();
    void autoscroll();
    void noAutoscroll();

    void setCursor(uint8_t, uint8_t);
    void noPower(void);
    void Power(void);
    void noBacklight(void);
    void backlight(void);
    void print(uint8_t b);
    void print(const char[]);
    void print(unsigned long n, uint8_t base);

};

#endif



1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?