Adapting graphical LCD with touch screen to ChipKIT UNO32

ChipKIT is a great substitution board to Arduino. It offers better performance as it is based on PIC32MX320F128 microcontroller based on 32-bit architecture. Microcontroller has 128K of Flash and 16K of SRAM on board. Having Arduino Uno shape factor ChipKIT offers more 42 programmable pins.

chipKIT-Uno32

ChipKIT like Arduino can be programmed with bootloader that communicates to PC through USB-to-USART converter chip FT232RQ. Digilent has developed an STK500v2 based bootloader that works on PIC so it is easy to program using AVRDUDE tool. Besides that they adapted an Arduino envoronemt to work with ChipKIT boards. It’s called Mpide. It also support Arduino boards but it aim is to program ChipKIT boards. Progamming experience is pretty same as for Arduino and even most of examples written for Arduino works on ChipKIT. This is true since there is no specific hardware elements touched like program memory or EEPROM. As you know Arduino is rich in hardware support libraries as all shields are designed for arduino. Late comers like ChipKIT even if they are hardware compatible may have some difficulties with library integration due to different architecture.

But with little bit effort you can make everything work.

Today I am going to try to run ITDB02 LCD module shield from iteadstudio.com.

ITDB02_Arduino_Shield

IT is basically an adapter for graphical color LCD with touchscreen/SD. Note! Touch screen and SC cannot work simultaneously due to shortage of pins. Anyway a little hack on ChipKIT would solve this problem. Lets see what is a starting point. Henning Karlsen has nice written libraries for Arduino and even for ChipKIT. But this library won’t work with ITDB02 shield as decided not to support this shield due to performance loss. Also he claims that this shield is not optimized for 3.3V power supply as there are resistors included. Instead he offers to make custom cable for interfacing LCD or use another shield for ChipKIT. I understand that move. If we look at ChipKIT pin layout we can clearly see that Arduino compatible pins aren’t bit aligned as it is in Arduino:

chipKIT_Uno32_Pin_Mapping

In Arduino digital pins D7..D0 are all PORTD pins. So they can controlled with PORTD command that gives significant increase of performance comparing to individual digitalwrite() commands. ChipKIT as you can see have these pins scattered and cannot be controlled with port commands. Instead you can see inner pins of header being aligned [RE0..RE7]. This is why another shield is offered that allow controlling LCD data pins with single command. Anyway I already have my ITDB02 shield on my table and want to make it work on ChipKIT. As starting point I’ve chosen to muck around with Arduino library due to same pin connectivity.

The main problem with controlling LCD that we cannot use port commands here as port pins aren’t aligned. To solve this I have written simple function that takes data byte and scatters them to d0..d7 pins according to layout:

void ITDB02::byteD0D7(unsigned char data)
{
  //ChipKIT pins DR9|RD2|RD1|RF1|RD0|RD8|RF3|RF2
  if((data)&(0b10000000)) digitalWrite(7, HIGH);
    else digitalWrite(7, LOW);
  if((data)&(0b01000000)) digitalWrite(6, HIGH);
    else digitalWrite(6, LOW);
  if((data)&(0b00100000)) digitalWrite(5, HIGH);
    else digitalWrite(5, LOW);
  if((data)&(0b00010000)) digitalWrite(4, HIGH);
    else digitalWrite(4, LOW);
  if((data)&(0b00001000)) digitalWrite(3, HIGH);
    else digitalWrite(3, LOW);
  if((data)&(0b00000100)) digitalWrite(2, HIGH);
    else digitalWrite(2, LOW);
  if((data)&(0b00000010)) digitalWrite(1, HIGH);
    else digitalWrite(1, LOW);
  if((data)&(0b00000001)) digitalWrite(0, HIGH);
    else digitalWrite(0, LOW);
}

This is the bottleneck of performance as each individual pin has to be set individually (read modify write operation), while in Arduino there were PORTD = VH; Anyway this workaround works. Also I’ve changed control pin manipulation with digitalWrite() commands. And surely as as all font/image arrays are stored in SRAM there is no need for pgm_read_byte() commands. Simply we replaced with array read statements.

Arduino based Touchscreen library works on ChipKIT out of box, so no modifications are needed.

Here are few images of working LCD:

ITDB02_Graph_Buttns

ITDB02_Graph_demo3__chipkit_fonts

ITDB02_Graph_demo3_chipkit_icons

Next logical step would be to adapt library for SD card. But this will be next time.

Download project files: ITDB02_Shield_ChipKIT

