Advertisement
sspence65

micro-epsilon odc2600

Nov 29th, 2018
346
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // #include <LiquidCrystal.h>
  3. // LiquidCrystal lcd(12,11,5,4,3,2);
  4.  
  5. int i;
  6. int iAnzBytes = 0;
  7. int index = 0;
  8. int tempMask = 0;
  9. byte bMaskmB = 0b00111111;
  10. byte bMaskhB = 0b00001111;
  11. byte bLowMask =0b11000000;
  12. byte bData[255];
  13. char StrStop[12] = {'+','+','+','\r','O','D','C','1',0x21,0x20,0x00,0x00};
  14. char StrStart[12] = {'+','+','+','\r','O','D','C','1',0x22,0x20,0x00,0x00};
  15.  
  16.  
  17. void setup() {
  18. // put your setup code here, to run once:
  19. // lcd.begin(16,2);
  20. Serial1.begin(19200);
  21. Serial.begin(19200);
  22. Serial.println("Stop data output");
  23. for (i = 0; i<12; i++){
  24. Serial1.print(StrStop[i]);
  25. delay(100);
  26. iAnzBytes =Serial1.available();
  27. Serial1.readBytes(bData,iAnzBytes);
  28. }
  29. // Serial.println(StrStop);
  30.  
  31. // sort the array looking for the lowest value
  32. /*
  33. * for ( i = 1; i < 5; i++) {
  34. if (temp[i] < value) {
  35. value = temp[i];
  36. index = i;
  37. }
  38. }
  39. //*/
  40. }
  41.  
  42. void loop() {
  43. // put your main code here, to run repeatedly:
  44.  
  45. Serial.println("!! New measurement !!");
  46. Serial.println("Start data output");
  47.  
  48. for (i = 0; i<12; i++){
  49. Serial1.print(StrStart[i]);
  50. }
  51. // Serial.println(StrStart);
  52. delay(300);
  53. iAnzBytes =Serial1.available();
  54. /*
  55. Serial.print("gelesene Bytes: ");
  56. Serial.print(iAnzBytes);
  57. Serial.print("\n");
  58. //*/
  59. Serial1.readBytes(bData,iAnzBytes);
  60. delay(100);
  61. iAnzBytes =Serial1.available();
  62. /*
  63. Serial.print("gelesene Bytes: ");
  64. Serial.print(iAnzBytes);
  65. Serial.print("\n");
  66. //*/
  67. Serial1.readBytes(bData,iAnzBytes);
  68.  
  69. Serial.println("Stop data output");
  70. for (i = 0; i<12; i++){
  71. Serial1.print(StrStop[i]);
  72. }
  73. // Serial.println(StrStop);
  74. // iAnzBytes =Serial.available();
  75. /*
  76. Serial.print("gelesene Bytes: ");
  77. Serial.print(iAnzBytes);
  78. Serial.print("\n");
  79. //*/
  80. if (iAnzBytes > 5){
  81. // Serial.readBytes(bData,iAnzBytes);
  82. //*
  83. Serial.print("Read bytes: ");
  84. Serial.println(iAnzBytes);
  85. //*/
  86. // Serial.print("\n");
  87. for (i = 1; i < iAnzBytes; i++) {
  88. //*
  89. Serial.print("Current byte: ");
  90. Serial.print(bData[i]);
  91. Serial.print("\n");
  92. //*/
  93.  
  94. tempMask = bData[i] & bLowMask;
  95. /*
  96. Serial.print("tempMask: ");
  97. Serial.print(tempMask);
  98. Serial.print("; bLowMask: ");
  99. Serial.print(bLowMask);
  100. Serial.print("\n");
  101. //*/
  102.  
  103. if((tempMask) == 0) break;
  104. }
  105. index = i;
  106. //*
  107. Serial.print("index: ");
  108. Serial.println(index);
  109. Serial.print("; LowData: ");
  110. Serial.println(bData[index]);
  111. // Serial.print("\n");
  112. //*/
  113.  
  114. long lB = bData[index];
  115. long mB = bData[index+1];
  116. long hB = bData[index+2];
  117. //*
  118. Serial.print("Values[HEX]: lB; mB; hB: ");
  119. // Serial.print("; ");
  120. Serial.print(lB, HEX); Serial.print("; ");
  121. Serial.print(mB, HEX); Serial.print("; ");
  122. Serial.println(hB, HEX); Serial.print("\n");
  123. //*/
  124. Serial.print("Values[BIN]: lB; mB; hB: ");
  125. // Serial.print("; ");
  126. Serial.print(lB, BIN); Serial.print("; ");
  127. Serial.print(mB, BIN); Serial.print("; ");
  128. Serial.println(hB, BIN); Serial.print("\n");
  129.  
  130. Serial.print("Masked values): ");
  131. //Serial.print("; ");
  132. Serial.print(lB, BIN);Serial.print("; ");
  133.  
  134. mB = mB & bMaskmB; // the upper 2 bits must be unmasked(they have to become 0)
  135. Serial.print(mB, BIN); Serial.print("; ");
  136. mB = mB * 64; // 64 = 2^6
  137.  
  138.  
  139. hB = hB & bMaskhB; // the upper 4 bits must be unmasked(they have to become 0)
  140. Serial.println(hB, BIN); Serial.print("; ");
  141. hB = hB * 4096; // 4096 = 2^12
  142.  
  143. // because in "lB" the upper 2 bits are always 0 anyway, you do not have to mask "lB".
  144.  
  145. long total = lB+mB+hB;
  146. Serial.print("total(DEC): ");
  147. Serial.println(total, DEC);
  148. float mm = total * 40.824 / 65519 - 0.4204872;
  149. float inch = total * 1.60724 / 65519 - 0.016554614;
  150. //*
  151. Serial.print("calculated value[mm]: ");
  152. Serial.print(mm-6.594220, 6); //subtracted thickness of plate from mm
  153. Serial.println(" mm");
  154.  
  155. Serial.print("calculated value[inch]: ");
  156. Serial.print(inch-0.259639, 6); //subtracted thickness of plate from inch
  157. Serial.println(" inch");
  158. Serial.println(); Serial.println();
  159. /*/
  160.  
  161. lcd.clear();
  162. if ((mm < 40) && (mm > 0,0001)) {
  163. lcd.setCursor(0,0);
  164. lcd.print(mm, 4);
  165. lcd.print(" mm");
  166. lcd.setCursor(0,1);
  167. lcd.print(inch, 4);
  168. lcd.print(" inch");
  169. }
  170. else {
  171. lcd.setCursor(0,0);
  172. lcd.print("--.---");
  173. lcd.print(" mm");
  174. lcd.setCursor(0,1);
  175. lcd.print("--.---");
  176. lcd.print(" inch");
  177. }
  178.  
  179.  
  180. // */
  181. /*
  182. Serial.print("zu wenig Bytes gelesen");
  183. Serial.print("\n");
  184. //*/
  185. }
  186.  
  187. delay(300);
  188. }
Advertisement
RAW Paste Data Copied
Advertisement