Advertisement
Guest User

Untitled

a guest
May 10th, 2017
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.97 KB | None | 0 0
  1. /*
  2.  * Demo sketch for new "PLX DAQ v2"
  3.  * including most all common commands to be used
  4.  */
  5.  
  6. int i = 0;
  7. #include <OneWire.h>
  8. #include <DallasTemperature.h>
  9. #define ONE_WIRE_BUS_PIN 2
  10. OneWire oneWire(ONE_WIRE_BUS_PIN);
  11. DallasTemperature sensors(&oneWire);
  12.  
  13. DeviceAddress Probe01 = { 0x28, 0xFF, 0x73, 0x01, 0xA2, 0x16, 0x05, 0x24 }; // 1
  14. DeviceAddress Probe02 = { 0x28, 0xFF, 0xA4, 0xF0, 0xA1, 0x16, 0x05, 0x31 }; // 2
  15. DeviceAddress Probe03 = { 0x28, 0xFF, 0x99, 0x10, 0xA2, 0x16, 0x05, 0xF4 }; // 3
  16. DeviceAddress Probe04 = { 0x28, 0xFF, 0x4A, 0x0A, 0xA2, 0x16, 0x05, 0xC7 }; // 4
  17.  
  18. void setup() {
  19.  
  20.   // open serial connection
  21.     Serial.begin(9600);
  22.  
  23.     //Serial.println("CLEARDATA"); // clears sheet starting at row 2
  24.     Serial.println("CLEARSHEET"); // clears sheet starting at row 1
  25.    
  26.   // define columns
  27.     Serial.println("LABEL,Temp1,Temp2,Temp3,Temp4");
  28.  
  29.   // set the names for the 3 checkboxes
  30.     Serial.println("CUSTOMBOX1,LABEL,Stop logging at 250?");
  31.     Serial.println("CUSTOMBOX2,LABEL,Resume log at 350?");
  32.     Serial.println("CUSTOMBOX3,LABEL,Quit at 450?");
  33.  
  34.   // check 2 of the 3 checkboxes (first two to true, third to false)
  35.     Serial.println("CUSTOMBOX1,SET,1");
  36.     Serial.println("CUSTOMBOX2,SET,1");
  37.     Serial.println("CUSTOMBOX3,SET,0");
  38.   /*-----( Temp Probe Setup )-----*/
  39.   sensors.begin();
  40.   sensors.setResolution(Probe01, 10);
  41.   sensors.setResolution(Probe02, 10);
  42.   sensors.setResolution(Probe03, 10);
  43.   sensors.setResolution(Probe04, 10);
  44. }
  45.  
  46. void loop() {
  47. /*-----( Temp Probe Loop )-----*/
  48.   sensors.requestTemperatures();
  49.   getTemp(Probe01);
  50.   getTemp(Probe02);
  51.   getTemp(Probe03);
  52.   getTemp(Probe04);
  53.     // simple print out of number and millis. Output e.g.,: "DATA,DATE,TIME,TIMER,4711,13374"
  54.         Serial.print("DATA,Temp1,Temp2,Temp3,Temp4");
  55.         Serial.print(sensors.getTempC(Probe01));
  56.         Serial.print(",");
  57.         Serial.print(sensors.getTempC(Probe02));
  58.         Serial.print(",");
  59.         Serial.print(sensors.getTempC(Probe03));
  60.         Serial.print(",");
  61.         Serial.print(sensors.getTempC(Probe04));
  62.         Serial.print(",");
  63.         Serial.println("SCROLLDATA_20");
  64.  
  65.     // clear some cells in Excel (rectangle range from B10 to D20)
  66.       if(i==100)
  67.         Serial.println("ClearRange,B,10,D,20");
  68.  
  69.     // do a simple beep in Excel on PC
  70.       if(i==150)
  71.         Serial.println("BEEP");
  72.  
  73.     // read a value (in this case integer) from Excel (from a sheet by name)
  74.       if(i==200)
  75.       {
  76.         Serial.println("CELL,GET,FROMSHEET,Simple Data,E,4"); // ==> request value from sheet
  77.           // Serial.println("CELL,GET,E4"); ==> short version to read from active sheet in Excel
  78.         int readvalue = Serial.readStringUntil(10).toInt(); // get response. Note: the '10' is important! Always use but never change ;-)
  79.         Serial.println( (String) "Value of cell E4 is: " + readvalue); // result displayed in Excel DirectDebugWindow to double check
  80.       }
  81.  
  82.     // check value of custombox1 on PLX DAQ in Excel and if
  83.     // checkbox is checked then send the command to pause logging
  84.       if(i==250)
  85.       {
  86.         Serial.println("CUSTOMBOX1,GET");
  87.         int stoplogging = Serial.readStringUntil(10).toInt();
  88.         // this information can be seen in the direct debug window on PLX DAQ in Excel
  89.         Serial.println( (String) "Value of stoplogging/checkbox is: " + stoplogging);
  90.         if(stoplogging)
  91.           Serial.println("PAUSELOGGING");
  92.       }
  93.  
  94.     // get a true random number from the computer
  95.       if(i==300)
  96.       {
  97.         Serial.println("GETRANDOM,-4321,12345"); // between -4321 to 12345
  98.         int rndseed = Serial.readStringUntil(10).toInt();
  99.         Serial.println( (String) "Got random value '" + rndseed + "' from Excel" );
  100.         // Note: this information is not posted to the Excel sheet because "DATA" is missing
  101.         // instead this information can be seen in the direct debug window
  102.       }
  103.  
  104.     // and now resume logging
  105.       if(i==350)
  106.       {
  107.         Serial.println("CUSTOMBOX2,GET");
  108.         int resumelogging = Serial.readStringUntil(10).toInt();
  109.         if(resumelogging)
  110.           Serial.println("RESUMELOGGING");
  111.       }  
  112.  
  113.     // post to specific cells on default sheet as well as named sheet
  114.       if(i==400)
  115.       {
  116.         Serial.println("CELL,SET,G10,400 test 1 string"); // default sheet active in PLX DAQ Excel
  117.         Serial.println("CELL,SET,ONSHEET,Simple Data,G,11,400 test 2 string"); // named sheet available in PLX DAQ Excel
  118.       }
  119.        
  120.     // and for forced quit of Excel with saving the file first
  121.       if(i==450)
  122.       {
  123.         Serial.println("CUSTOMBOX3,GET");
  124.         if(Serial.readStringUntil(10).toInt()) {
  125.           Serial.println("SAVEWORKBOOKAS,450-Lines-File");
  126.           Serial.println("FORCEEXCELQUIT");
  127.         }
  128.         else
  129.           Serial.println("No forced Excel quit requested!");
  130.       }
  131. }
  132.  
  133. void getTemp(DeviceAddress deviceAddress)
  134. {
  135.   float tempC = sensors.getTempC(deviceAddress);
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement