Raspberry Pi with I2C 2004 LCD

Reblogged from: http://hardware-libre.fr/2014/03/en-raspberry-pi-using-a-4×20-characters-display/

Some people requested it, so here it is…
We want to use a 4×20 caracters Arduino LCD on the Raspberry Pi.
We will use the I²C protocol and a small python class to access the display.

02_1

As you can see in this picture, the LCD display has an included I²C board.

Wiring is based on our add a RTC clock previous tutorial . The two modules (RTC and display) could be used in pair, thanks to the I²C protocol. You could even chain more I²C devices.

Be carefull with the logic levels :
Our precious Raspberry Pi works with a 3.3V logic. The display is a 5V logic device. When the Pi’s I²C internal pull-ups are ok for the RTC clock, those won’t be enough to handle the display.
So, we’ll use a small I²C logic converter. It will be very usefull for our future projects, because it allows using 3.3V and 5V devices without worrying about I²C logic levels. A ready-to-use converter costs only a few cents, so it’s a very nice component to add to the Pi.

1- What you need

– a 4×20 I²C display (like this one)
– a 70 cents I²C 3.3v-5v logic converter (like this one)

2- Wiring

Let’s start from the converter :

5V side :
AVCC -> Pi +5v
AVCC -> display +5v
AGND -> Pi GND
AGND -> display GND
ASCL -> display SCL
ASDA -> display SDA

3.3V side :
BVCC -> Pi +3.3v
BGND -> Pi GND
BSCL -> Pi SCL
BSDA -> Pi SDA

With this wiring, one could add I²C devices, without worrying about logic levels : 5V modules connect to the converter’s A side, 3.3V modules connect to the B side. Easy.

2- Enable and setup the I²C in Raspbian

We add the modules to the startup : :

sudo nano /etc/modules

Add those 2 lines:

i2c-bcm2708 
i2c-dev

We reboot :

sudo reboot

we now install the required components :

sudo apt-get install python-smbus i2c-tools

We remove the I²C modules from the blacklist :

sudo nano /etc/modprobe.d/raspi-blacklist.conf

the line

blacklist i2c-bcm2708

becomes

#blacklist i2c-bcm2708

Our Raspberry should be ready to use I²C devices after a new reboot.

sudo reboot

3- Testing the I²C

We are going to use the i2cdetect command to list every I²C devices. This command is not the same on a Rev 1 or Rev 2 Pi (I²C bus address is different), so it’s important to choose the right one :

sudo i2cdetect -y 0 (for Rev 1)
sudo i2cdetect -y 1 (for Rev 2)

Capture
On this screenshot, you can see my Pi has 3 I²C devices :
– display with address #27
– unused AT24C32 eeprom chip with address #50
– DS1307 RTC with address #68. It is noted « UU » because it’s in use.
Your display may have another address. I’ve seen #24 and #28 but it can be something else. It should be indicated in the display’s datasheet. We need this address to setup the driver a little later.

4- Python class install

To ‘talk’ with the display, we will use a small python class. So, the prefered language to use the display will also be python.
Let’s create 2 files in a subfolder of the home directory, and copy-paste the content in each one

cd
mkdir display_420
sudo nano i2c_lib.py
import smbus
from time import *

class i2c_device:
   def __init__(self, addr, port=1):
      self.addr = addr
      self.bus = smbus.SMBus(port)

# Write a single command
   def write_cmd(self, cmd):
      self.bus.write_byte(self.addr, cmd)
      sleep(0.0001)

# Write a command and argument
   def write_cmd_arg(self, cmd, data):
      self.bus.write_byte_data(self.addr, cmd, data)
      sleep(0.0001)

# Write a block of data
   def write_block_data(self, cmd, data):
      self.bus.write_block_data(self.addr, cmd, data)
      sleep(0.0001)

# Read a single byte
   def read(self):
      return self.bus.read_byte(self.addr)

# Read
   def read_data(self, cmd):
      return self.bus.read_byte_data(self.addr, cmd)

# Read a block of data
   def read_block_data(self, cmd):
      return self.bus.read_block_data(self.addr, cmd)
sudo nano lcddriver.py
import i2c_lib
from time import *

# LCD Address
ADDRESS = 0x27

# commands
LCD_CLEARDISPLAY = 0x01
LCD_RETURNHOME = 0x02
LCD_ENTRYMODESET = 0x04
LCD_DISPLAYCONTROL = 0x08
LCD_CURSORSHIFT = 0x10
LCD_FUNCTIONSET = 0x20
LCD_SETCGRAMADDR = 0x40
LCD_SETDDRAMADDR = 0x80

# flags for display entry mode
LCD_ENTRYRIGHT = 0x00
LCD_ENTRYLEFT = 0x02
LCD_ENTRYSHIFTINCREMENT = 0x01
LCD_ENTRYSHIFTDECREMENT = 0x00

# flags for display on/off control
LCD_DISPLAYON = 0x04
LCD_DISPLAYOFF = 0x00
LCD_CURSORON = 0x02
LCD_CURSOROFF = 0x00
LCD_BLINKON = 0x01
LCD_BLINKOFF = 0x00

