ni.com checkout is currently experiencing issues.

Support teams are actively working on the resolution.

LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino and Dallas DS1820 (one-wire)

Solved!
Go to solution

I am trying to get this work also.  However, I have not been able to yet.  I am getting error 5003 when it is running.

0 Kudos
Message 21 of 172
(3,925 Views)

IIRC, to prevent this (in many cases) make sure you never use the "Abort Execution" button when running anything with LIFA.

If restarting everything doesn't help, are you able to use the blink example with the Arduino?

0 Kudos
Message 22 of 172
(3,925 Views)

Hi everyone!

It was not obligatory for me to use the DS1820 to measure temperature, so to give a fast solution to that issue, I simply used a thermistor in one of the analogic input.

Anyway I hope this thread finishes with a clear and complete solution for the DS1820. (I think it is by far a much better sensor than a simple thermistor)

If there is anyone interested to see my first LabVIEW program, I can attach the link to the video in another message.

DMDsync
0 Kudos
Message 23 of 172
(3,925 Views)

Hi guys!

DMDsync: please, send the video!
I'm trying use the DS1820 but I can't!

I'm looking for another solution..

Thanks!

0 Kudos
Message 24 of 172
(3,925 Views)

Hi guys!

Someone could use the Dallas DS1820 (one-wire) with arduino?

I tried as in the tutorial, but it did not work

I had to re-install my LIFA

Thanks

0 Kudos
Message 25 of 172
(3,925 Views)

Hey lucagvf2!!

I forgot to mention that the video is in spanish so I'm not sure if it will be of help to you. I used a simple LM35 to suit my goals. The purpose of the video was to show my first LabVIEW program, and what I was able to measure (I also could store some data on an excel file). It is not a tutorial of how to make the program.

Anyway if you still think it would be helpful for you, I will copy the link.

Refering to the question in your second message, I can say that I was able to use the DS1820 together with Arduino but not with LIFA. I was able to adapt an example of a serial comunication to send the data from the DS1820 to LabVIEW.

I hope you can find the way to fully interface the DS1820 with LabVIEW using LIFA.

best regards!

DMDsync
0 Kudos
Message 26 of 172
(3,925 Views)

Hi there,

I also tried to get the Dallas DS1820 working (and it works perfectly when using the Dallas Temp Sensor Library) but I don't get it running with LVIFA. I followed the instructions and modified both LVIFA_Base.pde (ino) and LabviewInterface.h.Please find attached the codes and the vi.

Please help - I spent a week after-work-playing-around and I still don't get it...

Thanks heaps!

Daniel

Dallas VI.png

/*********************************************************************************

**

**  LVFA_Firmware - Provides Basic Arduino Sketch For Interfacing With LabVIEW.

**

**  Written By:    Sam Kristoff - National Instruments

**  Written On:    November 2010

**  Last Updated:  Dec 2011 - Kevin Fort - National Instruments

**

**  This File May Be Modified And Re-Distributed Freely. Original File Content

**  Written By Sam Kristoff And Available At www.ni.com/arduino.

**

*********************************************************************************/

/*********************************************************************************

**

** Includes.

**

********************************************************************************/

// Standard includes.  These should always be included.

#include <Wire.h>

#include <SPI.h>

#include <Servo.h>

#include <OneWire.h>

#include <TFT_Graphics.h>

#include "LabVIEWInterface.h"

/*********************************************************************************

**  setup()

**

**  Initialize the Arduino and setup serial communication.

**

**  Input:  None

**  Output: None

*********************************************************************************/

void setup()

  // Initialize Serial Port With The Default Baud Rate

  syncLV();

  // Place your custom setup code here

 

}

/*********************************************************************************

**  loop()

**

**  The main loop.  This loop runs continuously on the Arduino.  It

**  receives and processes serial commands from LabVIEW.

**

**  Input:  None

**  Output: None

*********************************************************************************/

void loop()

{  

  // Check for commands from LabVIEW and process them.  

  checkForCommand();

  // Place your custom loop code here (this may slow down communication with LabVIEW)

 

  if(acqMode==1)

  {

    sampleContinously();

  }

}

/*********************************************************************************

**

**  LVIFA_Firmware - Provides Functions For Interfacing With The Arduino Uno

**

**  Written By:    Sam Kristoff - National Instruments

**  Written On:    November 2010

**  Last Updated:  Dec 2011 - Kevin Fort - National Instruments

**

**  This File May Be Modified And Re-Distributed Freely. Original File Content

**  Written By Sam Kristoff And Available At www.ni.com/arduino.

**

*********************************************************************************/

#include <Wire.h>

#include <SPI.h>

#include <LiquidCrystal.h>

#include <TFT_Graphics.h>

#include <OneWire.h>

// Variables

unsigned int retVal;

//int sevenSegmentPins[8];

int currentMode;

unsigned int freq;

unsigned long duration;

int i2cReadTimeouts = 0;

char spiBytesToSend = 0;

char spiBytesSent = 0;

char spiCSPin = 0;

char spiWordSize = 0;

//Servo *servos;

byte customChar[8];

LiquidCrystal lcd(0,0,0,0,0,0,0);

// Sets the mode of the Arduino (Reserved For Future Use)

void setMode(int mode)

{

  currentMode = mode;

}

// Checks for new commands from LabVIEW and processes them if any exists.

int checkForCommand(void)

#ifdef STEPPER_SUPPORT

  // Call run function as fast as possible to keep motors turning

  for (int i=0; i<8; i++){

   // steppers.run();

  }

#endif

  int bufferBytes = Serial.available();

  if(bufferBytes >= COMMANDLENGTH)

  {

    // New Command Ready, Process It 

    // Build Command From Serial Buffer

    for(int i=0; i<COMMANDLENGTH; i++)

    {

      currentCommand = Serial.read();      

    }    

    processCommand(currentCommand);    

    return 1;

  }

  else

  {

    return 0;

  }

}

// Processes a given command

