hello,
Is it necessary to have in python IIC.py library like GPS.py to use iic function in module. I already have GPS ,SER, MDM ,… byt can’t find IIC and SPI . If Yes from where can I find it ?
hello,
Is it necessary to have in python IIC.py library like GPS.py to use iic function in module. I already have GPS ,SER, MDM ,… byt can’t find IIC and SPI . If Yes from where can I find it ?
This is from Telit_Easy_Script_Python_r12.pdf. You can find this near the bottom of the page at
http://www.telit.com/en/products/gsm-gp … =show&p=47
"3.8. IIC built-in module
IIC built-in module is an implementation on the Python core of the IIC bus
You need to use IIC built-in module if you want to create one or more IIC bus on the available GPIO pins. This IIC bus handling module is mapped on creation on two GPIO pins that will become the Serial Data and Serial Clock pins of the bus. It can be created more than one IIC bus over different pins and the pins used must not be used for other purposes."
So yes, you should need an “import IIC” in your script.
I have been able to get data back on my SFE GE865 eval board from ‘AT#I2CRD=7,6,91,0,2’ on a TMP102 connected to GPIO 7 (sda) and GPIO 6 (sck), and ADDR connected to GND. This was done from an Arduino and through RSTERM and TeraTerm, and was also captured with an MSO-19. I haven’t gotten data back from an AT command in a pyhton script yet, so sometime this week I’ll try the IIC.readwrite and see if my foo is any better.
Hi,
As stated above, the IIC library is built in, but must be imported by your module. I had a pretty awful time getting the IIC to talk to a NXP PCA9555 i/o expander. I finally got this to work:
import IIC
SDA_pin=13 #initialize IIC bus on GPIO 13 and 5
SCL_pin=5
IICbus=IIC.new(SDA_pin,SCL_pin)
status=IICbus.init() #returns 1 for success, -1 for fail
busmessage=‘\x40’+‘\x6’+‘\xF’+‘\x0’ #sets pins 1-4 to input and 5 to 17 to output (00001111,00000000)
status=IICbus.send(busmessage) #initializes registers
busmessage=‘\x40’+‘\x2’+‘\xF0’+‘\xFF’
status=IICbus.send(busmessage) #turns off all outputs (11110000,11111111
#print 'turn off outputs result = ’
def readport():
readresult=0
busmessage=‘\x40’+‘\x0’
status=IICbus.send(busmessage) #reads ports
readresult=IICbus.dev_read(64,2)
portval=ord(readresult[0])
return readresult
def sendmessage(ledstatus):
busmessage=‘\x40’+‘\x2’+chr(int(ledstatus[0],16))+chr(int(ledstatus[1],16))
status=IICbus.send(busmessage)
return ledstatus
I had forgotten about this thread, but I finally got the AT command to return data from an I2C device (TMP102) as well as iic.readwrite command. I have attached a module that uses Telit’s iic and can be called to return the whole and fractional degF temperature value. I’d prefer if the Telit device could do floating point math to get rid of the divmod.
So YES, you must import iic, it is built in, so the import iic command is sufficient in your code to then use iic commands.
The line to call the module is:
(t_whole, t_frac_whole) = TMP102.TMP102_degF() # Call Module TMP102_degF in TMP102.py to measure and report temperature
def TMP102_degF():
"""Polls TMP102 and returns temperature value"""
import IIC
import SER2
#global t_whole
#global t_frac_whole
#a = SER2.send('In TMP102 Module') #debug
#SER2.send('Initialize GPIO pins\r\n')
I2C_SDA = 7 # GPIO used for SDA pin
I2C_SCL = 6 # GPIO used for SCL pin
I2C_ADDR = 0x48 # TMP_102 address ADD0 pin to ground
TMP102 = IIC.new(I2C_SDA, I2C_SCL, I2C_ADDR)
status = TMP102.init() # Initialize TMP102 sensor on GPIO
if (status == 1):
tmploop = 2
while (tmploop > 0):
ret = TMP102.readwrite('\x00', 2) # Read 2 bytes from Temperature register
ret1 = ord(ret[0:1]) # Assign 1st byte to ret1
ret2 = ord(ret[1:2]) >> 4 # Assign 2nd byte to ret2 and bitshift right 4
calc = 288 * ret1 + 18 * ret2 + 5120 # Convert from degC to degF * 160 to use only integers
#SER2.send(str(calc) + ' calc\r\n') #debug
tval = divmod(calc, 160) # Find whole# and remainder
t_whole = int(str(tval)[1:str(tval).find(',')]) # Extract whole number as integer
t_frac = int(str(tval)[str(tval).find(' '):str(tval).find(')')]) # Extract fraction as integer
t_frac_divmod = divmod( t_frac * 100, 160) # Calculate fraction as integer with 2 decimal precision * 100
t_frac_whole = int(str(t_frac_divmod)[1:str(t_frac_divmod).find(',')]) # Extract fractional portion of temperature
if (ret == -1): # Check to see if ERROR returned from Read of TMP102
a = SER2.send('readwrite Error Acknowledged.\r\n')
tmploop = tmploop - 1
if (tmploop == 0):
a = SER2.send('Temperature reading failed\r\n')
return
else: # If no ERROR,
#a = SER2.send('Temperature is ' + str(t_whole) + '.' + str(t_frac_whole) + 'F\r\n')
return (t_whole, t_frac_whole)
if (status == -1):
a = SER2.send('TMP102 initialization failed.\r\n')
return (None, None)
This isn’t pretty, but given that there are only 16 possible fractional strings, you could do this::
fractionStrings = ['.0', '.0625', '.125', '.1875', '.25', '.3125', '.375', '.4375', '.5', '.5625', '.625', '.6875', '.75', '.8125', '.875', '.9375']
...
SER2.send('Temperature is ' + str(t_whole) + '.' + fractionStrings[t_frac_whole]...
Congratulations on getting that to work, I went through some pain getting a telit to talk to a string of TMP100s.
Hi, LAWERNCEADUNN - I am doing a similar project using the same 16 port expander as you used (still choosing components, have not built a prototype as of yet) Mind if I ask what format did your input return from the iic bus as (i.e. int, string, tupple)? I didn’t see a to binary conversion/ functionality in the Python 1.52 and was wondering how you got/ processed your results (readresult) (i.e. how you knew which inputs had been set etc.).