# flags for display/cursor shift
LCD_DISPLAYMOVE = 0x08
LCD_CURSORMOVE = 0x00
LCD_MOVERIGHT = 0x04
LCD_MOVELEFT = 0x00

# flags for function set
LCD_8BITMODE = 0x10
LCD_4BITMODE = 0x00
LCD_2LINE = 0x08
LCD_1LINE = 0x00
LCD_5x10DOTS = 0x04
LCD_5x8DOTS = 0x00

# flags for backlight control
LCD_BACKLIGHT = 0x08
LCD_NOBACKLIGHT = 0x00

En = 0b00000100 # Enable bit
Rw = 0b00000010 # Read/Write bit
Rs = 0b00000001 # Register select bit

class lcd:
   #initializes objects and lcd
   def __init__(self):
      self.lcd_device = i2c_lib.i2c_device(ADDRESS)

      self.lcd_write(0x03)
      self.lcd_write(0x03)
      self.lcd_write(0x03)
      self.lcd_write(0x02)

      self.lcd_write(LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | LCD_4BITMODE)
      self.lcd_write(LCD_DISPLAYCONTROL | LCD_DISPLAYON)
      self.lcd_write(LCD_CLEARDISPLAY)
      self.lcd_write(LCD_ENTRYMODESET | LCD_ENTRYLEFT)
      sleep(0.2)

   # clocks EN to latch command
   def lcd_strobe(self, data):
      self.lcd_device.write_cmd(data | En | LCD_BACKLIGHT)
      sleep(.0005)
      self.lcd_device.write_cmd(((data & ~En) | LCD_BACKLIGHT))
      sleep(.0001)

   def lcd_write_four_bits(self, data):
      self.lcd_device.write_cmd(data | LCD_BACKLIGHT)
      self.lcd_strobe(data)

   # write a command to lcd
   def lcd_write(self, cmd, mode=0):
      self.lcd_write_four_bits(mode | (cmd & 0xF0))
      self.lcd_write_four_bits(mode | ((cmd << 4) & 0xF0))

   # put string function
   def lcd_display_string(self, string, line):
      if line == 1:
         self.lcd_write(0x80)
      if line == 2:
         self.lcd_write(0xC0)
      if line == 3:
         self.lcd_write(0x94)
      if line == 4:
         self.lcd_write(0xD4)

      for char in string:
         self.lcd_write(ord(char), Rs)

   # clear lcd and set to home
   def lcd_clear(self):
      self.lcd_write(LCD_CLEARDISPLAY)
      self.lcd_write(LCD_RETURNHOME)

In this lcddriver.py file, you’ll have to set the I²C address. It defaults to #27 :

# LCD Address
ADDRESS = 0x27

5- Using the display

It’s the fun part…
If you want to use the display in a python script, you only have to include those 2 files your script folder.
Here is what you need to use it in you script :

# loading the class
import lcddriver
from time import *

# lcd start
lcd = lcddriver.lcd()

# this command clears the display (captain obvious)
lcd.lcd_clear()

# now we can display some characters (text, line)
lcd.lcd_display_string("   Hello world !", 1)
lcd.lcd_display_string("      I am", 2)
lcd.lcd_display_string("        a", 3)
lcd.lcd_display_string("   Raspberry Pi !", 4)

As you can see, using this display with the Pi is very easy.

Sans titre
You can download these scripts on github :
https://github.com/CaptainStouf/raspberry_lcd4x20_I2C

Raspberry Pi Touch Screen Display Connect Tutorial

RASPBERRY PI WITH A 3.2″ TFT WITH TOUCH CONTROL

I have spent the last few weeks working on getting a SainSmart 3.2″ TFT with touch control working with my Raspberry Pi and I have had success.

You can see an update on this project here;
http://ozzmaker.com/2013/05/27/raspberry-pi-with-a-3-2-tft-with-touch-control-part-2/

#######Update March 2014#######
If you are interested in a TFT for your Raspberry Pi, this may interest you;
https://www.kickstarter.com/projects/2135028730/piscreen-a-35-tft-with-touchscreen-for-the-raspber
We have started a kickstarter for a 3.5″ TFT with touch control, which comes in a kit or preassembled.
###############################

I have currently connected it up with a breadboard, I now need to work on a more permanent solution.

Download the Kernel that contains the drivers.

Click on the images for a larger view.

Graph
Graph
Click the image below for a much larger version
Graph

My setup;
M74HC4040B1R 
74HC4094N 
5v to TFT
3.3v to ICs
Reset through 10k resistor
Back light connected to 3.3v

I start Xwindows with sudo FRAMEBUFFER=/dev/fb1 startx -- -dpi 60

Thanks to XaLKiDEoS , Notro, drsb and  valdodov.;
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=64&t=33679
http://www.valdodov.com/

Cheap and Powerful LCD Display for Arduino and Raspberry Pi

This is a little TFT LCD from SainSmart for only $12.99 with lots of suscessful expriments and test around.

For Arduino:

Arduino + SainSmart 1.8 TFT graphictest_highspeed:

 

