Pages: [1]   Go Down
Author Topic: Arduino + mlx90614 +firmata  (Read 1465 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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******************************************
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50452
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your VB code has absolutely nothing to do with Firmata, so this:
Quote
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.
makes no sense. Why would you start with a completely unrelated, specific purpose, app?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well i dont really understand your question.. What i mean is that i combined the code from the Bildr blog and the code in the simpleAnalogFirmata Example(build in arduino software) and put them together so i have the "Arduino code"

You want to know why i want to be able to read the values from the serial in visual basic?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50452
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I can accept that you want to read data from the sensor into the VB application. What I don't understand is why you choose the Firmata sketch as the starting point.

That is like trying to use a potentiometer to dim an LED starting from an Ethernet web server example.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don´t really know what i am doing here, just bought the arduino uno. And i have no programming experience.. All i want is the temperature in my visual basic application.. If i should not use firmata what should i look at then? 

I just thought i was on the right track since i could read the serial, just not weary well.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50452
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the Arduino IDE, there are examples available to load/run/modify. Pick one similar to what you want to do. The Firmata sketch is so far out in left field from where you want to be, and includes so much code that is irrelevant for what you are doing, that it makes it difficult to see what you have added/deleted/bypassed.

The Analog/AnalogInOutSerial example might be a good starting point. See if you can make sense of what that example is doing, and then extend it to include your sensor.
Logged

Pages: [1]   Go Up
Jump to: