Hi i bought and hooked up an mlx90614 thermal sensor like in this link http://bildr.org/2011/02/mlx90614-arduino/
Then i have combined the code from the link with the "simpleAnalogFirmata Example" so that it looks like the "Arduino Code" further down. It works perfect in the arduino serial monitor.
But in Visual Studio 2010 i have a problem. A can also read the serial output but half the time im getting corrupted values, missing numbers or text.
i have tried changing the delay in the arduino code and things like changing Bits per second, databits, parity and those sorts of things. And some of the things seems to do some kind of difference
So im stuck, and i could use some help
VB Code*******************************************************************
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FirmataVB1.SerialPort1.Open()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = FirmataVB1.SerialPort1.ReadLine
End Sub
End Class
VB Code End********************************************************************
Arduino Code*****
/* Supports as many analog inputs and analog PWM outputs as possible.
*
- This example code is in the public domain.
*/
#include <Firmata.h>
#include <i2cmaster.h>
char st1[30];
byte analogPin = 0;
void analogWriteCallback(byte pin, int value)
{
if (IS_PIN_PWM(pin)) {
pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
analogWrite(PIN_TO_PWM(pin), value);
}
}
void setup()
{
Firmata.setFirmwareVersion(0, 1);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.begin(57600);
Serial.begin(115200);
PORTC = (1 << PORTC4) | (1 << PORTC5);
}
void loop()
{
while(Firmata.available()) {
Firmata.processInput();
} long int tpl;
tpl=readMLXtemperature(0); // read sensor object temperature
sprintf(st1,"%03li.%li",tpl/100);
Serial.print(st1);
Serial.println("");
delay(0);
}
//****************************************************************
// read MLX90614 i2c ambient or object temperature
long int readMLXtemperature(int TaTo) {
long int lii;
int dlsb,dmsb,pec;
int dev = 0x5A<<1;
i2c_init();
i2c_start_wait(dev+I2C_WRITE); // set device address and write mode
if (TaTo) i2c_write(0x06); else i2c_write(0x07); // or command read object or ambient temperature
i2c_rep_start(dev+I2C_READ); // set device address and read mode
dlsb = i2c_readAck(); // read data lsb
dmsb = i2c_readAck(); // read data msb
pec = i2c_readNak();
i2c_stop();
lii=dmsb*0x100+dlsb;
return(lii);
// do one analogRead per loop, so if PC is sending a lot of
// analog write messages, we will only delay 1 analogRead
Firmata.sendAnalog(analogPin, analogRead(analogPin));
analogPin = analogPin + 1;
if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0;
}
Arduino Code End***************