4 Comments:

  1. The μLCD-32PT(SGC) 3.2” Serial LCD Display Module by 4D Systems is a true marvel, with it’s dedicated graphic processor. It uses the Serial1 port of the chipKIT UNO32 board (pins 39 and 40). Please find the full library at http://sites.google.com/site/vilorei/arduino/13–serial-touch-320×240-lcd-screen

  2. I’m getting the same errors from Henning Karlsen’s libraries as from your library. I’m not sure where to start, so I was hoping for some advice, included are the errors:

    ITDB02_Graph_ChipKIT.cpp:64:21: error: ‘uint16_t gamma [10][2]’ redeclared as different kind of symbol
    c:\documents and settings\slinker\my documents\downloads\mpide-0023-windows-20120903\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/math.h:273:15: error: previous declaration of ‘double gamma(double)’
    ITDB02_Graph_ChipKIT.cpp: In member function ‘void ITDB02::InitLCD(byte)’:
    ITDB02_Graph_ChipKIT.cpp:176:46: error: invalid conversion from ‘double (*)(double)’ to ‘int’
    ITDB02_Graph_ChipKIT.cpp:176:46: error: initializing argument 2 of ‘void ITDB02::main_W_com_data(char, int)’
    ITDB02_Graph_ChipKIT.cpp:177:46: error: invalid conversion from ‘double (*)(double)’ to ‘int’
    ITDB02_Graph_ChipKIT.cpp:177:46: error: initializing argument 2 of ‘void ITDB02::main_W_com_data(char, int)’
    ITDB02_Graph_ChipKIT.cpp:178:46: error: invalid conversion from ‘double (*)(double)’ to ‘int’
    ITDB02_Graph_ChipKIT.cpp:178:46: error: initializing argument 2 of ‘void ITDB02::main_W_com_data(char, int)’
    ITDB02_Graph_ChipKIT.cpp:179:46: error: invalid conversion from ‘double (*)(double)’ to ‘int’
    ITDB02_Graph_ChipKIT.cpp:179:46: error: initializing argument 2 of ‘void ITDB02::main_W_com_data(char, int)’
    ITDB02_Graph_ChipKIT.cpp:180:46: error: invalid conversion from ‘double (*)(double)’ to ‘int’
    ITDB02_Graph_ChipKIT.cpp:180:46: error: initializing argument 2 of ‘void ITDB02::main_W_com_data(char, int)’
    ITDB02_Graph_ChipKIT.cpp:181:46: error: invalid conversion from ‘double (*)(double)’ to ‘int’
    ITDB02_Graph_ChipKIT.cpp:181:46: error: initializing argument 2 of ‘void ITDB02::main_W_com_data(char, int)’
    ITDB02_Graph_ChipKIT.cpp:182:46: error: invalid conversion from ‘double (*)(double)’ to ‘int’
    ITDB02_Graph_ChipKIT.cpp:182:46: error: initializing argument 2 of ‘void ITDB02::main_W_com_data(char, int)’
    ITDB02_Graph_ChipKIT.cpp:183:46: error: invalid conversion from ‘double (*)(double)’ to ‘int’
    ITDB02_Graph_ChipKIT.cpp:183:46: error: initializing argument 2 of ‘void ITDB02::main_W_com_data(char, int)’
    ITDB02_Graph_ChipKIT.cpp:184:46: error: invalid conversion from ‘double (*)(double)’ to ‘int’
    ITDB02_Graph_ChipKIT.cpp:184:46: error: initializing argument 2 of ‘void ITDB02::main_W_com_data(char, int)’
    ITDB02_Graph_ChipKIT.cpp:185:46: error: invalid conversion from ‘double (*)(double)’ to ‘int’
    ITDB02_Graph_ChipKIT.cpp:185:46: error: initializing argument 2 of ‘void ITDB02::main_W_com_data(char, int)’

    Any suggestion? I have the mpide-0023-windows-20120903 btw

  3. this issue can be resolved by changing the variable name ‘gamma’ to some other variable name.

    in ITDB02_Graph_ChipKIT.cpp:64:21 change

    ‘uint16_t gamma [10][2]’ to ‘uint16_t gamma2 [10][2]’
    change all other instances of ‘gamma’ to ‘gamma2’ in the ITDB02_Graph_ChipKIT.cpp file.

  4. I’m getting the same errors as shown in the comment above. I am assuming that there has been a fix for the gamma issue.

    can anyone help with this problem?

Leave a Reply

Your email address will not be published. Required fields are marked *