2 iic object method: init(), 3 iic object method: readwrite(string, read_len) – Rainbow Electronics GM862-GPS User Manual
Page 47

Easy Script
in Python
80000ST10020a Rev.8 - 01/10/08
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved
page 47 of 100
This creates one IIC bus over the lines SDA=GPIO3 and SCL=GPIO4 with default address 0x50. If no
address defined, the address anyway can be feed with the readwrite() function as first part of the
string.
NOTE: available pins for the IIC bus are GPIO1 - GPIO13. The only exception is the module family
GM862 where available pins are GPIO2 - GPIO13 where GPIO2 must be used only for output.
2.8.2 IIC object method: init()
This command does the first pin initialisation on the IIC bus previously created. It has no input
parameter. Return value is a Python integer that is -1 if an error occurred otherwise is 1.
Example:
status = myIIC1.init()
2.8.3 IIC object method: readwrite(string, read_len)
16
This command can send a string or receive a string of read_len bytes from from IIC bus device at
address addr. First input parameter string is Python character while the second parameter read_len is
a Python integer used in process of reading data from the IIC bus and can assume values in the range
from 0 to 254.
Return value is a Python string which contains received data.
Example of use:
#start of I2C example for a particular I2C device
import IIC
import MOD
I2C_SCL = 12 # GPIO used for SCL pin
I2C_SDA = 4 # GPIO used for SDA pin
I2C_ADDR = 0x50 # myIIC1 address
NUM_REGS = 8 # max # of registers
myIIC1 = IIC.new(I2C_SDA, I2C_SCL, I2C_ADDR)
status = myIIC1.init()
#MOD.sleep(5)
print ' Writing from ADDR = 0x08, DATA = "Telit" '
if myIIC1.readwrite('\x08'+'Telit',0) == -1:
print 'Error acknowledged'
#MOD.sleep(5)
16
NOTE: it is not possible to perform at the same time reading and writing of the string