Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

D6T Thermal Sensor Code Help needed for MikroC dsPIC PRO

Home Forums MikroC Pro for PIC Project Discussions D6T Thermal Sensor Code Help needed for MikroC dsPIC PRO

This topic contains 7 replies, has 2 voices, and was last updated by  Bitahwa Bindu 2 months, 2 weeks ago.

  • Author
    Posts
  • #5230

    SheldonNyce
    Participant

    I need to interface an Omron D6T-44L-06 with a PIC24FJ64GB002 microcontroller, and I have no idea how to do it using the MikroC dsPIC PRO IDE. I need the temperature reading to be displayed on a 16 x 2 LCD. Can someone please help me with the project? If it will help, we can start with the D6T-1A-02 thermal sensor, and then I can take it from there. But it’s VERY urgent, and I could really use the help! I have included the OMRON D6T user guide, which has some code, and I tried to copy and paste the code into the MikroC IDE but it did not want to compile. Please help, I don’t have experience with I2C.

  • #5241

    Bitahwa Bindu
    Keymaster

    Hi,

    You are using I2C_Send1() function I don’t think it exits in mikroC, you can use the I2C1_Write() function and this function expects only one parameter.

    From the user guide, one of the example to retrieve the value is as follow:

    extern void I2C_start ( ) ;
    extern void I2C_repeatstart ( ) ;
    extern void I2C_stop( );
    extern void I2C_send1( char addr8 , char cmd );
    extern void I2C_getx( char addr8 , char buff [ ] , int length ) ;

    1. Initialize your I2C bus with I2C1_Init();
    2. Send a start command: I2C_Start();
    3. Send a restart: I2C_Repeat_Start();
    4. Send a stop: I2C_Stop();
    5.  Send address (char addr8)  of slave : I2C1_Write(0x14);
    6. Send command :  I2C1_Write(0x4C);
    7. Then read the content of the buffer and send ack with I2C_Rd();

    Read more about mikroC 12C functions: https://download.mikroe.com/documents/compilers/mikroc/pic/help/i2c_library.htm#i2c1_wr

     

    The logic can be summarized below:

    //Declare variables

    MyArray[35] As Byte
    bIndex As Byte

    I2C_Start()
    I2C_WriteByte($14)
    I2C_WriteByte($4C)

    I2C_Restart()
    I2C_WriteByte($15)
    For bIndex = 0 To 34
    MyArray[bIndex] = I2C_ReadByte()
    If bIndex = 34 Then
    I2C_Stop()
    Else
    I2C_Ack()
    EndIf
    Next

  • #5243

    SheldonNyce
    Participant

    Dear Bitahwa,

     

    Thank you so much for getting back to me. I tried your logic, and programmed the suggested code.

    In the email, I have also included a photo of the oscilloscope output for the SDA1 and SCL1 lines.

    The LCD is not displaying anything, and just seems to have a bit of a flicker. I have tested the LCD with normal text, and have adjusted the contrast and the LCD is working perfectly, so I am not sure why it would not display the temperature values.

    Please not that the sensor for the code and the hardware I am testing is the D6T-1A-02

    Once I have this sensor working, I will try use the D6T-44L-06 sensor.

    Have I done something wrong with the code?

    Please help.

    Kind Regards,

     

    Sheldon Nyce

  • #5247

    Bitahwa Bindu
    Keymaster

    Hi,

    A few observation form your code.

    1. When you compile this code, does it compile without generating any errors? In your code you are writing to LCD: Lcd_Out(1,1,tPTAT); but the Lcd_Out() function takes only a string variable and I didn’t see where you converted your int tPTAT to string.
    2. Microcontrollers don’t have an operating system so they read code from top to bottom, it’s your responsibility to make sure the code doesn’t exit the main() function, otherwise the microcontroller will keep on resetting.  That’s what maybe what you are getting. It execute the code than reset. Always use a while(1) loop to keep the microcontroller looping over and over again so it does not exit. Codes that should be read continuously like this temperature reading, must be inside a while(1) loop.
    3. The LCD code does not depend on the I2C, so at least the LCD if codded and connected correctly, should display some values, even if wrong values if wrong information is read. To test if your LCD is working , in the main() after Lcd_Display(); write: LcD_Out(1,1,”Hello”); then a delay of 1 second: Delay_ms(1000);  then put an empty loop: while(1) {} Check if you can display “Hello” to your lcd.
    4. As we said, you are getting the values, then you are initializing the lcd, then you display the lcd then the program execute and reset. This goes very fast in PIC cycle period you can’t see any thing, because you are allowing your PIC to exit and reset.
  • #5248

    SheldonNyce
    Participant

    I have edited the code according to the above recommendations. It’s still not working properly. The new code is attached.

    Thank you so much for assistance thus far.

    Attachments:
    You must be logged in to view attached files.
  • #5272

    SheldonNyce
    Participant

    Thank you so much for all of the assistance! It works now. Please see attached for working code for the Omron D6T-1A-01 thermal sensor!

    Thanks for all of the assistance!

    Attachments:
    You must be logged in to view attached files.
  • #5276

    Bitahwa Bindu
    Keymaster

    Great! That’s good to hear. Good luck for the rest of your project and thanks for your feedback.

You must be logged in to reply to this topic.

Select your currency
EUR Euro
USD United States (US) dollar