LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to merge processing code for HMC5583L and MMA7361C

Ohhh damn it, how do I go about making the combined sketches to work w LIFA and are there any precautions I have to adhere while merging the codes? I'm using the files in .pde format btw.

0 Kudos
Message 11 of 32
(1,812 Views)

There shouldn't be any .pde files when using LIFA.  LIFA uses the newer .ino file extension.

To see how to add custom function, simply look at the existing functions to see how they work.  Then, duplicate one of those function first (with a different command number) in both the firmware and LabVIEW.  If you get that new function working correctly, then you can chang the code to do what you need to do.

0 Kudos
Message 12 of 32
(1,812 Views)

hmm alright ill try my best to work along those lines, thanks for your input Nathan!

I had to use an older version of arduino as the HMC5883L file is of a old make and can only be used with .pde format programs.

0 Kudos
Message 13 of 32
(1,812 Views)

As far as I know, nothing is directly related to the file extension. There

were however significant changes to some functionalities when version 1.0

was released. But the required changes shouldn't be all that hard to make.

If you provide a link to each of the libraries that you are using, I can

see if they will work with LIFA.

0 Kudos
Message 14 of 32
(1,812 Views)

oh haha i was following instructions from my teacher regarding that.

I could not find a link for the HMC5883L library file, ill paste the relavent codes here.

0 Kudos
Message 15 of 32
(1,812 Views)

HMC5883L.cpp:

/*

HMC5883L.cpp - Class file for the HMC5883L Triple Axis Magnetometer Arduino Library.

Copyright (C) 2011 Love Electronics (loveelectronics.co.uk)

This program is free software: you can redistribute it and/or modify

it under the terms of the version 3 GNU General Public License as

published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program.  If not, see <http://www.gnu.org/licenses/>.

WARNING: THE HMC5883L IS NOT IDENTICAL TO THE HMC5883!

Datasheet for HMC5883L:

http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-docu...

*/

#include <WProgram.h>

#include "HMC5883L.h"

HMC5883L::HMC5883L()

{

  m_Scale = 1;

}

MagnetometerRaw HMC5883L::ReadRawAxis()

{

  uint8_t* buffer = Read(DataRegisterBegin, 6);

  MagnetometerRaw raw = MagnetometerRaw();

  raw.XAxis = (buffer[0] << 😎 | buffer[1];

  raw.ZAxis = (buffer[2] << 😎 | buffer[3];

  raw.YAxis = (buffer[4] << 😎 | buffer[5];

  return raw;

}

MagnetometerScaled HMC5883L::ReadScaledAxis()

{

  MagnetometerRaw raw = ReadRawAxis();

  MagnetometerScaled scaled = MagnetometerScaled();

  scaled.XAxis = raw.XAxis * m_Scale;

  scaled.ZAxis = raw.ZAxis * m_Scale;

  scaled.YAxis = raw.YAxis * m_Scale;

  return scaled;

}

int HMC5883L::SetScale(float gauss)

{

          uint8_t regValue = 0x00;

          if(gauss == 0.88)

          {

                    regValue = 0x00;

                    m_Scale = 0.73;

          }

          else if(gauss == 1.3)

          {

                    regValue = 0x01;

                    m_Scale = 0.92;

          }

          else if(gauss == 1.9)

          {

                    regValue = 0x02;

                    m_Scale = 1.22;

          }

          else if(gauss == 2.5)

          {

                    regValue = 0x03;

                    m_Scale = 1.52;

          }

          else if(gauss == 4.0)

          {

                    regValue = 0x04;

                    m_Scale = 2.27;

          }

          else if(gauss == 4.7)

          {

                    regValue = 0x05;

                    m_Scale = 2.56;

          }

          else if(gauss == 5.6)

          {

                    regValue = 0x06;

                    m_Scale = 3.03;

          }

          else if(gauss == 8.1)

          {

                    regValue = 0x07;

                    m_Scale = 4.35;

          }

          else

                    return ErrorCode_1_Num;

 

          // Setting is in the top 3 bits of the register.

          regValue = regValue << 5;

          Write(ConfigurationRegisterB, regValue);

}

int HMC5883L::SetMeasurementMode(uint8_t mode)

{

          Write(ModeRegister, mode);

}

void HMC5883L::Write(int address, int data)

{

  Wire.beginTransmission(HMC5883L_Address);

  Wire.send(address);

  Wire.send(data);

  Wire.endTransmission();

}

uint8_t* HMC5883L::Read(int address, int length)

{

  Wire.beginTransmission(HMC5883L_Address);

  Wire.send(address);

  Wire.endTransmission();

 

  Wire.beginTransmission(HMC5883L_Address);

  Wire.requestFrom(HMC5883L_Address, length);

  uint8_t buffer[length];

  if(Wire.available() == length)

  {

            for(uint8_t i = 0; i < length; i++)

            {

                      buffer = Wire.receive();

            }

  }

  Wire.endTransmission();

  return buffer;

}

char* HMC5883L::GetErrorText(int errorCode)

{

          if(ErrorCode_1_Num == 1)

                    return ErrorCode_1;

 

          return "Error not defined.";

}

0 Kudos
Message 16 of 32
(1,812 Views)

HMC5883L.h:

/*

HMC5883L.h - Header file for the HMC5883L Triple Axis Magnetometer Arduino Library.

Copyright (C) 2011 Love Electronics (loveelectronics.co.uk)

This program is free software: you can redistribute it and/or modify

it under the terms of the version 3 GNU General Public License as

published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program.  If not, see <http://www.gnu.org/licenses/>.

WARNING: THE HMC5883L IS NOT IDENTICAL TO THE HMC5883!

Datasheet for HMC5883L:

http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-docu...

*/

#ifndef HMC5883L_h

#define HMC5883L_h

#include <inttypes.h>

#include "../Wire/Wire.h"

#define HMC5883L_Address 0x1E

#define ConfigurationRegisterA 0x00

#define ConfigurationRegisterB 0x01

#define ModeRegister 0x02

#define DataRegisterBegin 0x03

#define Measurement_Continuous 0x00

#define Measurement_SingleShot 0x01

#define Measurement_Idle 0x03

#define ErrorCode_1 "Entered scale was not valid, valid gauss values are: 0.88, 1.3, 1.9, 2.5, 4.0, 4.7, 5.6, 8.1"

#define ErrorCode_1_Num 1

struct MagnetometerScaled

{

          float XAxis;

          float YAxis;

          float ZAxis;

};

struct MagnetometerRaw

{

          int XAxis;

          int YAxis;

          int ZAxis;

};

class HMC5883L

{

          public:

            HMC5883L();

            MagnetometerRaw ReadRawAxis();

            MagnetometerScaled ReadScaledAxis();

 

            int SetMeasurementMode(uint8_t mode);

            int SetScale(float gauss);

            char* GetErrorText(int errorCode);

          protected:

            void Write(int address, int byte);

            uint8_t* Read(int address, int length);

          private:

            float m_Scale;

};

#endif

0 Kudos
Message 17 of 32
(1,812 Views)

Untitled.png

This is the errors i get when attempting to use the .ino format

0 Kudos
Message 18 of 32
(1,812 Views)
0 Kudos
Message 19 of 32
(1,812 Views)

Could you please attach the files or provide a link to where you got them?

0 Kudos
Message 20 of 32
(1,812 Views)