FT800Calibrate

The FT800 chip (as used on the Gameduino and FTDI VM800B43A module) has a resistive touchscreen which enables a user to interact with your application but touching the screen. However, before they can do that, the screen needs to be calibrated so that the FT800 can correctly map a physical point on the screen to an internal x,y value. Calibrating the screen just requires a single line of code:

Ft.SelfCalibrate()

which will start the internal FT800 calibration sequence. This involves displaying three dots on the screen which the user presses in turn. Once this has been done, the screen is ready to use for touch. And that's it! Well, almost...

Unfortunately, when the display is powered down, the calibration settings are lost. The FT800 cannot save the calibration values. The application must save the settings to some form of non-volatile RAM, like EEPROM. However, many PIC24 devices (like the one used in Firewing for PIC24) does not have any internal EEPROM! This means an external EEPROM device must be used.

Or does it? Luckily, we can use the microcontrollers own internal FLASH memory to save the calibration settings, removing the need for external EEPROM. To do this, just include the "ROM" module at the top of your program, which will enable you to read and write word values to internal FLASH. The following listing is the complete code needed to calibrate and save your display settings. The first time the program is executed, the calibration screen is displayed. After you have finished calibrating, power down and then power up. The screen will then display "FT800 is calibrated".

#option FT_MODEL = GAMEDUINO      ' enable for Gameduino 2
imports Ft800                     ' import FT800
imports Rom                       ' import ROM module

' this flag is set or cleared, depending on the calibration
' state...
dim IsCalibrated as boolean = false

' save all calibration settings...
sub SaveCalibration()
   dim address as ushort = 0
   WriteWord(address, &H1234)
   for index as byte = 0 to 23  
      dim reg as byte = Ft.rd8(REG_TOUCH_TRANSFORM_A + index)
      address += 1
      WriteWord(address, reg)
   next
end sub

' restore all calibration settings...      
sub LoadCalibration()
   dim address as ushort = 0
   dim val as ushort = ReadWord(address)
   if val <> &H1234 then
      IsCalibrated = false
   else
      IsCalibrated = true
      for index as byte = 0 to 23 
         address += 1
         dim reg as byte = ReadWord(address)
         Ft.wr8(REG_TOUCH_TRANSFORM_A + index, reg)
      next        
   end if 
end sub

' program entry point...
sub main()
    LoadCalibration() 
    if IsCalibrated then  
       Ft.Clear()           
       Ft.cmd_text(240, 136, 29, OPT_CENTER, "FT800 is calibrated")  
       Ft.Swap() 
    else         
       Ft.SelfCalibrate()  
       SaveCalibration()
    end if
 end sub

Please note that calibration setting will change from display to display. If you plug in a new display (for example, a Gameduino after using a VM800B43A module) you should save the new settings to ROM by forcing a re-calibration:

Ft.SelfCalibrate()  
SaveCalibration()