void processCommand(unsigned char command[])

  // Determine Command

  if(command[0] == 0xFF && checksum_Test(command) == 0)

  {

    switch(command[1])

    {   

    /*********************************************************************************

    ** LIFA Maintenance Commands

    *********************************************************************************/

    case 0x00:     // Sync Packet

      Serial.print("sync");

      Serial.flush();       

      break;

    case 0x01:    // Flush Serial Buffer 

      Serial.flush();

      break;

     

    /*********************************************************************************

    ** Low Level - Digital I/O Commands

    *********************************************************************************/

    case 0x02:    // Set Pin As Input Or Output     

      pinMode(command[2], command[3]);

      Serial.write('0');

      break;

    case 0x03:    // Write Digital Pin

      digitalWrite(command[2], command[3]);

       Serial.write('0');

      break;

    case 0x04:    // Write Digital Port 0

      writeDigitalPort(command);

       Serial.write('0');

      break;

    case 0x05:    //Tone         

      freq = ( (command[3]<<8) + command[4]);

      duration=(command[8]+  (command[7]<<8)+ (command[6]<<16)+(command[5]<<24));  

  

      if(freq > 0)

      {

        tone(command[2], freq, duration);

      }

      else

      {

        noTone(command[2]);

      }   

       Serial.write('0');

      break;

    case 0x06:    // Read Digital Pin

      retVal = digitalRead(command[2]); 

      Serial.write(retVal);   

      break;

    case 0x07:    // Digital Read Port

      retVal = 0x0000;

      for(int i=0; i <=13; i++)

      {

        if(digitalRead(i))

        {

          retVal += (1<<i);

        }

      }

      Serial.write( (retVal & 0xFF));

      Serial.write( (retVal >> 8));   

      break;

     

    /*********************************************************************************

    ** Low Level - Analog Commands

    *********************************************************************************/

    case 0x08:    // Read Analog Pin   

      retVal = analogRead(command[2]);

      Serial.write( (retVal >> 8));

      Serial.write( (retVal & 0xFF));

      break;

    case 0x09:    // Analog Read Port

      analogReadPort();

      break;

     

    /*********************************************************************************

    ** Low Level - PWM Commands

    *********************************************************************************/     

    case 0x0A:    // PWM Write Pin

      analogWrite(command[2], command[3]);

       Serial.write('0');

      break;

    case 0x0B:    // PWM Write 3 Pins

      analogWrite(command[2], command[5]);

      analogWrite(command[3], command[6]);

      analogWrite(command[4], command[7]);

       Serial.write('0');

      break;

     

    /*********************************************************************************

    ** Sensor Specific Commands

    *********************************************************************************/     

    //case 0x0C:    // Configure Seven Segment Display

      //sevenSegment_Config(command);

      // Serial.write('0');

      //break;

    //case 0x0D:    // Write To Seven Segment Display

     // sevenSegment_Write(command);

      // Serial.write('0');

      //break;

     

    /*********************************************************************************

    **  I2C

    *********************************************************************************/

    case 0x0E:    // Initialize I2C

      Wire.begin();

       Serial.write('0');

      break;

    case 0x0F:    // Send I2C Data

      Wire.beginTransmission(command[3]);

      for(int i=0; i<command[2]; i++)

      {

        #if defined(ARDUINO) && ARDUINO >= 100

          Wire.write(command[i+4]);

        #else

          Wire.send(command[i+4]);

        #endif

       

      }

      Wire.endTransmission();

       Serial.write('0');  

      break;

    case 0x10:    // I2C Read 

      i2cReadTimeouts = 0;

      Wire.requestFrom(command[3], command[2]);

      while(Wire.available() < command[2])

      {

        i2cReadTimeouts++;

        if(i2cReadTimeouts > 100)

        {

          return;

        }

        else

        {

          delay(1);

        }

      }

      for(int i=0; i<command[2]; i++)

      {

        #if defined(ARDUINO) && ARDUINO >= 100

          Serial.write(Wire.read());

        #else

          Serial.write(Wire.receive());

        #endif

       

      }

      break;

     

    /*********************************************************************************

    ** SPI

    *********************************************************************************/     

    case 0x11:    // SPI Init

      SPI.begin();

       Serial.write('0');

      break;

    case 0x12:    // SPI Set Bit Order (MSB LSB)

      if(command[2] == 0)

      {

        SPI.setBitOrder(LSBFIRST);

      }

      else

      {

        SPI.setBitOrder(MSBFIRST);

      } 

       Serial.write('0'); 

      break;

    case 0x13:    // SPI Set Clock Divider

      spi_setClockDivider(command[2]);

       Serial.write('0');

      break;

    case 0x14:    // SPI Set Data Mode

      switch(command[2])

      {

      case 0:

        SPI.setDataMode(SPI_MODE0);

        break; 

      case 1:

        SPI.setDataMode(SPI_MODE1);

        break;

      case 2:

        SPI.setDataMode(SPI_MODE2);

        break;

      case 3:

        SPI.setDataMode(SPI_MODE3);

        break;

      default:       

        break;

      }   

       Serial.write('0');

      break;

    case 0x15:  // SPI Send / Receive

      spi_sendReceive(command);

      break;

    case 0x16:  // SPI Close

      SPI.end();

       Serial.write('0'); 

      break;

     

    /*********************************************************************************

    ** Servos

    *********************************************************************************/     

   // case 0x17:  // Set Num Servos

    //  free(servos);

    //  servos = (Servo*) malloc(command[2]*sizeof(Servo));

    //  for(int i=0; i<command[2]; i++)

    //  {

    //    servos = Servo();

    //  }

     // if(servos == 0)

     // {

    //    Serial.write('1');

    //  }

    //  else

    //  {

    //     Serial.write('0');

    //  }

    //  break;

    case 0x18:  // Configure Servo

     // servos[command[2]].attach(command[3]);

     //  Serial.write('0');

      break;

    case 0x19:  // Servo Write

     // servos[command[2]].write(command[3]);

     //  Serial.write('0');

      break;

    case 0x1A:  // Servo Read Angle

    //  Serial.write(servos[command[2]].read());

      break;

    case 0x1B:  // Servo Write uS Pulse

    //  servos[command[2]].writeMicroseconds( (command[3] + (command[4]<<8)) );

     //  Serial.write('0');

      break;

    case 0x1C:  // Servo Read uS Pulse

   //   retVal = servos[command[2]].readMicroseconds();

    //  Serial.write ((retVal & 0xFF));

    //  Serial.write( (retVal >> 8));

      break;

    case 0x1D:  // Servo Detach

   //   servos[command[2]].detach();

    //   Serial.write('0');

      break;

     /*********************************************************************************

         **                                      LCD

         *********************************************************************************/ 

   

    case 0x41: // color command HEX code

  

        initialize(LCD_HORIZONTAL);

        ClearScreen(BLACK);

        break;

   

     

       

    case 0x1E:  // LCD Init

        lcd.init(command[2], command[3], command[4], command[5], command[6], command[7], command[8], command[9], command[10], command[11], command[12], command[13]);

      

        Serial.write('0');

        break;

      case 0x1F:  // LCD Set Size

        lcd.begin(command[2], command[3]);

        Serial.write('0');

        break;

      case 0x20:  // LCD Set Cursor Mode

        if(command[2] == 0)

        {

          lcd.noCursor();

        }

        else

        {

          lcd.cursor();

        }

        if(command[3] == 0)

        {

          lcd.noBlink();

        }

        else

        {

          lcd.blink();

        }

        Serial.write('0');

        break;

      case 0x21:  // LCD Clear

        lcd.clear();

        Serial.write('0');

        break;

      case 0x22:  // LCD Set Cursor Position

        lcd.setCursor(command[2], command[3]);

        Serial.write('0');

        break;

      case 0x23:  // LCD Print

        lcd_print(command);       

        break;

      case 0x24:  // LCD Display Power

        if(command[2] == 0)

        {

          lcd.noDisplay();

        }

        else

        {

          lcd.display();

        }

        Serial.write('0');

        break;

      case 0x25:  // LCD Scroll

        if(command[2] == 0)

        {

          lcd.scrollDisplayLeft();

        }

        else

        {

          lcd.scrollDisplayRight();

        }

        Serial.write('0');

        break;

      case 0x26: //  LCD Autoscroll

        if(command[2] == 0)

        {

          lcd.noAutoscroll();

        }

        else

        {

          lcd.autoscroll();

        }

        Serial.write('0');

        break;

      case 0x27: // LCD Print Direction

        if(command[2] == 0)

        {

          lcd.rightToLeft();

        }

        else

        {

          lcd.leftToRight();

        }

        Serial.write('0');

        break;

      case 0x28: // LCD Create Custom Char

        for(int i=0; i<8; i++)

        {

          customChar = command[i+3];

        }     

        lcd.createChar(command[2], customChar);

       

        Serial.write('0');

        break;

      case 0x29:  // LCD Print Custom Char

        lcd.write(command[2]);

        Serial.write('0');

        break;

           

       

    /*********************************************************************************

    ** Continuous Aquisition

    *********************************************************************************/       

      case 0x2A:  // Continuous Aquisition Mode On

        acqMode=1;

        contAcqPin=command[2];

        contAcqSpeed=(command[3])+(command[4]<<8); 

        acquisitionPeriod=1/contAcqSpeed;

        iterationsFlt =.08/acquisitionPeriod;

        iterations=(int)iterationsFlt;

        if(iterations<1)

        {

          iterations=1;

        }

        delayTime= acquisitionPeriod;

       if(delayTime<0)

       {

         delayTime=0;

       }  

        break;  

      case 0x2B:  // Continuous Aquisition Mode Off

        acqMode=0;     

        break; 

     case 0x2C:  // Return Firmware Revision

         Serial.write(byte(FIRMWARE_MAJOR)); 

         Serial.write(byte(FIRMWARE_MINOR));  

        break; 

     case 0x2D:  // Perform Finite Aquisition

         Serial.write('0');

         finiteAcquisition(command[2],(command[3])+(command[4]<<8),command[5]+(command[6]<<8));

        break;  

    /*********************************************************************************

    ** Stepper

    *********************************************************************************/       

//   #ifdef STEPPER_SUPPORT

  //    case 0x30:  // Configure Stepper

  //      if (command[2] == 5){    // Support AFMotor Shield

  //        switch (command[3]){

   //       case 0:

   //         steppers[command[3]] = AccelStepper(forwardstep1, backwardstep1);

   //         break;

   //       case 1:

   //         steppers[command[3]] = AccelStepper(forwardstep2, backwardstep2);

   //         break;

   //       default:

   //         break;

   //       }

    //    }

     //   else if(command[2]==6) {                   // All other stepper configurations

     //     steppers[command[3]] = AccelStepper(1, command[4],command[5],command[6],command[7]);      

     //   }  

     //   else{

     //     steppers[command[3]] = AccelStepper(command[2], command[4],command[5],command[6],command[7]);

      //  } 

      //   Serial.write('0');

     //   break;

     // case 0x31:  // Stepper Write

     //   AccelStepper_Write(command);

     //    Serial.write('0');

     //   break;

     // case 0x32:  // Stepper Detach

     //   steppers[command[2]].disableOutputs();

     //    Serial.write('0');

     //   break;

     // case 0x33:  // Stepper steps to go

     //   retVal = 0;

     //   for(int i=0; i<8; i++){

     //     retVal += steppers.distanceToGo();

     //   }

      //  Serial.write( (retVal & 0xFF) );

      //  Serial.write( (retVal >> 😎 );

 

    //    break;

   // #endif

case 0x42:  // OneWire Read

       

        OneWire_Read();

        break;

    /*********************************************************************************

    ** Unknown Packet

    *********************************************************************************/

    default:      // Default Case

      Serial.flush();

      break;    

    }

  }

  else{ 

    // Checksum Failed, Flush Serial Buffer

    Serial.flush();

  }  

}

