Temp & Humidity sensor interfacing question


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223

    Default Temp & Humidity sensor interfacing question

    Hi everyone, I got a Grove Temp & Humidity sensor....according to this link "http://www.seeedstudio.com/wiki/Grove-_Temperature_and_Humidity_Sensor" I need to send signal to trigger and should give 40 bits of data. From the attached image D1 is the communication line...please correct me if I'm wrong, All I need to do is send binary 1 to D1 and the 40 bits will coming out from the sensor? Hope anyone can give me a hint.... I'm planning to use Pic18F44550 and I'm using PBP2.60.thanks in advance,tacbanon
    Attached Images Attached Images  

  2. #2
    Join Date
    Apr 2008
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: Temp & Humidity sensor interfacing question

    Hello tacbanon

    What i read from the waveform is diferent than you.

    First the sensor has an internal pull up resistor so the idle state is 1

    then you must send a low pulse and release back to 1 (blue color)

    then the sensor places data line low for sometime then back to high for sometime

    and after that sends the 40 bits in a row

    from the waveform it seems that a zero is a short pulse and a 1 a long pulse ( Twice the width ? )

    the problem is that i don't see anyware the pulse duration nor for ack pulse or 0 and 1 pulse duration.

    In the past i found a sample code in proton basic to decode infrared sony protocol that i ported
    to picbasic pro.

    As far as i remenber it was based on a array with the proper number of elements
    and used pulsin in a loop to wait for a start pulse that was longer than the others


    after detecting the start pulse you enter another loop
    with a counter wait a cicle time , read the port and store 0 or 1 on each increasing array number

    this aproach is not wat you need here because the sony infrared protocol (as far as i remenber ) was fixed leght bits
    with 0 or 1

    Here you have to use pulsin in a loop to measure the width of the 40 positive incoming pulses and decide what to store on
    the array 0 or 1 based on that.

    Sorry for my english . If i have time i will search for that code and post it to see if it can help you.

  3. #3
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Temp & Humidity sensor interfacing question

    Hi Fernando,Thanks for the information and sharing your time. I will try your suggestion and post my results. This will be a challenge for me Thanks,Tacbanon

  4. #4
    Join Date
    Feb 2012
    Location
    Meico,D.F.
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Temp & Humidity sensor interfacing question

    '************************************************* ***************
    '* Name : RHT03Humedad y temperatura.BAS *
    '* Author : Leonardo Castillo *
    '* Notice : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 15/02/2012 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    'el maestro pone su linea como salida a nivel bajo por 1-10ms para que el sensor
    'se reinicie al detectar la presencia de el maestro, seguido se pone la linea a
    'nivel alto por 20-40us para esperar la respuesta del sensor. Transcurrido dicho
    'punto el maestro se configura como entradapara esperar la respuesta del sensor.
    'El sensor debe de poner la linea en nivel bajo por 80us como respuesta de la señal
    'detectada, despues pone la linea en alto por 80us como preparacion para el embio
    'de los datos (El sensor enbia 40 bits de datos de los cuales los primeros 16 corres-
    'ponden a el valor de la humedad relativa, los siguientes 16 bits corresponden a
    'la temperatura con signo, el bit 16 de el segundo dato corresponde al signo, un "0"
    'corresponde a un valor positivo y un "1" corresponde a un valor negativo. los dos
    'datos word deben de dividirse entre 10 para obtener la parte decimal de los
    'resultados. La temperatura negativa no esta en forma complelentaria sino en forma
    'normal.) . El formato de la señal de datos es la siguiente, un cero "0" se representa
    'con un nivel bajo de 50us seguido de un nivel alto de 26-28us, un uno "1" es repre-
    'sentado enbiando un nivel bajo de 50us seguido de un nivel alto de 70us. Tras el
    'envio de los 40 bits de datos el sensor pone la linea en nivel bajo y ya no cambia
    'con lo que el maestro interpreta el fin de el envio de datos por parte del sensor
    'con lo que el maestro es configurado como salida y al nivel alto.
    'Los intervalos de medicion deben ser mayores a 2 segundos.
    'pic 16F627A
    include "modedefs.bas"
    asm
    __config _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    endasm
    define osc 4
    ' Define LCD registros y bits
    Define LCD_DREG PORTB
    Define LCD_DBIT 4
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 2
    Define LCD_EREG PORTB
    Define LCD_EBIT 3
    'variables
    Humedad var word
    Temperatura var word
    Signo var byte
    Parcial var word
    CheckSum var byte
    Dato var word[3]
    Valor var byte
    i var byte
    j var byte
    symbol EntSal=PORTA.0
    Inicio:
    pause 500 ' pausa para reiniciar el LCD
    CMCON=7 ' modulo comparador off
    OPTION_REG=%00001000 'prescaler asignado al WDT 1:1 y ciclo de instruccion interna
    Lectura:
    output entsal ' configura pin como salida
    'TRISA.0=0
    low entsal ' pone pin a nivel bajo para que el sensor detecte su presencia
    'ENTSAL=0
    pause 10 ' pausa para que se reinicie el sensor por la presencia del micro
    high entsal ' se pone el pin a nivel alto para finalizar el reinicio del sensor
    'ENTSAL=1
    input entsal ' se configura el pin como entrada para esperar embio de datos
    'TRISA.0=1
    while entsal=0 ' el sensor pone baja la linea por 80us para preparar el embio
    wend ' de datos, entra en un ciclo hasta que la linea deja de ser 0
    while entsal=1 ' el sensor pone en alto la linea por 80us para preparar el embio
    wend ' de datos, entra en un ciclo hasta que la linea deja de ser 1
    '---inicio de la resepcion de los datos por el microcontrolador----
    '------------------
    '------------------
    ''for j=0 to 2 'esta rutina de lectura consume 24 instrucciones mas
    ''for i=0 to 15
    ''pulsin entsal,1,Valor ' se mide el ancho del pulso (con 4 MHz los inc son de 10us)
    ''if valor<30 then ' si el pulso es menor a 30us
    '' Dato[j]=dato[j] | 0 ' se coloca un cero en el registro parcial
    ''else ' pero si no
    '' dato[j]=dato[j] | 1 ' se coloca un uno en el registro
    ''endif
    ''dato[j]=dato[j]<<1 ' se recorre el dato almacenado en el registro para continuar
    ''next i ' con la resepcion de datos hasta completar 16 datos
    ''next j
    '------------------
    '------------------
    for j=0 to 2
    i=0
    repeat
    while entsal=0
    wend
    TMR0=0 'inicializa el TMR0
    while entsal=1
    WEND
    Valor=TMR0
    IF valor<40 then
    dato[j]=dato[j] | 0
    else
    dato[j]=dato[j] | 1
    endif
    dato[j]=dato[j]<<1
    i=i+1
    until i=16
    next j
    'Se almacenan los valores en los registros respectivos
    humedad=dato[0]
    temperatura=dato[1]
    signo=temperatura.15
    temperatura.15=0
    if signo=1 then temperatura=~temperatura 'valor complementario de la temperatura(negativo)
    Parcial=dato[2]
    checksum=Parcial.Byte1
    valor=humedad.Byte1+Humedad.Byte0+Temperatura.Byte 1+temperatura.Byte0
    if valor<>checksum then ' se checa que los datos correspondan con el valor checksum
    lcdout $fe,1,"error de lectura" ' si son diferentes entonces hay error de transmicion
    pause 2000 ' pausa de 2 segundos para iniciar nueva lectura
    goto lectura ' lo escribe en el display e inicia otra lectura
    else ' si no realiza la combercion de humedad y tempèratura
    lcdout $fe,1,"HR=",dec humedad/10,".",dec1 humedad," T=",sdec temperatura/10,".",sdec1 temperatura
    endif
    pause 2000 ' pausa de 2 segundos para esperar nuevos datos del sensor
    goto lectura
    end

  5. #5
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Temp & Humidity sensor interfacing question

    Hi Leonard, thanks for giving the time to share the codes...I will give it a try...

  6. #6
    Join Date
    Feb 2012
    Location
    Meico,D.F.
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Temp & Humidity sensor interfacing question

    Ok, and good bye

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts