Have you ever interfaced a D6T thermal sensor with a uC?

Dear all Programming Guru’s:

I am a final year undergraduate student from a University in South Africa. In order to complete my degree, I have one final project to complete – I need to create a system that counts the number of people in a test area, and the information thereof will be used as an input to a light dimmer for the test area.

I have elected to use a D6T thermal sensor to detect human presence, and the thermal information gathered will be used as an input to a Neural Network.

Now that you have some background info of the design task, I will present the problem I am currently facing: I can’t get the sensor to work, and I have no idea why.

Also, I should mention that I am part of a class of 255 students, and we were each randomly assigned a project, and no two projects are similar. So the project is not to “get the sensor working”, the scope is much bigger than that. Thus, if you are able to assist me with my current problem – don’t think that you are helping me cheat, or anything like that. Our study leaders have encouraged us to reach out to experienced professionals (such as yourselves) to ask for mentorship.

The other major problem is that I am extremely inexperienced when it comes to programming, as my discipline of study is “Electrical Engineering”. I did one small module on C programming, back in 2012 and I barely passed the module. So please be gentle with me – I am likely to make mistakes. This is my first attempt at programming an I2C device.

Right, now that THAT disclaimer is out of the way; now onto the problem at hand.

In order to get this sensor running and to test to see if it works, I am interfacing a D6T-1A-01 thermal sensor using I2C communication protocol to a 16 Bit PIC24FJ64GB002 microcontroller. The output of the sensor should be displayed on and LCD connected to the uC. Please see the attached zip folder for a photo of the physical circuit. I am programming the devices using the MikroC dsPIC PRO IDE.

I have tested the LCD using simple text, and that part of the code is working fine.

With the entire thing set up, with 5V feeding the sensor and the LCD and 3,3V feeding the uC, I get random numbers output to the LCD. Completely random, and they don’t change with time. When I switch the system off, wait for a while, and switch the system back on, I get a different set of random numbers, but the numbers never change with time. See the attached photo of LCD.

If I disconnect the sensor during operation, nothing happens to the numbers… they stay the same. Sometimes the LCD goes blank, but only sometimes.

I measured the SDA and SCL lines using an oscilloscope, and a photo of the output can be seen in the zip folder. If I look at the D6T user guide (also in the zip folder), it seems like there is missing data?

The Oscilloscope readings also never change, even if I bring a heat source closer to the sensor…

Now, you might be asking yourself, why is this guy posting this question on this forum? The short answer is – because nobody who has responded on the dsPIC MikroC forum has ever worked with a D6T sensor, and so we are chasing our tails a little bit. A chap by the username “Hexreader” was extremely kind in assisting me as far as possible, but without the hardware – there is only so much one can do. Thus, I needed to broaden the scope of outreach. My hope is that, if you’ve ever worked with one of these sensors, that you might be able to spot some obvious mistakes, even if you’ve never coded the sensor using the dsPIC MikroC IDE.

So if you’ve ever worked with a D6T thermal sensor, could you take a look at the attached folder and see if you can spot why my system is not working as hoped?

I would greatly appreciate any and all assistance. You would literally be a life-saver and if necessary, I would even be willing to pay for working code.

D6T user guide: https://omronfs.omron.com/en_US/ecb/products/pdf/en_D6T_users_manual.pdf

If you wish to contact me privately to discuss the matter further, my email address is: sheldonnyce@tuks.co.za

Thank you for entertaining this post!

D6T-1A-01Rev0.zip (1.91 MB)

Is your microcontroller running Arduino code ? Do you want us to learn a new I2C library to be able to answer your question ?
Do not cross-post: https://forum.arduino.cc/index.php?topic=624017.0

No it is not running Arduino code. Otherwise this wouldn't be a challenge. My hope is that perhaps someone with experience using this sensor might have some knowledge and experience with programming C programming, as well as Arduino code.

No I do not expect you to learn a new library. This post is a question for real programmers who know how to program outside of the comfort zone of Arduino, and people who have used this sensor before. As Omron does not provide good support for their products.

SheldonNyce:
...as well as Arduino code.

But there is no Arduino code.

If using Arduino code is no challenge, then buy an Arduino board and start with this library: GitHub - jordanlui/Omron-Arduino: Arduino code to get data out of the incredible 4x4 IR OMRON D6T MEMS sensor..

To answer your question we would have to learn this I2C library: https://download.mikroe.com/documents/compilers/mikroc/pic/help/i2c_library.htm and compare it with the working Arduino library.
That is not a challenge, that is a job for you.

What is this: "if (bIndex = 4){" ? Can you explain in words what that does ?

Do you assume that you read 5 bytes but are reading 4 bytes instead ? Why would the I2C1_Stop() be inside the for-loop ? By the way, you are not reading 4 bytes either, you are not reading any byte at all.

I think you need another forum to ask your question.

Now we're getting somewhere. This is helpful input - thank you.

For the project, our study leaders are ignorant and believe that "no one uses Arduino in industry" and so NONE of the projects can use Arduino code. In fact, I'm not really even supposed to be using MikroC. They want us to use XC16 compiler in the MPLAB X IDE... Yawn...

I wish we could use Arduino.

Why would I not be reading anything at all?

This is precisely why I posted on this forum... Because no-one on the MikroC forum has pointed these bugs out, and yet, you have noticed them.

Any suggestions as to how to fix them?

As I said any the beginning, any and all input would be greatly appreciated. Thanks very much

if(bIndex=4) doesn't make any sense, as it sets bIndex equal to 4. The correct operation should be "if(bIndex==4)

Is that correct?

Please bare with me, my programming is poor and I'm learning as I go, but once again, thanks for the assistance.

The '==' is one thing, but you can take the STOP out of the for-loop. Read a number of bytes (in a for-loop) and if that is done then do a STOP.

It is true, "no one uses Arduino in industry". Arduino was created at a universaty in Italy. It was sadly not created by software engineers with many years of experience in the embedded field. The reliability is not even close to 100%. It is meant for fast prototyping, and that is what Arduino is best used for.

This is not Arduino related, you should ask your questions somewhere else. Perhaps stackexchange/stackoverflow has a forum or a tag for this.

I am concerned that you mentioned that:

Koepel:
Do you assume that you read 5 bytes but are reading 4 bytes instead ? Why would the I2C1_Stop() be inside the for-loop ? By the way, you are not reading 4 bytes either, you are not reading any byte at all.

Is this because the Stop() is in the for loop? Why would I not be reading any byte at all? What could be the corrective measure?

I'm sorry that I'm asking on this forum, I really don't mean to annoy anyone. But this is the only place where I am getting any help, and I'm panicking because I need to get this sensor working ASAP so that I can use this program as a template to program the D6T-44L to get inputs to a Neural Network that I have to design.... So the pressure is on BIG TIME to get the sensor working, and I'm freaking out.

Thanks for the help, hopefully it can somehow help someone in the Arduino environment.

GUYS IT WORKED!!!! Literally just by changing to "if(bIndex==4)", now I get meaningful data! So now we have real temperature data.

Next question - I have to reset the chip (MCLR) every time to update the temperature reading. How do I get it to read temp data continuously in real-time?

You guys are the best!!!