/*********************************************************************************

**  Functions

*********************************************************************************/

//void ini_and_send_color()

//{

//  tft.initialize(LCD_HORIZONTAL);

//  delay(5000);

//  tft.ClearScreen(BLACK); //Send color BLACK

//  delay(5000);

//}

// Writes Values To Digital Port (DIO 0-13).  Pins Must Be Configured As Outputs Before Being Written To

void writeDigitalPort(unsigned char command[])

{

  digitalWrite(13, (( command[2] >> 5) & 0x01) );

  digitalWrite(12, (( command[2] >> 4) & 0x01) );

  digitalWrite(11, (( command[2] >> 3) & 0x01) );

  digitalWrite(10, (( command[2] >> 2) & 0x01) );

  digitalWrite(9, (( command[2] >> 1) & 0x01) );

  digitalWrite(8, (command[2] & 0x01) );

  digitalWrite(7, (( command[3] >> 7) & 0x01) );

  digitalWrite(6, (( command[3] >> 6) & 0x01) );

  digitalWrite(5, (( command[3] >> 5) & 0x01) );

  digitalWrite(4, (( command[3] >> 4) & 0x01) );

  digitalWrite(3, (( command[3] >> 3) & 0x01) );

  digitalWrite(2, (( command[3] >> 2) & 0x01) );

  digitalWrite(1, (( command[3] >> 1) & 0x01) );

  digitalWrite(0, (command[3] & 0x01) );

}

