Infra Red Thermometer - MLX90614 BAP code

Has anyone gotten the Infra Red Thermometer - MLX90614 working with the basic atom pro? If so could you post your code?

sparkfun.com/commerce/produc … ts_id=9570

That looks like a very interesting sensor. I’m going to have to get one to play with. :slight_smile: It allows either I2C or reading PWM to get data from it, so it should not be too hard to make it work with your favorite microcontroller.

What is your experience with micros and writing software for them?

8-Dale

My experience working with microcontrollers is copying what others have done (like a monkey), mimicking exactly how they wire it up to the microcontroller (verbatim), using the same voltages, resistors, and other electrical magic (hopefully they’ve posted the Radio Shack and/or Digi-Key part numbers and show pictures and wiring diagrams of what they did), and finally the code they run inside the microcontroller to act on it all. If I think I can replicate it I run out and order everything! Most times I order two of everything because I usually melt things the first time through trying to solder it all together. If by some miracle or act of god I can get all the electrical things to work, code in the microcontroller to compile, download, and install inside the microcontroller, I then pipe the clean results out to the com port with something like this:

serout S_OUT, i9600, [dec duty, 13] 'output to com port

Whew!

That then gets the data into my world dah-dah-dah-dah (the PC). Then I do really cool things with it!

If I can get this sensor to work I’m going to point it at my motor and motor controller (I bought two sensors)

http://www.otherrobots.com/endlesssphere/BellyPan.jpg

OK, I bought three of these sensors, maybe I’ll point the last one at me just to see what system is ultimately failing in all of this (sweat beading off my forehead). :laughing:

I’ll then display the data on my PC touch screen/dashboard (mounted between my handlebars) at which point I hope to notice things are heating up and get off the throttle, at the same time I hope to automatically turn on a fan inside a tube:

http://www.otherrobots.com/endlesssphere/fanbuildfinal2of3.jpg

that fan will then hopefully start to cool down my etek motor so that the attached wiring doesn’t melt (notice third melted phase wire detached on the right):

http://www.otherrobots.com/endlesssphere/motor02melt.jpg

What can I say, in the end, it all ends up being kind of a rube goldberg device.

To date I’ve traveled more than 26 miles on a charge and I’ve gone faster than 52 MPH (my current records to date).

All I want is a robot I can ride on! :laughing:

http://www.otherrobots.com/endlesssphere/dcdcconverter.jpg

OK, now I feel like I’m rambling. What was your question again?

Oh yes…

Not much but I know going down this path will absolutely get me what I need, I’m absolutely willing to study, listen, and learn. Microcontrollers in my opinion are the bridge between the electronics world and the PC.

I’m also studying the CAN bus, and now you know the rest of the story… :unamused:

OK, well, as long as you don’t suffer from programaphobia, you should do well. My best suggestion is snag yourself a good micro combination, such as the BotBoard II and Basic Atom Pro (get the starter kit with programming manual), and go for the gold. :smiley: The Atom Pro is very easy to work with, and there is a LOT of good work being done here with it, so no lack of support if you have questions and need help with something. Dig into the data sheet for your sensor and learn about I2C and how to read PWM signals so you can get data out of the sensor. Then put it all together and see what you can do with it.

8-Dale

I have two BotBoard II’s with the Basic Atom Pro and I’m confortable with visual basic so that’'s not a problem. I’m still figuring out how to wire the pins. I’m reading the manual with the sensors (it has four pins instead of three)! I’m not comfortable with the electonics part of it. I’ve gotton the Ping to work so I’m hoping this will work the same.

Well, there are only two choices for getting data from that sensor - I2C and reading a PWM signal. If you don’t already have the programming manual for the Basic Atom Pro, you need to get one. ALL the information you need on both I2C and PWM (pulsin reads) is in there. :slight_smile: PWM would be the easiest to start out with.

It’s been quite awhile since I dusted off my Atom Pro and did any programming for it, but I am seriously considering putting it to work again. I am also being tempted by the Arc32 board, but so far I am resisting.

8-Dale

PWM is what I want to use.

I think this is what I need to do, not sure what the C1, 0.1uF, and U1 means:

http://www.otherrobots.com/lynxmotion/MLX90614PWMDiagram.jpg

Looks like I’m going to need one of these from RadioShack:

0.1 uF Metallized Polyester Film Capacitor
Model: 272-1053 | Catalog #: 272-1053

http://rsk.imageg.net/graphics/product_images/pRS1C-2264788w345.jpg

radioshack.com/product/index … Id=2102589

I’ve been searching for code samples. This was one example but the person still wasn’t getting it to work:

' =========================================================================

' ----- I/O Definitions ]-------------------------------------------------

Reset CON 3
Alr CON 2
Sensor CON 1

' ----- Variables ]-------------------------------------------------------

temperature VAR Word
tempL VAR temperature.LOWBYTE
tempH VAR temperature.HIGHBYTE
pec VAR Byte

Init:
' LOW Reset
' pause 50
' INPUT Reset

' Input sensor

setSlaveAddress:
SEROUT sensor,n2400,[0,"!TEMW",$5A,$2E,$5A,"C"]
pause 10

getTemperature:
SEROUT Sensor,n2400,[0,"!TEMR",$5A,$07]
pause 10
SERIN Sensor,n2400,[tempL,tempH,pec]
pause 10
' return

displayTemperature:
serout s_out,i2400,[DEC tempL, " , ",DEC tempH, 10,13]

end

That example is NOT reading a PWM value. You need to use the pulsin command to read PWM values. It is not serial data you need to read.

