Dangerous Prototypes

Dangerous Prototypes => Bus Pirate Development => Topic started by: pietja on October 20, 2011, 10:45:16 pm

Title: BPv4 HD66717 I2C Demo
Post by: pietja on October 20, 2011, 10:45:16 pm
HD66717 LCD Controller
Everyone knows the HD44780 LCD controller but there are many others.

This demo is about the "BT21605AV-YETF-LED04-I2C" 2x16 LCD module with the less common HD66717 controller in I2C mode.

Overview
Chip: HD66717
Bus: I2C, pull-up resistors required.
Power: 2.7-5.5v
Reference: HD66717 Controller (http://http://www.gaw.ru/pdf/lcd/Chips/Hitachi/hd66717.pdf)
Datasheet of the display (http://http://www.qscomp.cz/Pdf/BT_21605_i2cbus_dm.pdf)
Second datasheet with the I2C address (http://http://www.swissdis.ch/produkte/documents/FL_BT21605AV-YETF-LED04-I2CHD6.pdf)

Connecting this display requires a minimal of four connections.
Code: [Select]
Connections
BP      LCD

SDA    SDL
SCL    SCL
+5V    VDD
GND    GND

also connect 3.3V back to VPU on the Bus Pirate
[attachment=1]
Fist we need to setup the Bus Pirate to use the I2C protocol.
Code: [Select]
HiZ>m << Enter mode selection
1. HiZ
2. 1-WIRE
3. I2C
4. SPI
5. 2WIRE
6. 3WIRE
7. LCD
8. DIO
x. exit(without change)

(1)>3 << Select I2C
I2C mode:
 1. Software
 2. Hardware

(1)>2 << Select Hardware
Set speed:
 1. 100KHz
 2. 400KHz
 3. 1MHz

(1)>1 << Select 100KHz
Ready
I2C>W << Enable PSU
Power supplies ON
I2C>P << Enable pull-ups
Pull-up resistors ON
I2C>
In the second datasheet we found the default I2C address but we use the search option of the Bus Pirate to make sure.
Code: [Select]
I2C>(1) << Finding the Controller
Searching I2C address space. Found devices at:
0x70(0x38 W) 0x72(0x39 W)
I2C>
0x70 is the instruction address and 0x72 is the data address.
This controller is write only so we can't get any data back.

Now we are going to initialize the controller.
For more details see page 39 of the HD66717 datasheet.
Code: [Select]
I2C>
I2C>[0x70 << Addressing the controller for instructions
I2C START BIT
WRITE: 0x70 ACK
I2C>0x1C << Power control
WRITE: 0x1C ACK
I2C>0x4F << Contrast control
WRITE: 0x4F ACK
I2C>0x0F << Cursor control
WRITE: 0x0F ACK
I2C>0x14 << Display on/off control
WRITE: 0x14 ACK
I2C>] << We are done initializing the controller.
I2C STOP BIT
I2C>
This display is addressed as and LCD with 4 lines.
Each line in the controller is 12 characters long however we can only see 8 characters of them, so after 8 useful characters we need to send 4 useless ones to get back on the screen.

Sending
Code: [Select]
<Line 1>@@@@{Line 2}@@@@[Line 3]@@@@(Line 4)@@@@
will result in the following and get us back home:
Code: [Select]
<Line 1>{Line 2}
[Line 3](Line 4)
Now we can send something useful to the controller to finally see something on the screen.
Code: [Select]
I2C>[0x70 0x02] << first we go back home
I2C START BIT
WRITE: 0x70 ACK
WRITE: 0x02 ACK
I2C STOP BIT
I2C>[0x72 0x3c 0x4c 0x69 0x6e 0x65 0x20 0x31 0x3e] << sending "<Line 1>"
I2C START BIT
WRITE: 0x72 ACK
WRITE: 0x3C ACK
WRITE: 0x4C ACK
WRITE: 0x69 ACK
WRITE: 0x6E ACK
WRITE: 0x65 ACK
WRITE: 0x20 ACK
WRITE: 0x31 ACK
WRITE: 0x3E ACK
I2C STOP BIT
I2C>[0x72 0x40 0x40 0x40 0x40] << skipping past the 4 hidden characters
I2C START BIT
WRITE: 0x72 ACK
WRITE: 0x40 ACK
WRITE: 0x40 ACK
WRITE: 0x40 ACK
WRITE: 0x40 ACK
I2C STOP BIT
I2C>
[attachment=0]
Now its easy to send anything we want.
Code: [Select]
[0x70 0x1c 0x4f 0x0f 0x14] ;initialize

[0x70 0x02] ;return home
[0x72 0x3c 0x4c 0x69 0x6e 0x65 0x20 0x31 0x3e] ;<Line 1>
[0x72 0x40 0x40 0x40 0x40] ;@@@@
[0x72 0x7b 0x4c 0x69 0x6e 0x65 0x20 0x32 0x7d] ;{Line 2}
[0x72 0x40 0x40 0x40 0x40] ;@@@@
[0x72 0x5b 0x4c 0x69 0x6e 0x65 0x20 0x33 0x5d] ;[Line 3]
[0x72 0x40 0x40 0x40 0x40] ;@@@@
[0x72 0x28 0x4c 0x69 0x6e 0x65 0x20 0x34 0x29] ;(Line 4)
[0x72 0x40 0x40 0x40 0x40] ;@@@@

[0x70 0x02] ;return home
[0x72 0x42 0x75 0x73 0x50 0x69 0x72 0x61 0x74 0x40 0x40 0x40 0x40 0x65 0x76 0x34 0x20 0x44 0x61 0x6e 0x67 0x40 0x40 0x40 0x40 0x65 0x72 0x6f 0x75 0x73 0x20 0x50 0x72 0x40 0x40 0x40 0x40 0x6f 0x74 0x6f 0x74 0x79 0x70 0x65 0x73 0x40 0x40 0x40 0x40] ;BusPirat@@@@ev4 Dang@@@@erous Pr@@@@ototypes@@@@


Note this is only the basic stuff for this controller, like the HD44780 it also has the ability to use custom characters (8 for the HD44780 and 4 for the HD66717) and it has software controlled contrast.
Title: Re: BPv4 HD66717 I2C Demo
Post by: ian on October 21, 2011, 10:01:10 am
Fantastic demo, thank you. I'll post this up. May I please copy this to a wiki page under a CC-BY-SA license (with credit to you of course)?

Are these easy to source? I have lots of projects where a 2pin LCD connection would be ideal for quick/temporary debugging.
Title: Re: BPv4 HD66717 I2C Demo
Post by: Sjaak on October 21, 2011, 10:17:42 am
[quote author="ian"]
Are these easy to source? I have lots of projects where a 2pin LCD connection would be ideal for quick/temporary debugging.[/quote]

Design your own :) or use the bp lcd adapter
Title: Re: BPv4 HD66717 I2C Demo
Post by: pietja on October 21, 2011, 11:44:02 am
Of course it would be nice if this is on the wiki, you have my ok to copy it.

The display i used is from a really old stock and its not made any more, the replacement is also hard to get (http://http://uk.farnell.com/batron/bthq21605av-yetf-led04-i2c/lcd-module-alphanumeric-16x2-i2c/dp/1137381) and it uses a slightly different controller.

However there are other LCD models with an I2C or SPI interface.
http://www.lcd-module.com/products/dog.html (http://www.lcd-module.com/products/dog.html)

And like Sjaak said there is also the bp lcd adapter.

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01072076920session_write_close ( )...(null):0
20.01102208512ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01102209288Database_MySQL->query( ).../DatabaseHandler.php:119
40.05612348024Database_MySQL->error( ).../Db-mysql.class.php:273