Connecting Robot Electronics modules to the Propeller (PropSTICK) using the I2C Bus 

This example shows how to connect the LCD03 module to the Propeller, and provides the source code for other modules at the bottom of the page. The LCD03 is used in I2C mode, I2C mode is selected by removing the link on the 2 pin header on the LCD03 module. The PropSTICK we used also provides a regulator for the 3.3V required by the Propeller and an RS232 interface to the PC. A schematic of the PropSTICK is available here: PropStick-v1.2.pdf

Circuit Schematic for connecting the PropSTICK to the I2C bus


Diagram shows How to connect the PropSTICK for use with The I2C examples on this page. Note 5V supplied to the PropSTICK is regulated to 3.3V for the Propeller chip by a regulator mounted underneath the chip.

The I2C example uses the pull up resistors for positive output by setting the tri-states to input, the only output that is needed from the propeller is to pull down the voltage to ground.  

Software for  Propeller

The following code is for the Propeller to control an LCD03 and requires the below functions from our simplified i2cObject.spin 

Init (SDA line, SCL line) - sets up the SCL and SDA pins 
readLocation( address, register, data ) - READ from a single specified register
writeLocation( address, register, data ) - WRITE to a single specified register

'* Controlling The LCD03 using the Parallax Propeller   *
'* Written by C Clarke                                  *
'* 16/02/2007                                           *

   _clkfreq = 5_000_000                  '5mhz xtal
   _CLKMODE = xtal1 + pll16x             'phase lock loop to multiply clock to 80mhz (5mhz*16)

   i2cSCLLine = 13                       'SCL is on Propeller pin A13
   i2cSDALine = 12                       'SDA is on Propeller pin A12
   LCD03_Addr = $c6                      'LCD03 address (default) at 0xC6
   LCD03_CMD_REG = 0
   LCD03_KEYL_REG = 1
   LCD03_KEYH_REG = 2
   LCD03_VER_REG = 3

   i2cObject : "i2cObject"               'include the I2C handler 
   Num : "numbers"                       'number handler allows keypad states to be formatted as ascii text string
                                         'note numbers is an object file included in installation directory
   byte version,keyl,keyh,length 

pub main

   Num.init                                                         'required to be called before using Num.ToStr function 
   i2cObject.init(i2cSDALine,i2cSCLLine)                            'pin numbers of the sda and scl lines to i2cobject
   i2cObject.Writelocation(LCD03_Addr,LCD03_CMD_REG,12)             'command of 12 to LCD03 to clear screen
   i2cObject.Writelocation(LCD03_Addr,LCD03_CMD_REG,4)              'command of 4 to LCD03 to hide cursor
   i2cObject.Writelocation(LCD03_Addr,LCD03_CMD_REG,19)             'command of 19 to LCD03 to turn backlight on 
      i2cObject.Writelocation(LCD03_Addr,0,1)                       'home position for cursor command
      outputString(string("LCD03 WITH PROPELLER"))                  'string() makes string, and passes pointer to outputstring()
      outputString(string("SOFTWARE VERSION"))
      version := i2cObject.readLocation(LCD03_Addr,LCD03_VER_REG)   'LCD03 version in register 3
      outputString(Num.ToStr(version, NUM#dec2))                    'write version to lcd03 display
      keyl := i2cObject.readLocation(LCD03_Addr,LCD03_KEYL_REG)     'LCD03 keyl in register 1
      keyh := i2cObject.readLocation(LCD03_Addr,LCD03_KEYH_REG)     'LCD03 keyh in register 2
      outputString(string(" ")) 
      outputString(string(" KEYSL ="))
      outputString(Num.ToStr(keyl, NUM#BIN9))                       'print keyl in binary 
      outputString(string("   "))                                   'just space to finish line
      outputString(string(" KEYSH ="))
      outputString(Num.ToStr(keyh, NUM#BIN9))                       'print keyh in binary 

      waitcnt(5_000_000 + cnt)                                      'just a delay

PUB OutputString(str_addr)                                          'passed pointer by string() in main to ascii byte string
   repeat strsize(str_addr)                                         'repeat for string length calculated by strsize
      i2cObject.Writelocation(LCD03_Addr,LCD03_CMD_REG,byte[str_addr++])       'send string bytes to LCD03 

Examples available for download

i2cobject.spin       - control any Devantech I2C module from your propeller using these functions
lcd03.spin             - the example above available as a .spin file
md23simple.spin   - a simple program that reads the md23 encoders and reverses the motors after a count is reached
md23.spin             - an example of a md23 and a lcd03 on the i2c bus
srf08.spin              - displays range and light sensor data from an srf08