8-Dale

I ended up going with this:
0.1µF 50V Hi-Q Ceramic Disc Capacitor Pk/2
http://rsk.imageg.net/graphics/product_images/pRS1C-2160274w345.jpg
radioshack.com/product/index … Id=2062365

Here is my setup. The only additional electronics added to the circuit was the capacitor. Hopefully this should do it. Guess it’s time to apply power.

http://www.otherrobots.com/lynxmotion/tempsensor01.jpg

I’ve tried this code but I get the timeout error.

wdist var word

main:
low p8
pulsout p8, 5
input p8
pulsin p8, 0, toolong, 65535, wdist
'wdist = wdist / 148   ;convert for inches
serout s_out, i9600, "Distance: ", sdec wdist, 13, 10]      ;display result in terminal
goto main

toolong:      ; if the program gets here the sensor is not functioning, or wired wrong
serout s_out, i9600, "Timeout, sensor is not working", 13]
goto main

By default it is set to SMBus. It needs to be configured to use PWM by setting the pin high. I’ve been reading the manual but it’s a tough read.

sparkfun.com/datasheets/Sens … 14M005.pdf

You will find that most data sheets and device manuals can be difficult to read, but you will need to learn how to decipher them when you want to work with new devices. :wink: This is a pretty simple device too. Imagine the more involved devices and learning to use them.

8-Dale

They do have a C# sample on the Melexis (manufacturer site).

SMBus/PWM communication implementation on STC-MCU
This is software for a MCU with 8051 architecture for communication with the MLX90614 using the SMBus or PWM interface.
It includes:
Basic SMBus protocol setup;
Reading measurements from the MLX90614 with the SMBus and calculating the temperature;
Adjusting programmable settings (SMBus address, emissivity) of the MLX90614;
Detecting the PWM signal from a MLX90614 and calculating the temperature.

Current Revision: 1.1
File Type: Software & Tools
File Size: 298.0 KB
melexis-rf-ics.com/Asset/SMBusPW … _5880.aspx

This appears to be the code that shows the timing for the PWM. Not sure how to convert this to BAP.

//----------------------------------------------------------------------------------------------------------------------------------------//
//Head files
//----------------------------------------------------------------------------------------------------------------------------------------//
#include <STC12C5410AD.H>
#include "stdio.h"
#include "math.h"
#include "intrins.h"
#include "string.h"
#include "PWM_display.h"                  //Including PWM_display.h (showing temperature on digital LEDs)
//----------------------------------------------------------------------------------------------------------------------------------------//
//Macro definition of I/O ports
//----------------------------------------------------------------------------------------------------------------------------------------//
  sbit P3_3=P3^3;    
//utilize MCU external interrupt source 1£¨INT1£©to measure PWM pulse on SDA pin of MLX90614
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------//
//Function: Calculate Temperature according PWM pulse width and period£¨Duty cycle£©
//----------------------------------------------------------------------------------------------------------------------------------------//
int Calculate(unsigned int t1pwm, unsigned int T1pwm)
{
  
   int DC;
   long int T;
   int T1;
   int K;
   int T1max=120;                                      //The maximum object temperature, saved in EEPROM 00h
   int T1min=-20;                                      //The minimum object temperature, saved in EEPROM 01h
   K=2*(T1max-T1min);

   DC=t1pwm*100000/T1pwm;                
   //Calculate Duty cycle, times 100,000 shifts the fixed point 5 position to the right
  
   T=(DC-0.125*100000)*K+T1min*100000;
  //calculate object temperature, DC is duty cycle
   T1=T/1000;                                          
  //To truncate the resolution to 0.01¡æ, a division by 1000 is done on the results
   return T1;

}
//----------------------------------------------------------------------------------------------------------------------------------------//
//Name£ºmain 
//Function£ºUse STC MCU external interrupt source port 1¡¢Timer 0 and 1 to measure PWM pulse width and period
//----------------------------------------------------------------------------------------------------------------------------------------//
void main(void)
{
   unsigned int A;
   unsigned int B;
   unsigned int C;
   unsigned int D;
   unsigned int Data1;
   unsigned int Data2;
   int Data;

   TMOD=0x19;                                 //Set timer 0£¨GATE=1£©and Timer 1£¨ GATE=0£©work in mode 1
   TH0=0x00;                                  //Clear TH0, TL0 
   TL0=0x00;
   ET0=1;                                     //Open Timer 0 interrupt enable
   ET1=1;                                     //Open Timer 1 interrupt enable
   EA=1;                                      //Open overall interrupt enable
   TL1=0x00;                                  //Clear TH1, TL1 
   TH1=0x00;
   EX1=0;                                     //Turn-off INT1 interrupt

while(P3_3==1)		                      //Wait INT1 low pulse
{;}
while(P3_3==0)		                      //Wait INT1 high pulse
{;}
TR0=1;                                        //Open timer 0
TR1=1;			                      //Open timer 1
while(P3_3==1)		                      //Wait INT1 low pulse
{;}
TR0=0;                                        //Clear timer 0
C=TL0;                                        //T0 Low byte sends to C
D=TH0;                                        //T0 High byte sends to D
while(P3_3==0)		                      //Wait INT1 high pulse
{;}           
TR1=0;                                        //Clear timer 1
A=TL1;                                        //T1 Low byte sends to A
B=TH1;                                        //T1 High byte sends to B
Data2=(D<<8)+C;
Data1=(B<<8)+A;

Data=Calculate(Data2,Data1);                  //Calculate temperature based on counter value
display(Data);                                //Show temperature 
}