PICAXE-08M + MLX90614 IR temp sensor

fredsan42

New Member
I just recently got started with a PICAXE-08M and have done a few simple projects successfully. I picked up an MLX90614 temperature sensor from Parallax, but I can't seem to get it to work with my PICAXE.

The MLX90614 has some instructions and sample code for using it with a BASIC Stamp, so I'm trying to interpolate to get it working with the PICAXE. So far I'm getting nothing from the sensor, so I'm guessing there's something going on with the serial communication.

I wrote a simple PICAXE program to send the "!ID" command out to the MLX90614, which should cause it to respond with 3 bytes. I've confirmed that the PIC is sending the data by hooking it up to my PC. I've also hooked an oscilloscope probe up to the "SIG" line of the MLX90614 and I see that the PIC is transmitting something when it's connected to the MLX, but the MLX never responds. I'm using the N2400 baud rate specification, and I'm wondering if the MLX wants me to use the "T2400" with the MAX232 chip, as I'm just using the simple resistor setup at the moment. Does anyone have experience here and know if that's what I may be missing?

Thanks.
 

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

Do you have a link to the data sheet and the example code ? I found this ...

http://www.melexis.com/Sensor_ICs_Infrared_and_Optical/Infrared/MLX90614_615.aspx

If that's the same it says, "The thermometer comes factory calibrated with a digital SMBus output" - I don't know a lot about SMBus or how to drive it. I'm not sure how you mean by using N2400 and further talk of MAX232 is confusing as SMBus is not RS232-style serial and the chip is unlikely to be +/-12V tolerant.
 

papaof2

Senior Member
The Parallax unit has an SMSbus to serial converter chip on the board. The chip does autobaud (2400 and up).

The hardest part will likely be using a single pin for serial in and out, or connecting two PICAXE pins to a single pin on the Parallax board.

John
 

fredsan42

New Member
Yes, it is the datasheet you linked to from Parallax's website.

As you mentioned, there is sample BS2 code, and I tried converting it. After it didn't work, I tried dumbing it down to a very simple level to at least get the MLX to respond with something. I connected it as follows:


MLX to PICAXE
+5V to +5V
GND to GND
SIG to I/O 2 (pin 5)
RST to I/O 1 (pin 6)
ALR - Not connected

My code looks like this:

<code>
' reset the chip
low 1
pause 5
high 1

pause 50
' Default should be $5A, but all devices should respond to $00
SEROUT 2, N2400, (0, "!ID", $00)
SERIN 2, N2400, (lowbyte, highbyte, pec)
pause 20
</code>

I connected up an oscilloscope to the reset and serial lines and confirmed that the program starts up, pulls the reset line low to high, and then sends the 0x0, "!ID", 0x0 data out. The MLX doesn't seem to do anything as a result. At least there's no additional activity on the serial line.

I'll admit I'm a bit of a newbie with the PICAXE and microcontrollers in general, so I don't really know if it's even valid for me to do a SERIN and SEROUT on the same pin without some sort of additional circuitry or something. I just have the pin directly connected between the MLX and PICAXE.

Any other thoughts?

Thanks!
 

hippy

Ex-Staff (retired)
[ Edit : Modified to take account of above post ]

Looking at the documentation it would appear that to read the version number, using Pin 2 of the PICAXE connected to the module SIG, Pin 1 to RST ...