// Reads all 6 analog input ports, builds 8 byte packet, send via RS232.

void analogReadPort()

{

  // Read Each Analog Pin

  int pin0 = analogRead(0);

  int pin1 = analogRead(1);

  int pin2 = analogRead(2);

  int pin3 = analogRead(3);

  int pin4 = analogRead(4);

  int pin5 = analogRead(5);

  //Build 8-Byte Packet From 60 Bits of Data Read

  char output0 = (pin0 & 0xFF);  

  char output1 = ( ((pin1 << 2) & 0xFC) | ( (pin0 >> 😎 & 0x03) );

  char output2 = ( ((pin2 << 4) & 0xF0) | ( (pin1 >> 6) & 0x0F) );

  char output3 = ( ((pin3 << 6) & 0xC0) | ( (pin2 >> 4) & 0x3F) );   

  char output4 = ( (pin3 >> 2) & 0xFF);   

  char output5 = (pin4 & 0xFF);

  char output6 = ( ((pin5 << 2) & 0xFC) | ( (pin4 >> 😎 & 0x03) );

  char output7 = ( (pin5 >> 6) & 0x0F );

  // Write Bytes To Serial Port

  Serial.print(output0);

  Serial.print(output1);

  Serial.print(output2);

  Serial.print(output3);

  Serial.print(output4);

  Serial.print(output5);

  Serial.print(output6);

  Serial.print(output7);

}

// Configure digital I/O pins to use for seven segment display

//void sevenSegment_Config(unsigned char command[])

//{

  // Configure pins as outputs and store in sevenSegmentPins array for use in sevenSegment_Write

  //for(int i=2; i<10; i++)

  //{

    //pinMode(command, OUTPUT);

    //sevenSegmentPins[(i-1)] = command;

  //} 

//}

//  Write values to sevenSegment display.  Must first use sevenSegment_Configure

//void sevenSegment_Write(unsigned char command[])

//{

  //for(int i=1; i<9; i++)

  //{

    //digitalWrite(sevenSegmentPins[(i-1)], command);

  //}

//}

// Set the SPI Clock Divisor

void spi_setClockDivider(unsigned char divider)

{

  switch(divider)

  {

  case 0:

    SPI.setClockDivider(SPI_CLOCK_DIV2);

    break;

  case 1:

    SPI.setClockDivider(SPI_CLOCK_DIV4);

    break;

  case 2:

    SPI.setClockDivider(SPI_CLOCK_DIV8);

    break;

  case 3:

    SPI.setClockDivider(SPI_CLOCK_DIV16);

    break;

  case 4:

    SPI.setClockDivider(SPI_CLOCK_DIV32);

    break;

  case 5:

    SPI.setClockDivider(SPI_CLOCK_DIV64);

    break;

  case 6:

    SPI.setClockDivider(SPI_CLOCK_DIV128);

    break;

  default:

    SPI.setClockDivider(SPI_CLOCK_DIV4);

    break;

  } 

}

void spi_sendReceive(unsigned char command[])

{

  if(command[2] == 1)        //Check to see if this is the first of a series of SPI packets

  {

    spiBytesSent = 0;

    spiCSPin = command[3];   

    spiWordSize = command[4];                   

    // Send First Packet's 8 Data Bytes

    for(int i=0; i<command[5]; i++)

    {

      // If this is the start of a new word toggle CS LOW

      if( (spiBytesSent == 0) || (spiBytesSent % spiWordSize == 0) )

      {             

        digitalWrite(spiCSPin, LOW);               

      }

      // Send SPI Byte

      Serial.print(SPI.transfer(command[i+6]));    

      spiBytesSent++; 

      // If word is complete set CS High

      if(spiBytesSent % spiWordSize == 0)

      {

        digitalWrite(spiCSPin, HIGH);                 

      }

    }

  }

  else

  {

    // SPI Data Packet - Send SPI Bytes

    for(int i=0; i<command[3]; i++)

    {

      // If this is the start of a new word toggle CS LOW

      if( (spiBytesSent == 0) || (spiBytesSent % spiWordSize == 0) )

      {             

        digitalWrite(spiCSPin, LOW);               

      }

      // Send SPI Byte

      Serial.write(SPI.transfer(command[i+4]));    

      spiBytesSent++; 

      // If word is complete set CS High

      if(spiBytesSent % spiWordSize == 0)

      {

        digitalWrite(spiCSPin, HIGH);                 

      }

    }

  }

}

// Synchronizes with LabVIEW and sends info about the board and firmware (Unimplemented)

void syncLV()

{

  Serial.begin(DEFAULTBAUDRATE);

  i2cReadTimeouts = 0;

  spiBytesSent = 0;

  spiBytesToSend = 0;

  Serial.flush();

}

// Compute Packet Checksum

unsigned char checksum_Compute(unsigned char command[])

{

  unsigned char checksum;

  for (int i=0; i<(COMMANDLENGTH-1); i++)

  {

    checksum += command;

  }

  return checksum;

}

// Compute Packet Checksum And Test Against Included Checksum

int checksum_Test(unsigned char command[])

{

  unsigned char checksum = checksum_Compute(command);

  if(checksum == command[COMMANDLENGTH-1])

  {

    return 0;

  }

  else

  {

    return 1;

  }

}

// Stepper Functions

//#ifdef STEPPER_SUPPORT

  //void AccelStepper_Write(unsigned char command[]){

//   int steps = 0;

//   int step_speed = 0;

//   int acceleration = 0;

 

    //Number of steps & speed are a 16 bit values, split for data transfer. Reassemble 2 bytes to an int 16

  //  steps = (int)(command[5] << 😎 + command[6];

  //  step_speed = (int)(command[2] << 😎 + command[3];

  //  acceleration = (int)(command[7] << 😎 + command[8];

 

  //  steppers[command[4]].setMaxSpeed(step_speed);

 

  //  if (acceleration == 0){

      //Workaround AccelStepper bug that requires negative speed for negative step direction

  //    if (steps < 0) step_speed = -step_speed;

  //    steppers[command[4]].setSpeed(step_speed);

  //    steppers[command[4]].move(steps);

  //  }

  //  else {

  //    steppers[command[4]].setAcceleration(acceleration);

  //    steppers[command[4]].move(steps);

  //  }

// }

//#endif

void sampleContinously()

{

  

  for(int i=0; i<iterations; i++)

  {

     retVal = analogRead(contAcqPin);

     if(contAcqSpeed>1000) //delay Microseconds is only accurate for values less that 16383

     {

       Serial.write( (retVal >> 2));

       delayMicroseconds(delayTime*1000000); //Delay for neccesary amount of time to achieve desired sample rate   

     }

     else

     {

        Serial.write( (retVal & 0xFF) );

        Serial.write( (retVal >> 8));  

        delay(delayTime*1000);

     }

  }

}

void finiteAcquisition(int analogPin, float acquisitionSpeed, int numberOfSamples)

{

  //want to exit this loop every 8ms

   acquisitionPeriod=1/acquisitionSpeed;

  

  for(int i=0; i<numberOfSamples; i++)

  {

     retVal = analogRead(analogPin);

   

     if(acquisitionSpeed>1000)

     {

       Serial.write( (retVal >> 2));

       delayMicroseconds(acquisitionPeriod*1000000);

     }

     else

     {

       Serial.write( (retVal & 0xFF) );

       Serial.write( (retVal >> 8));

       delay(acquisitionPeriod*1000);

     }

  }

}

void lcd_print(unsigned char command[])

{

  if(command[2] != 0)

  {         

    // Base Specified By User

    int base = 0;

    switch(command[2])

    {

      case 0x01:  // BIN

        base = BIN;

        break;

      case 0x02:  // DEC

        base = DEC;

        break;

      case 0x03:  // OCT

        base = OCT;

        break;

      case 0x04:  // HEX

        base = HEX;

        break;

      default:

        break;

    }

    for(int i=0; i<command[3]; i++)

    {

      lcd.print(command[i+4], base);

    }

  }

  else

  {

   

    for(int i=0; i<command[3]; i++)

    {

      lcd.print((char)command[i+4]);

   

    }

  }

  Serial.write('0');

}

void initialize(uint8_t orient)

{

    LCD::SetOrientation(orient);

    LCD::SetColor(WHITE);

    LCD::init();

    }

void ClearScreen(uint16_t color)

{

   

    LCD::resetArea();

    LCD::fill(LCD::GetWidth()-1, LCD::GetHeight()-1, color);

}

 

void OneWire_Read()// Funcion para leer desde el sensor DS1820

  OneWire ds(2);          // Create a OneWire Object "ds" on pin 2.  Hard coding for now, because I can't declare this in a case.

  byte OneWireData[9];    // Defining stuff for the added OneWire function because I'm getting irritated with trying to make this fit into a case or function.

  int Fract, Whole, Tc_100, SignBit, TReading;

    // Start the Conversion

    ds.reset();      // Reset the OneWire bus in preparation for communication

    ds.skip();       // Skip addressing, since there is only one sensor

    ds.write(0x44);  // Send 44, the conversion command

  // Wait for the Conversion

    delay(1000);     // Wait for the conversion to complete

  // Read back the data

    ds.reset();                      // Reset the OneWire bus in preparation for communication

    ds.skip();                       // Skip addressing, since there is only one sensor

    ds.write(0xBE);                  // Send the "Read Scratchpad" command

    for ( byte i = 0; i < 9; i++) {

      OneWireData = ds.read();    // Read the 9 bytes into data[]

    }

  // Scale the data

    TReading = (OneWireData[1] << 😎 + OneWireData[0];

    SignBit = TReading & 0x8000;               // Mask out all but the MSB

    if (SignBit)                                   // If the MSB is negative, take the Two's Compliment to make the reading negative

    {

      TReading = (TReading ^ 0xffff) + 1;          // 2's comp

    }

    Tc_100 = (6 * TReading) + TReading / 4;    // Scale by the sensitivity (0.0625°C per bit) and 100

    Whole = Tc_100 / 100;                      // Split out the whole number portion of the reading

    Fract = Tc_100 % 100;                      // Split out the fractional portion of the reading

  // Return the data serially

    if (SignBit) {              // If the reading is negative, print a negative sign

      Serial.print("-");

    }

    Serial.print(Whole);        // Print the whole number portion and a decimal

    Serial.print(".");

    if (Fract < 10) {            // if the fraction portion is less than .1, append a 0 decimal

      Serial.print("0");

    }

    Serial.print(Fract);        // Otherwise print the fractional portion

}

0 Kudos
Message 27 of 172
(3,925 Views)

Hi, has anyone found a solution? a step by step tutorial to use arduino and this probe?

Thank you.

0 Kudos
Message 28 of 172
(3,925 Views)

The solution is in posts 5 and 6.  However, it was written for an older verison of LIFA so you will need to manually insert the new code and appropriately change the command reference number in the firmware code that you add and the LabVIEW VI from post 6.

If you are still unable to figure it out, post your modified firmware code and your VI and I will try to see if I can find anything wrong with it.

0 Kudos
Message 29 of 172
(3,925 Views)

Nathan_B, Thanks for the reply. I am a beginner with arduino. I will send the files I changed. I do not send you the VI because i have this error:

LabVIEWInterface.ino: In function 'void processCommand(unsigned char*)':

LabVIEWInterface.ino:150: warning: left shift count >= width of type

LabVIEWInterface.ino:150: warning: left shift count >= width of type

LabVIEWInterface:362: error: 'OneWire_Read' was not declared in this scope

LabVIEWInterface:363: error: expected `;' before 'break'

at :

     /*********************************************************************************

         **                                      Temp

         *********************************************************************************/ 

     case 0x1E:  // OneWire Read

        OneWire_Read()

     break;    

0 Kudos
Message 30 of 172
(3,925 Views)