[text] Arduino Code

Viewer

copydownloadembedprintName: Arduino Code
  1. #include <Wire.h>
  2. #include <SPI.h>
  3. #include <Servo.h>
  4. #include <HMC5883L.h>
  5. #include "LabVIEWInterface.h" 
  6.  
  7. HMC5883L compass;
  8. int error = 0;
  9.  
  10. unsigned long millis_readsample = 0;    
  11. unsigned long freq_readsample = 100; 
  12.  
  13. /*********************************************************************************
  14.  **  setup()
  15. *********************************************************************************/
  16. void setup()
  17. {  
  18.   // Initialize Serial Port With The Default Baud Rate
  19.   syncLV();
  20.  
  21.   // Place your custom setup code here
  22.   Wire.begin();
  23.   
  24.   compass = HMC5883L(); 
  25.   error = compass.SetScale(1.3); 
  26.   error = compass.SetMeasurementMode(Measurement_Continuous);
  27.   millis_readsample = millis() + freq_readsample;
  28. }
  29.  
  30.  
  31. /*********************************************************************************
  32.  **  loop()
  33. *********************************************************************************/
  34.  
  35. void loop()
  36. {   
  37.   float var;
  38.   
  39.   // Check for commands from LabVIEW and process them.
  40.   checkForCommand();
  41.   
  42.   // Place your custom loop code here (this may slow down communication with LabVIEW)
  43.    if (millis() >= millis_readsample)
  44.   {
  45.     MagnetometerScaled scaled = compass.ReadScaledAxis(); 
  46.     int xScaled = scaled.XAxis;  
  47.     int yScaled = scaled.YAxis;  
  48.        
  49.     serialWriteFloat((float)xScaled);
  50.     serialWriteFloat((float)yScaled);
  51.  
  52.     millis_readsample += freq_readsample;  
  53.   }
  54. }
  55.  
  56. void serialWriteFloat(float arg) 
  57. {
  58.   byte * data = (byte *) &arg; 
  59.   Serial.write (data, sizeof (arg));
  60. }
  61.  

Editor

You can edit this paste and save as new:


File Description
  • Arduino Code
  • Paste Code
  • 24 Jan-2022
  • 1.53 Kb
You can Share it: