PDA

View Full Version : Thermal sensor help



sthmck
06-16-2008, 12:55 PM
Hey,
I want to use a devantech thermal array sensor with a basic stamp 2pe, but I am having some problems. I know what pins to connect to on the stamp (pin 8 is SDA and pin 9 is SCL). I havent done anything with I2C before so I dont have a cool how to write a program for the basic stamp to input values. Does anyone have any experience with this sensor controller combination? I could sure use the help.

Adrenalynn
06-16-2008, 01:47 PM
Whatcha tryin' to detect with it? Is it for a firefighting 'bot (in which case, I'd probably build a sliding window and "remember" the highest temperatures I've seen as a threshold), or are you trying to find people (I'd be looking for 20-29deg C), or something else cool?

According to the spec sheet, it provides 10 registers that contain:

Register 0, Software Rev
Reg 1 Ambient Temp Deg C
Reg 2 Pixel 1 Deg C
Reg 3 Pixel 2 Deg C
Reg 4 Pixel 3 Deg C
[...]
Reg 9 Pixel 8 Deg C

You know how to hook up the hardware, right? Remember your pullup resistors.

Onward to the most basic of coding and then we can discuss your use of it if it's not enough of a hint.

I don't have a Basic Stamp handy, but something like this should about do the job of simply demonstrating how to capture the data from it:



SDA CON 8 'Serial Data [SDA] is on pin 13, Serial Clock [SCL] is on pin 14
Ver VAR Byte ' Version information is in the first byte
Am_C VAR Byte ' Ambient Temperature in Deg C is in second byte
P1 VAR Byte ' Pixel Temps Follow in Deg C
P2 VAR Byte
P3 VAR Byte
P4 VAR Byte
P5 VAR Byte
P6 VAR Byte
P7 VAR Byte
P8 VAR Byte
'A tight loop displaying the registers to the PC debugger console as fast as we can.
DispLoop:
I2CIN SDA, $d1, 0, [Ver, Am_C, P1, P2, P3, P4, P5, P6, P7, P8 ]
DEBUG 2,0,2, "Rev", DEC Ver, " "
DEBUG 2,0,3, "Ambient C", DEC Am_C, " "
DEBUG 2,0,4, "P1 P2 P3 P4 P5 P6 P7 P8"
DEBUG 2,0,5, DEC3 P1, " ", DEC3 P2, " ", DEC3 P3, " ", DEC3 P4, " ", DEC3 P5, " ", DEC3 P6, " ", DEC3 P7, " ", DEC3 P8
GOTO DispLoop

sthmck
06-17-2008, 09:17 AM
hey thanks for the help. I am going to be using it to detect a flame. At this point though I am just interested in returning values to see how the sensor reacts. I tried the code, but it just returns a values of 255 for every pixel. here is the output.

255 255 255 255 255 255 255 255
Rev255
Ambient C255
P1 P2 P3 P4 P5 P6 P7 P8

Adrenalynn
06-17-2008, 01:42 PM
Huh. The registers are uninitialized...

Can you post a diagram of how it's hooked-up, make sure it's spitting data out at all?

I have a slightly different one here, optimized for human body heat, but I actually don't have a working BASIC Stamp - which is bizarre given my obsession with microcontrollers. ;) I'm reading my from a SAM7 right now, but have also used the ATMega. I just got a spiffy Atmel AVR programmer the other day, so I'll probably be moving it over to something like the socket3300 series...

Anywho - let's check-out your connections, then try to debug code.

robot maker
07-19-2008, 07:06 PM
here is a test program for bs2,since i have one and doing some testing on tpa81 and cmps-03 for my robots
'************************************************* **********
'** **
'** I2C Routines for the Basic Stamp BS2/BS2e/BS2sx **
'** with the TPA81 Thermal sensor module **
'** **
'** Copyright 2006 - Devantech Ltd **
'** Commercial use of this software is prohibited **
'** Private and educational use only is permitted **
'** **
'** Written by Gerald Coe - March 2006 **
'** **
'************************************************* **********

' Connect P8 (pin13) of the BS2 to the TPA81 SDA
' Connect P9 (pin14) of the BS2 to the TPA81 SCL
' Use 4k7 pull-up resistors from SCL and SDA to 5v supply
SDA CON 8 ' I2C data
SCL CON 9 ' I2C clock
SDAin VAR IN8
SDAout VAR OUT8
SDAdir VAR DIR8
Ver VAR Byte
Ambient VAR Byte
Pix1 VAR Byte
Pix2 VAR Byte
Pix3 VAR Byte
Pix4 VAR Byte
Pix5 VAR Byte
Pix6 VAR Byte
Pix7 VAR Byte
Pix8 VAR Byte
I2cBuf VAR Byte ' I2c read/write buffer
I2cAddr VAR Byte ' Address of I2C device
I2cReg VAR Byte ' Register number within I2C device
I2cData VAR Word ' Data to read/write
I2cAck VAR Bit ' Acknowledge bit
DEBUG 2,0,1, "BS2/BS2e/BS2sx - TPA81 Demonstration "
DEBUG 2,0,2, "Firmware Version "
DEBUG 2,0,3, "Ambient "
DEBUG 2,0,4, "Pix1 Pix2 Pix3 Pix4 Pix5 Pix6 Pix7 Pix8"
I2cAddr = $D0
I2cReg = 0
MainLoop:
GOSUB I2cTPA81Read ' read data from TPA81
DEBUG 2,17,2, DEC Ver, " "
DEBUG 2,8,3, DEC Ambient, " "
DEBUG 2,0,5, DEC3 Pix1, " ", DEC3 Pix2, " ", DEC3 Pix3, " ", DEC3 Pix4, " ", DEC3 Pix5, " ", DEC3 Pix6, " ", DEC3 Pix7, " ", DEC3 Pix8
GOTO MainLoop

'--------------------------------------------------------------------------------------------
' I2C subroutines follow
'--------------------------------------------------------------------------------------------
I2cTPA81Read:
I2cAck = 1 ' send Ack
GOSUB I2cStart
I2cBuf = I2cAddr
GOSUB I2cOutByte ' send device address
I2cBuf = I2cReg
GOSUB I2cOutByte ' send register number
GOSUB I2cStart ' repeated start
I2cBuf = I2cAddr | 1
I2cAck = 1 ' send Ack
GOSUB I2cOutByte ' send device address (with read set)
GOSUB I2cInByte
Ver = I2cBuf ' read the data
GOSUB I2cInByte
Ambient = I2cBuf
GOSUB I2cInByte
Pix1 = I2cBuf
GOSUB I2cInByte
Pix2 = I2cBuf
GOSUB I2cInByte
Pix3 = I2cBuf
GOSUB I2cInByte
Pix4 = I2cBuf
GOSUB I2cInByte
Pix5 = I2cBuf
GOSUB I2cInByte
Pix6 = I2cBuf
GOSUB I2cInByte
Pix7 = I2cBuf
I2cAck = 0 ' send Nak
GOSUB I2cInByte
Pix8 = I2cBuf
GOSUB I2cStop
RETURN

I2cByteWrite: ' writes I2cData.lowbyte to I2cReg at I2cAddr
GOSUB I2cStart
I2cBuf = I2cAddr
GOSUB I2cOutByte ' send device address
I2cBuf = I2cReg
GOSUB I2cOutByte ' send register number
I2cBuf = I2cData.LOWBYTE
GOSUB I2cOutByte ' send the data
GOSUB I2cStop
RETURN

I2cWordWrite: ' writes I2cData to I2cReg at I2cAddr
GOSUB I2cStart
I2cBuf = I2cAddr
GOSUB I2cOutByte ' send device address
I2cBuf = I2cReg
GOSUB I2cOutByte ' send register number
I2cBuf = I2cData.HIGHBYTE
GOSUB I2cOutByte ' send the data - high byte
I2cBuf = I2cData.LOWBYTE
GOSUB I2cOutByte ' send the data - low byte
GOSUB I2cStop
RETURN

I2CByteRead:
GOSUB I2cStart
I2cBuf = I2cAddr
GOSUB I2cOutByte ' send device address
I2cBuf = I2cReg
GOSUB I2cOutByte ' send register number
GOSUB I2cStart ' repeated start
I2cBuf = I2cAddr | 1
GOSUB I2cOutByte ' send device address (with read set)
I2cAck = 0 ' send Nak
GOSUB I2cInByte
I2cData.LOWBYTE = I2cBuf ' read the data
I2cData.HIGHBYTE = 0
GOSUB I2cStop
RETURN

I2CWordRead:
GOSUB I2cStart
I2cBuf = I2cAddr
GOSUB I2cOutByte ' send device address
I2cBuf = I2cReg
GOSUB I2cOutByte ' send register number
GOSUB I2cStart ' repeated start
I2cBuf = I2cAddr | 1
I2cAck = 1 ' send Ack
GOSUB I2cOutByte ' send device address (with read set)
GOSUB I2cInByte
I2cData.HIGHBYTE = I2cBuf ' read the data
I2cAck = 0 ' send Nak
GOSUB I2cInByte
I2cData.LOWBYTE = I2cBuf
GOSUB I2cStop
RETURN

I2cOutByte:
SHIFTOUT SDA, SCL, MSBFIRST, [I2cBuf]
INPUT SDA
HIGH SCL ' clock in the ack' bit
LOW SCL
RETURN

I2cInByte:
SHIFTIN SDA, SCL, MSBPRE, [I2cBuf]
SDAout = 0
SDAdir = I2cAck
HIGH SCL ' clock out the ack' bit
LOW SCL
INPUT SDA
RETURN

I2cStart ' I2C start bit sequence
HIGH SDA
HIGH SCL
LOW SDA
LOW SCL
RETURN

I2cStop: ' I2C stop bit sequence
LOW SDA
HIGH SCL
HIGH SDA
RETURN

robot maker
07-19-2008, 07:15 PM
what is the model of of the sensor you are using (eltec) or another type


Huh. The registers are uninitialized...

Can you post a diagram of how it's hooked-up, make sure it's spitting data out at all?

I have a slightly different one here, optimized for human body heat, but I actually don't have a working BASIC Stamp - which is bizarre given my obsession with microcontrollers. ;) I'm reading my from a SAM7 right now, but have also used the ATMega. I just got a spiffy Atmel AVR programmer the other day, so I'll probably be moving it over to something like the socket3300 series...

Anywho - let's check-out your connections, then try to debug code.

robot maker
07-21-2008, 09:51 AM
here is a test program for bs2




hey thanks for the help. I am going to be using it to detect a flame. At this point though I am just interested in returning values to see how the sensor reacts. I tried the code, but it just returns a values of 255 for every pixel. here is the output.

255 255 255 255 255 255 255 255
Rev255
Ambient C255
P1 P2 P3 P4 P5 P6 P7 P8

Adrenalynn
07-21-2008, 11:45 AM
here is a test program for bs2

Where?

And do you see a problem with mine?

robot maker
07-21-2008, 10:24 PM
no why, sorry post it twice


Where?

And do you see a problem with mine?