Low 1
Pause 5
Input 1
Pause 50
SerOut 2,N2400,(0,"!ID",$5A)
SerIn 2,N2400,b0,b1,b2
SerTxd("Version=",#b0,b1,#b2,CR,LF)

If N2400 does not work then try T2400. You can also try with a SETFREQ M8 as the first line to get communications faster, 4800 baud.

The PICAXE Pins should connect directly to the SIG and RST pins. No pull-up, pull-down, current limiting resistor or anything would appear to be necessary. Ensure both the module and PICAXE are running from the same voltage, 5V.
 
Last edited:

fredsan42

New Member
I neglected to include my symbol definitions, but I'm essentially doing that serin. I do have the parentheses where you do not. Does that make a difference? I believe I tried it both ways, and I also did try it with the $5A, but when it didn't respond, I dug around a little and found that all devices should respond to $00, so I tried that with the hopes that maybe my device had been programmed with a different default address.

I assume the sertxd is to output the command back to my PC serial port for debugging, right?

I will try the 4800 baud setting when I get home later. I tried T2400 (without the MAX232), but that didn't work either.

One thing I noticed when trying to look back at the transcription I typed of the serial data, it looks like it might not be transmitting what I think it is. When looking at the serial output from a PICAXE on the scope, should it basically be:

------------|_<8 data bits>--_|<8 data bits>--_|...|----------

aka, held high, then low for the start bit, 8 data bits, high for two clock pulses for the stop, then low for the start again, etc..?

I'm sort of answering my own question, but I think it's supposed to be the inverse of that when using N2400, as the line should be normally idle low, but when I connect the PICAXE to the MLX, the line seems to be held high, so maybe this implies that I need to use T2400. But when I do that by itself without the MAX232 setup, it doesn't seem to work any better. However, I don't think the MLX chip is expected the +/- 12V as a MAX232 would do.

I also need to disconnect the SIG line and re-check the oscilloscope of the transmitted data to see if it looks right when nothing else is connected. But in the mean time, any other thoughts would be appreciated.

Thanks again.
 

hippy

Ex-Staff (retired)
Yes, the brackets in SERIN will have an effect; it will be looking for a match of that byte sequence before valid data and then not storing anything. Use no brackets but that won't affect what you are seeing on the scope.

N2400 will transmit from a PICAXE as idle-low, active high ( ie, start bit = +V ). This is the same as what would be seen on a PC cable but if the module is expecting the data to have passed through a MAX232 from a PC then it will be expecting the inverse of this, so T2400 should fix that.

Yes, SERTXD is for debugging. It will display on the Programming Editor Terminal window by sending data up the dowload cable. Very useful IMO.
 

fredsan42

New Member
Thanks for the info. I realized the () impact as I was re-reading the documentation, but as you said, I'm not seeing anything on the scope, so fixing that won't fix my problem.

I do have a few plans for things to try later tonight when I get back to it. Do you see any reason to use 2 separate pins on the PICAXE for input/output, separated by diodes? i.e., the pin I'm using for output will be connected to the MLX SIG pin with a diode preventing current from coming back to the PICAXE, and the pin I'm using for input on the PICAXE would be connected to the same MLX SIG pin, but with the diode reversed, so the signal can only flow out of the MLX into the PICAXE on that pin.

Should this be necessary?
 

hippy

Ex-Staff (retired)
No, that shouldn't be necessary.

One difference between the suggested code and what you have is they make RST an input when finished. Don'y know if that does affect things. Might be worth changing that as well.
 

westaust55

Moderator
The schematic for the IR Temp module shows the RST signal pulled high with a 4.7KOhm resistor to +Vcc.



Additioally, the Parallax datasheet in the table on page 2 indicates that the connection to the RST pin is optional.

Therefore, seems unlikley there would be a need to change the pin used to drive RST back to an input, even though the BS2 sample code does change the pin back to an input.
 

fredsan42

New Member
I tried several things yesterday, but I still couldn't get the MLX to do anything. I tried N2400, T2400, with and without RST, and even diodes. As far as I can tell, the PIC always sends out the data, but the MLX doesn't respond.

Since the sample code is BS2, does anyone happen to know how serial communication with a BASIC Stamp works, primarily as in what voltage levels it uses? The only thing I can think of at this point is that the MLX is not expecting the 0V/5V swings the PICAXE is putting out.

Thanks.
 

hippy

Ex-Staff (retired)
AFAIK the BS2 works the same as a PICAXE, 0V/5V serial I/O. Apart from any polarity differences arising from Nxxxx and Txxxx I'd expect the two to behave the same.

I don't suppose you have a BS2 to try it with ? That would be quite an expense just to test but perhaps you could find someone who has one ? It is possible the module does not work or there's some subtle issue affecting operation.

Has the module had its ID changed ? You could work your way through all those to see. By using Data Eeprom you can increment the ID on every reset so you don't have to run 256 programs.

As you mentioned MAX232 ... did you by any chance connect the module via a MAX232 ?
 

westaust55

Moderator
The BS2 has not "N" and "T" capability for SEROUT commands.

I am using a 4x20 LCD display originally intended for use with a BS2 and for that I use the N2400 keyword.

Definitely should be connecting the IR Temp module direct to the 08M (not via a MAX232 chip).
 

fredsan42

New Member
hippy: Can you clarify what you mean by using "Data Eeprom"? It occurred to me that I could just write a loop that resets the chip, waits a short period, then sends out a command with a slave address from 0 to 255, but since I'm using an 08M, it will wait forever on the serin if nothing is received. Is your method a way around that?
 

hippy

Ex-Staff (retired)
Yes, this was to get round the fact SERIN just stops if nothing received. Try this -

Eeprom 0,(0)
PowerOnReset:
Read 0,b0
SerTxd("Trying ",#b0,CR,LF)
b1 = b0+1
Write 0,b1
... whatever
SerOut 2,N2400,(0,"!ID",b0)
... whatever
SerTxd("Something worked!")

Everytime you power it up / reset it will try a new ID. Power it off if it doesn't reposnd, next time powered-up it will try the next ID.

You could always just do the reset/send ID in a loop if you are watching on the scope and don't need to use the SERIN.
 

fredsan42

New Member
Still no luck. I wrote code to do send the "!TEMW" command in a loop from addresses 0 to 255 to tell the sensor, whatever address it may currently have, "Set your slave address to 0x5A and set your power-up mode to continuous measurement and output". I power down the sensor and power it back up, and it still does nothing. I would have expected immediate serial output to start showing up on the scope.

Any thoughts on whether it's possible that the MLX sensor is expecting data bits in reverse order or something?
 

hippy

Ex-Staff (retired)
The BS2's SEROUT should be sending bits in the same order as the PICAXE and vice-versa or they'd never be able to communicate with a PC. I'd expect the MLX to be expecting serial in that order or it would make life needlessly complicated.

You may be able to get better advice on configuration and use from the manufacturer's forums.

[ Added : I see that you tried that, but no responses there yet ]
 
Last edited:

westaust55

Moderator
Fredsan43,

you did not answer hippy question:
"As you mentioned MAX232 ... did you by any chance connect the module via a MAX232 ?"

Was surfing for PICAXE info and one find lead me to the Parallax forum where I see a question involving PICAXE did not get a particularly good welcome. :(
Can't help you particularly with a PICAXE. This is a support forum for the Parallax Stamps, SX, and Propeller. The PICAXE is a completely different beast although it's sold as a Stamp replacement. Try the PICAXE's manufacturer's website for their support forums.
Not all forums are as helpful as this.

I can confirm what hippy says about uniformity of SEROUT and SERIN between BS2 and PICAXE. The BS2 only has by default, the "Nxxx" option.
 
Last edited:

fredsan42

New Member
Yeah, that post is from me in case you didn't notice. :) I've been trying to get some information over there as well.

I have not yet tried to connect it via a MAX232, but that is the suggestion coming out from someone over there as well. But doesn't the MAX232 also change the voltage from 0V/5V to larger swings?

Aside from that, your earlier post suggested that I should *NOT* connect the MLX via a MAX232. Do you now think I should give that a try?

Thanks.
 

hippy

Ex-Staff (retired)
Do you now think I should give that a try?

No.

With the PICAXE driving the MAX232 you will be putting +/-12V into the module which will probably damage it. With the module driving the MAX232 you would damage the PICAXE unless you fitted the 22K/10K resistors.

Electrically a direct connection should be okay. It has to be a 'protocol issue' but I am not sure what. The initial "0x00" is supposed to be a wake-up signal; you could try two separate SEROUT's, one sending 0x00, the next sending "!ID" etc. maybe put a pause between the two.

A belated thought, if using T2400, put a "HIGH 2 : PAUSE 250" before the Reset pulse. The pause can always be reduced later if it solves the problem.
 
Last edited:

fredsan42

New Member
I will give that a try later today.

If either of you have a BS2 and a scope, it could be helpful if you could load the sample code up and show me what the serial sequence looks like on the scope. Even if you don't have the MLX, that might at least show me if there's something slightly different that the PICAXE is doing that's causing the MLX not to respond. I tried asking for someone to do this over at the Parallax forums, but no one has yet.
 

fredsan42

New Member
Well, it was an expensive test, but I bought a BS2 just to see if the sensor actually works. It does.

So I wrote functionally equivalent BS2 and PICAXE code and looked at the output on the oscilloscope.

The only thing I can find is that the entire transmission of the !ID sequence takes 11.82ms with the PICAXE and 11.56 on the BS2. The timing is very slightly different between the two, but the actual waveforms look the same, with the exception that the MLX sensor starts replying 2ms after the end of the transmission from the BS2, whereas it does nothing with the PICAXE.

Does anyone know what typical timing tolerances are for serial transmissions, or have any other thoughts?
 

westaust55

Moderator
PICAXE driving Parallax Temp Sensor

The |N2400", "N1200" in the SEROUT commands are effectively predefined symbols for values, but the values are only one value apart so not possible to try a little baud rate tweaking.

It might be the time required for the PICAXE to change the pin from being an output to being an input. Only the 08/08M can do this at all. The PICAXE pin might still be active as an output at 2ms preventing the return signal.

A guess, but try using a different PICAXE input purely for the return signal to see if you can read a response.

You will need to add a resistor (or diode) between the pin used as the PICAXE outputand the other pins.

Code:
PICAXE OUT ---- 2.2k Resistor -----+
                                   |
PICAXE INPUT ----------------------+------- IR Mod Data Pin
I has suggested such a scheme to another forum member ages ago but got no feedback whether it worked.
 
Last edited:

hippy

Ex-Staff (retired)
The PICAXE should switch from output to input reasonably fast, certainly in less than 2ms. I'd expect in the region of 250us.

You can improve that switching time by using "SETFREQ M8" and N1200/T1200 baud rates. The PICAXE will operate twice as fast ( halving the time to switch from output to input ) but still communicate at 2400 baud.

If it is the module slugging the change-over time then a pull-up or pull-down R as appropriate and suggested by westaust55 may help but I would expect you to be able to see such a problem on a scope.

Bit-banged and other serial receivers which sample mid-bit should be resiliant to up to +/-6% tolerance in total ( eg, a transmitter can run 3% slow a receiver 3% fast etc ). Receivers which perform more advanced bit-time windowing can do better but all should cope with +/-6%.

The total time for transmission is probably not as important as the individual bit and framed byte timings. Inter-byte gap lengths should not matter, however it is possible that timing is more critical between the 0x00 marker byte and the "!ID". I would not expect a longer time between 0x00 and "!ID" to be a problem and if too short from a PICAXE then sending 0x00 separately as suggested should have solved that by extending the inter-byte gap time.

Given that the module can work at speeds above 2400 where bit times and inter-byte gap times would be shorter anyway, and baud rate detection is done using the "!" of the command ( if I recall correctly ) I'm not sure how there would be a problem in this respect.

Did you try changing the reset sequence to turn the pin back to an input, or scoped that to see if there is a difference with PICAXE and BS2 operation ? While I agree with westaust55 that it doesn't appear necessary, nothing else is making much sense to explain why it doesn't work and that's the only other connection and control of the module. You could try extending the length of the reset pulse and the pause after it.

Did you also add the HIGH 2 if using a T2400 baud rate ?
 

ruperthart

New Member
Fredsan: did you get the MLX90614 to work?

if so, can you upload somecode? i have the same difficulties with a pic. r
 

pha555

Senior Member
PICAXE-20X2 with MLX90614ESF-AAA

I have posted code to directly interface the MLX90614 infrared temperature sensor with a PICAXE. This is direct. No special board from Parallax or SFE is required.

http://www.phanderson.com/picaxe/mlx90614.html

Note that the -AAA device is 5V. I have seen a -BAA which is intended for 3V operation.

Currently, there is just code to measure and display Tambient and Tobject

Cheers.

Peter Anderson, www.phanderson.com
 

John West

Senior Member
As we say some places in the States, "You the man," doc. That should help some. I can see I'm going to want to purchase a variety of different picaxe types so I can use them to glue my projects together whenever I can't translate the code from version to version.

For me, software fixes are great, but hardware fixes are quick.
 
Last edited:

Marcwolf

Senior Member
The |N2400", "N1200" in the SEROUT commands are effectively predefined symbols for values, but the values are only one value apart so not possible to try a little baud rate tweaking.

It might be the time required for the PICAXE to change the pin from being an output to being an input. Only the 08/08M can do this at all. The PICAXE pin might still be active as an output at 2ms preventing the return signal.

A guess, but try using a different PICAXE input purely for the return signal to see if you can read a response.

You will need to add a resistor (or diode) between the pin used as the PICAXE outputand the other pins.

Code:
PICAXE OUT ---- 2.2k Resistor -----+
                                   |
PICAXE INPUT ----------------------+------- IR Mod Data Pin
I has suggested such a scheme to another forum member ages ago but got no feedback whether it worked.

Ahh.. Ok - that will help me greatly too. It's a innsue between the BS and the PicAxe in that they often use the same line for both serial input AND output.
Many thanks
Dave
 
Top