Test ecran tft 1.8 sainsmart + modification librairie sur arduino(français):

 

Talking Arduino DHT-22 with TFT LCD:

 

Arduino Esm 2.0 test run:

 

Arduino Connected to 1.8″ SPI TFT LCD:

 

For Raspberry Pi:

Raspberry Pi boots with 1.8″ TFT LCD console:

 

SainSmart 1.8 ST7735R LCD on Raspberry P:

 

DIY Raspberry Pi Glass – Wearable Computer:

 

Raspberrypi booting to 1.8″ LCD:

 

SainSmart 1602 LCD Keypad (Arduino Compatible)

Feature:     

  • This is a 16×2 LCD Keypad module for Arduino Diecimila Duemilanove, UNO, MEGA1280, MEGA2560  board.
  • Blue Backlight with white words, adjustable backlighting.
  • 4 Bit Arduino LCD Library
  • 100% brand new and high quality
  • Sample Code Download

Description: 

The LCD Keypad shield is developed for Arduino compatible boards, to provide a user-friendly interface that allows users to go through the menu, make selections etc.

It consists of a 1602 white character blue backlight LCD.

The keypad consists of 5 keys — select, up, right, down and left.

To save the digital IO pins, the keypad interface only uses one ADC channel.

The key value is read out through a 5 stage voltage divider.

Diagram:

Bezel for SainSmart LCD Keypad Shield for the Arduino

The Code

Make sure you have the LiquidCrystal library installed. // LiquidCrystal Print // by Parzivail #include LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7); void setup() { lcd.clear(); lcd.begin(16, 2); } void loop() { lcd.setCursor(0, 0); lcd.print(“Hello, World!”); }
The LCD keypad shield is super-easy to use.  I just connected it to my Uno and it’s ready to go.  The shield uses the standard LiquidCrystal.h library.  There is some example code, a manual and some other info for the shield at the Sainsmart LCD keypad shield WIKI.

The LCD shield uses digital pins 4,5,6,7,8,9, and 10 for the display and uses Analog pin A0 for the keypad buttons.

I would only use this shield if I were running a program that was using nothing but this shield.  I don’t see an easy way to gain access to pins 11,12, and 13.  You are able to solder headers on to access Analog pins A1-A5, and digital pins 1,2,and 3.

Sample Code Download

Where to buy

 

Referrence:

http://www.instructables.com/id/Arduino-Controlled-Motion-Sensor/

http://www.meanpc.com/2012/02/sainsmart-lcd-keypad-arduino-shield.html

http://www.thingiverse.com/thing:123636

What’s Included In An Arduino Starter Kit?

What’s Included In An Arduino Starter Kit?

I’ve noticed that there many types of Arduino starters kit sold online, including those from adafruit, SainSmart, SparkFun and arduono.cc. Whatever the brand is. there are certain compoents that are included in a starter kit. Let’s see what the article lists as the things that should be included in a starter kit.

Everything Thing you need to Know About Arduino

I found another cool video for Arduino starters. Let’s watch it together.

Arduino Traffic Light

Previously, we talked about the traffic light project for beginners. I have found a video about this. Let’s get to know more about it. If you want further information about the project, please refer to my article at: https://arduinogeek.wordpress.com/2013/03/12/lets-start-to-program/

Some Recommended Arduino Beginner Projects

Now I’m going to make my own projects now. I was confused that what I should start with. Fortunately, I got much help from the Internet and found lots of interesting projects that are suitable for beginners. Now I’ve owned a SainSmart Starter Kit and a Mega 2560, and I can use them to do many basic and medium level projects.

1. http://startingelectronics.com/beginners/start-electronics-now/tut10-ten-arduino-projects-for-absolute-beginners/

It lists 10 Arduino projects for beginners and explains them very well. This is one chapater of the website’s tutorial. The previous chapter also helps to gain better understanding of arduino projects. I think I can finishing making all these projects, I will have huge progress.

3

2. http://forum.zomgstuff.net/showthread.php?20710-Arduino-Projects-amp-Inspiration-for-Beginners

The author writes down some of the projects he has made and posts all the photos of his finished work. He also mentions some useful information, like helpful arduino forums.

4

3.

This one is more visual for you to learn about Arduino projects.

 

All Kinds of Arduino Tutorials

Many beginners would complain that it’s hard to find useful and handy tutorials for Arduino. Now I wil recommend several useful online tutorials for you guys. I’m also using these tutorials and they help me a lot.

1. http://arduino.cc/en/Tutorial/HomePage

图像

Aduino.cc is a very professional Arduino forum. You can find almost all the answers to your questions. Their tutorial can satisfy your basic needs. If you can’t find your answers in their tutorial, just ask them directly in the forum.

2. http://www.ladyada.net/learn/arduino/

图像

This tutorial is very organized. They divide this tutorial into several lessons, by which you can learn step by step. It is easy to read and easy to understand.

3. http://robots.net/article/2751.html

图像

This one mainly introduces the basic knowledage about programming.

Arduino Tutorial

Arduino Tutorial

I have just found a very useful tutorial for Arduino and would like to share it with everybody.