Author Topic: Temperature Sensor  (Read 2124 times)

0 Members and 1 Guest are viewing this topic.

Offline bhsmithTopic starter

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 0
Temperature Sensor
« on: October 26, 2010, 09:29:11 AM »
I have a infrared temperature sensor that I want to connect to a touch screen.  Any way that I've tried to connect them and get a readout all I get is either a 1 or 255.  I know it uses PWM to get temperature readings.  I don't think I know how to set that up.  Here is what I have.

http://www.4dsystems.com.au/prod.php?id=116
http://www.sparkfun.com/commerce/product_info.php?products_id=9570

Any help is appreciated, Thanks!

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Temperature Sensor
« Reply #1 on: October 26, 2010, 12:58:49 PM »
This device has two different outputs:
1. PWM output. ie it keeps sending pulses where the width of the pulse equals the reading. If you are just reading the value of the pin then it could be random as to whether its currently high or low. Hence your 1 or 255 values. If you are using WebbotLib then it has function to measure the length of the incoming pulse.
2. An I2C output. Once again WebbotLib allows you to talk to I2C devices.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline bhsmithTopic starter

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 0
Re: Temperature Sensor
« Reply #2 on: October 26, 2010, 05:54:42 PM »
This device has two different outputs:
1. PWM output. ie it keeps sending pulses where the width of the pulse equals the reading. If you are just reading the value of the pin then it could be random as to whether its currently high or low. Hence your 1 or 255 values. If you are using WebbotLib then it has function to measure the length of the incoming pulse.
2. An I2C output. Once again WebbotLib allows you to talk to I2C devices.


I figure that way why I was getting those values, it was just reading the pin as high.  I'd gone through the programming language that it uses and haven't really found anything for PWM readings but it does support I2C.  Which is the only option I hadn't tried, of course.  I just didn't think that the sensor could communicate that way.  I'll try it out as soon as I can.  Thanks!!!

Offline bhsmithTopic starter

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 0
Re: Temperature Sensor
« Reply #3 on: October 28, 2010, 06:30:58 PM »
I've connected the sensor using the I2C and have made a little progress.  I can get an ack from the sensor and when I read from the buffer I get a constant 12 no matter what I do.  I've tried to read a byte and it always returns 0.  I'm not sure what to make of it.  Any suggestions?

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Temperature Sensor
« Reply #4 on: October 29, 2010, 05:38:30 PM »
What are you using to do the I2C. WebbotLib or something else?
A code example may help
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline bhsmithTopic starter

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 0
Re: Temperature Sensor
« Reply #5 on: October 29, 2010, 06:34:01 PM »
This is the code I am using.  Was trying a few different things to see what would happen.
Thanks!

#platform "uLCD-32032-P1_GFX2"

func main()
var readbyte,ack,size,i;//1000
var buffer[8];

print("Testing I2C component\n");

I2C_Open(1024);

I2C_Start();
pause(400);
ack:= I2C_AckStatus();//gets the status of the I2C device
print("Ack ",ack,"\n");
pause(1000);

readbyte:= I2C_Read();
print("Read Byte ",readbyte,"\n");  //This will display a 1
pause(400);

I2C_Gets(buffer,16);
pause(1000);
print(buffer);              //Prints 12
pause(1000);

I2C_Stop();
I2C_Close();

endfunc

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Temperature Sensor
« Reply #6 on: October 30, 2010, 09:51:26 AM »
Not sure about the syntax of the code library you are using.
But as an I2C communication it looks wrong. For example there is no slave I2C address (default is 0x5a according to data sheet) and there is no swap between write and read mode.
Look at some of the code examples in the comments section of the SparkFun link you give in your first post.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline bhsmithTopic starter

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 0
Re: Temperature Sensor
« Reply #7 on: November 03, 2010, 01:03:03 PM »
I'm still not having much luck with this.  I've found some other code examples but I still can't seem to get anything useful out of it.  Here is what I have along with the I2C functions for the programming language:

//Slave hex address is 0x5A
//Temperature address is 0x07
func main()
var true,temp,a;
var buffer[100];

print("Testing I2C component\n");
pause(1000);
I2C_Open(I2C_FAST);//1mhz
print("I2C Open\n");
I2C_Idle();
I2C_Start();
print("Started\n");
I2C_Write(0x07);
print("Write Complete\n");
I2C_Idle();
true:= I2C_Write(0x00);
print(true,"\n");       //Returns a 1
temp:= I2C_Read();
print(temp,"\n");       //Returns a 0

print(readbyte(0x5a),"\n");     //Returns a 0

pause(10000);

endfunc

func readbyte(var address)
var r;

    I2C_Idle();                        //Wait for bus Idle
    I2C_Start();                    //Generate Start condition
    I2C_Write(0x01);                //send control byte for write
    I2C_Idle();                        //Wait for bus Idle
    I2C_Write(HIbyte(address));        //Send High Address
    I2C_Idle();                        //Wait for bus Idle
    I2C_Write(LObyte(address));        //Send Low Address
    I2C_Idle();                        //Wait for bus Idle
    I2C_Restart();                    //Generate Restart
    I2C_Write(0x00);                //send control byte for Read
    I2C_Idle();                        //Wait for bus Idle
    r := I2C_Read();                //Read Length number of bytes to Data
    I2C_Nack();                        //send Not Ack
    I2C_Stop();                        //Send Stop Condition

    return r;

endfunc

//------------------------------//
//        I2C Functions           //
//------------------------------//
/*
I2C_Open("speed");              // Configure the I2C module, speed can be I2C_SLOW, I2C_MED, I2C_FAST (100khz, 400khz, 1mhz)
I2C_Close();                    // Disable the I2C1 module.
I2C_Start();                    // Generate a Start condition.
I2C_Stop();                     // Generate a Stop condition.
I2C_Restart();                  // Generate a Restart condition.
I2C_Read();                     // Read a single byte from the I2C Bus.
I2C_Write("byte");              // Write a byte to the I2C bus, Returns TRUE if ok
I2C_Ack();                      // Generate the acknowledge condition.
I2C_Nack();                     // Generate the negative acknowledge condition.
I2C_DataRdy();                  // Return TRUE if the I2C receive buffer is full.
I2C_Idle();                     // Wait until the I2C Bus is Inactive.
I2C_Gets("buffer", "length");   // Read length bytes from the I2C device to a buffer
I2C_Puts("buffer");             // Write an asciiz string to the I2C device
« Last Edit: November 04, 2010, 02:54:31 PM by bhsmith »

 


data_list