Pages: [1]   Go Down
Author Topic: eDIPTFT43-ATP programming  (Read 910 times)
0 Members and 1 Guest are viewing this topic.
San Juan, TX
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I have this GLCD to a Arduino Mega. It turns on and I can send simple commands. I found a quick sample that works using the Wire.h. The problem is the way the commands are sent. There is no problem converting the commands to bytes when it is a one for one. It is kinda hard to explain here is the sample code that I found:
I found it here
http://arduino.cc/forum/index.php?action=printpage;topic=62368.0
Code:
#include <Wire.h>
#define i2c_eaDIP ( 0xDE >> 1 )       // Ba2|Ba1|Ba0|Sa2|Sa1|Sa0|R/W

byte bcc;      

void setup()
{
  Serial.begin(9600);

  Wire.begin();           // join i2c bus (address optional for master)
  Wire.beginTransmission(i2c_eaDIP);  // transmit to device #0xDE
  Display_loeschen();
  Serial.println( Wire.endTransmission(), DEC);     // stop transmitting

  delay(100);

  Wire.requestFrom(0xDF, 1);
  Serial.println(Wire.available(), HEX);
  Serial.println(Wire.receive(), HEX);
 }

void Display_loeschen() {
  Wire.send(0x11);   // <DC1>
  Wire.send(0x03);   // len
  Wire.send(0x1B);   // ESC
  Wire.send('D');
  Wire.send('L');
  bcc = ( 0x11 + 0x03 + 0x1B + 'D' + 'L' ) % 0x100;
  Wire.send(bcc);
}

void loop()
{
  for(;;)
    ;
}

So pretty much you have to send 0x11 fist all the time, then the size, then ESC then the commands. Here is the manual link:
http://www.lcd-module.com/eng/pdf/grafik/ediptft43-ae.pdf
Notice on page 10 they have some example that makes no sense to me. All I just need to know is how they got those HEX numbers there
the sample command is
Code:
<DC1> len ESC D L ESC G D 0 0 479 271 bcc
$11 $0E $1B $44 $4C $1B $47 $44 $00 $00 $00 $00 $DF $01 $0FE $01 $6
so for each 0 they put 2 $00
for 479 they put $DF $01
and for 271  $0FE $01
I have a function that I wrote that takes the string command and gets each character and turns it to a bytes.
Code:
void  sendData( String commandString, boolean command){
Wire.write(0x11);
int bcc = 0x11;
int buf = commandString.length()+1;
        
        char bytes[buf];
commandString.toCharArray(bytes, buf);
        buf = buf-1;
        int length = buf;
if(command){
length = length + 1;
}

bcc = bcc + length;
Wire.write(length); // length
if(command){
Wire.write(27); // ESC
bcc = bcc + 27;
}

for(int i =0 ; i < buf; i++){
Wire.write((int)bytes[i]);
bcc = bcc + (int)bytes[i];
}
Wire.write(bcc);
}

This works great sendData("DL", true);
But, it messes up  when I try the example "ESCGD00479271"
Even If I was to break out each segment how do I figure out the size.

Any help would be greatly appreciated.

Thanks,
-Martin

Moderator edit: [code] ... [/code] tags added. (Nick Gammon)
« Last Edit: April 09, 2012, 05:26:30 pm by Nick Gammon » Logged

San Juan, TX
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just in case it might help anyone.
I found out what is going on with sending numbers. Apparently it sends numbers broken out into 2 parts of 2 hex numbers and backwards. For example: 479 decimal is 1DF HEX
But it send it $DF then $01.
It took me a while to finally see it, I'm just happy I understand whats going on now.
I will post the method I am working on that will send the commands correctly once it is finish.

I just have one issue with sending multiple commands. I have posted a question in the connection section where the I2C stuff is because I think it has to do with that. Unless it is the GLCD who is limited to only one command, I need to check it out.

Here is the link to the other post : http://arduino.cc/forum/index.php/topic,100597.0.html

Thanks,
Martin
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just have one issue with sending multiple commands. I have posted a question in the connection section where the I2C stuff is because I think it has to do with that. Unless it is the GLCD who is limited to only one command, I need to check it out.

Post your code please.
Logged

San Juan, TX
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help.

Code:
#include <Wire.h>
#define i2c_eaDIP ( 0xDE >> 1)       // Ba2|Ba1|Ba0|Sa2|Sa1|Sa0|R/W

byte bcc;       

void setup()
{
  Serial.begin(9600);

  Wire.begin();           // join i2c bus (address optional for master)
  //Wire.beginTransmission(i2c_eaDIP);  // transmit to device #0xDE
  command1();
  //Serial.println( Wire.endTransmission(), DEC);     // stop transmitting

  delay(100);
 }

void loop()
{
}

void command1(){
  Wire.beginTransmission(i2c_eaDIP);
  Serial.println("***************************");
  Wire.write((byte)17);   // <DC1>
  Serial.println((byte)17);
  Wire.write((byte)11);   // len
  Serial.println((byte)11);
  Wire.write((byte)27);   // ESC
  Serial.println((byte)27);
  Wire.write((byte)71);
  Serial.println((byte)71);
  Wire.write((byte)68);
  Serial.println((byte)68);
  Wire.write((byte)00);
  Serial.println((byte)00);
  Wire.write((byte)00);
  Serial.println((byte)00);
  Wire.write((byte)00);
  Serial.println((byte)00);
  Wire.write((byte)00);
  Serial.println((byte)00);
  Wire.write((byte)223);
  Serial.println((byte)223);
  Wire.write((byte)01);
  Serial.println((byte)01);
  Wire.write((byte)15);
  Serial.println((byte)15);
  Wire.write((byte)01);
  Serial.println((byte)01);
  bcc = ( 17 + 11 + 27 + 71 + 68 + 00 + 00 + 223 + 01 + 15 + 01 ) % 0x100;
  Wire.write(bcc);
  Serial.println(bcc);
  Serial.println( Wire.endTransmission(), DEC);
 
  Wire.beginTransmission(i2c_eaDIP);
  Wire.write((byte)17);   // <DC1>
  Serial.println((byte)17);
  Wire.write((byte)3);   // len
  Serial.println((byte)3);
  Wire.write((byte)27);   // ESC
  Serial.println((byte)27);
  Wire.write((byte)68);
  Serial.println((byte)68);
  Wire.write((byte)76);
  Serial.println((byte)76);
  bcc = ( 17 + 3 + 27 + 68 + 76 ) % 0x100;
  Wire.write(bcc);
  Serial.println(bcc);
  Serial.println( Wire.endTransmission(), DEC);
  delay(100);
  Wire.requestFrom(0xDF, 1);
}

I output to the serial to see exactly what is being sent. Once I get this part to work I can complete a function that will automate this process.

Thanks for the help again.
Martin
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, wouldn't this be a lot easier? ...

Code:
const byte firstCommand [] = { 17, 11, 27, 71, 68, 0, 0, 0, 0, 223, 1, 15, 1 };

void command1(){
  Wire.beginTransmission(i2c_eaDIP);
  Wire.write (firstCommand, sizeof firstCommand);
  bcc = 0;
  for (byte i = 0; i < sizeof firstCommand; i++)
    bcc += firstCommand [i];
  Wire.write(bcc % 0x100);
  Serial.println( Wire.endTransmission(), DEC);

...

(I might not have copied all the numbers correctly, better check).

Anyway, what's the exact problem? You are only doing one Wire.request, so I would only expect one thing back.
Logged

San Juan, TX
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help.
The main problem I am having is that I would like to send multiple commands to the screen.
For example:
1.Clear the screen
2.Display a menu
3. Change the menu option selected
4. Change the screen once an option is selected.
...

I modified my code with what you suggested but it does the same thing. It only seems to execute the first command.
Code:
#include <Wire.h>
#define i2c_eaDIP ( 0xDE >> 1)       // Ba2|Ba1|Ba0|Sa2|Sa1|Sa0|R/W

byte bcc;       
const byte secondCommand [] = { 17, 03, 27, 68, 76};
const byte firstCommand [] = { 17, 11, 27, 71, 68, 0, 0, 0, 0, 223, 1, 15, 1 };

void setup()
{
  Serial.begin(9600);

  Wire.begin();           // join i2c bus (address optional for master)
  //Wire.beginTransmission(i2c_eaDIP);  // transmit to device #0xDE
  command1();
  command2();
  //Serial.println( Wire.endTransmission(), DEC);     // stop transmitting

  delay(100);

  //Wire.requestFrom(0xDF, 1);
  //Serial.println(Wire.available(), HEX);
  //Serial.println(Wire.read(), HEX);
 }
 
void loop()
{
}
 
void command1(){
  Wire.beginTransmission(i2c_eaDIP);
  Wire.write (firstCommand, sizeof firstCommand);
  bcc = 0;
  for (byte i = 0; i < sizeof firstCommand; i++)
    bcc += firstCommand [i];
  Wire.write(bcc % 0x100);
  Serial.println( Wire.endTransmission(), DEC);
  Wire.requestFrom(0xDF, 1);
}

void command2(){
  Wire.beginTransmission(i2c_eaDIP);
  Wire.write (secondCommand, sizeof secondCommand);
  bcc = 0;
  for (byte i = 0; i < sizeof secondCommand; i++)
    bcc += secondCommand [i];
  Wire.write(bcc % 0x100);
  Serial.println( Wire.endTransmission(), DEC);
  Wire.requestFrom(0xDF, 1);
}

I'm new in using I2C. How is a request submitted and executed and how does it get ready for the next command?
Or am I just going at this all wrong?

Thanks,
Martin
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why are you requesting stuff anyway? You aren't reading it.

I would expect something like:

Code:
void command1()
  {
  Wire.beginTransmission(i2c_eaDIP);
  Wire.write (firstCommand, sizeof firstCommand);

  // calculate sum check
  bcc = 0;
  for (byte i = 0; i < sizeof firstCommand; i++)
    bcc += firstCommand [i];

  // send sumcheck
  Wire.write(bcc % 0x100);

  // done
  if (Wire.endTransmission() != 0)
     return;   // error on send

  if (Wire.requestFrom(i2c_eaDIP, 1) != 1)
     return;   // nothing received

  byte foo = Wire.read ();

  // do something with foo here
}

BTW you request from, and send to, the same address. You didn't seem to be doing that.
Logged

San Juan, TX
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks much Nick,
That seems to do it. I put a Serial.println(foo); and I get the 6 that the documentation says it should be returning <ACK> for both commands. It clears the screen then draws the line, or if I flip them it draws the line then clears the screen.

BTW, I see what you mean about the
BTW you request from, and send to, the same address. You didn't seem to be doing that.
In the documentation under the I2C stuff it says
Quote
all pins open: Write $DE
Read $DF

I didn't know how this stuff works, so I assumed to read from it must get it from that address.

Thanks for the help, it is much appreciated.
-Martin
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the documentation under the I2C stuff it says ...

The Wire library does that for you. So you use the address shifted 1 bit to the right. Then the library puts the read/write bit in for you.
Logged

Pages: [1]   Go Up
Jump to: