kozubovskyy

Untitled

Mar 11th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. /**
  2. * Complete project details at https://RandomNerdTutorials.com/arduino-load-cell-hx711/
  3. *
  4. * HX711 library for Arduino - example file
  5. * https://github.com/bogde/HX711
  6. *
  7. * MIT License
  8. * (c) 2018 Bogdan Necula
  9. *
  10. **/
  11.  
  12. #include <Arduino.h>
  13. #include "HX711.h"
  14.  
  15. // HX711 circuit wiring
  16. const int LOADCELL_DOUT_PIN = 4;
  17. const int LOADCELL_SCK_PIN = 5;
  18.  
  19. const int pin2 = 2;
  20.  
  21. float peso = 0 ;
  22. float peso1 = 0 ;
  23. float peso2 = 0 ;
  24. const int pin3 = 3;
  25.  
  26. HX711 scale;
  27. HX711 scale2;
  28.  
  29. void setup() {
  30. Serial.begin(57600);
  31. //Serial.println("HX711 Demo");
  32. //Serial.println("Initializing the scale");
  33.  
  34. scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  35. scale2.begin(pin2, pin3) ;
  36.  
  37. //Serial.println("Before setting up the scale:");
  38. // Serial.print("read: \t\t");
  39. //Serial.println(scale.read()); // print a raw reading from the ADC
  40. // Serial.println(scale2.read());
  41.  
  42. //Serial.print("prima cella \t\t");
  43. //Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
  44. //Serial.print("seconda cella \t\t");
  45. //Serial.println(scale2.read_average(20)); // print the average of 20 readings from the ADC
  46.  
  47. //Serial.print("get value scala 1: \t\t");
  48. // Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
  49. // Serial.print("get value scala 2: \t\t");
  50. //Serial.println(scale2.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
  51.  
  52. //Serial.print("get units scala 1: \t\t");
  53. //Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
  54. //Serial.print("get units scala 2: \t\t");
  55. //Serial.println(scale2.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
  56. // by the SCALE parameter (not set yet)
  57.  
  58. scale.set_scale(76);
  59. scale2.set_scale(77);
  60. //scale.set_scale(-471.497); // this value is obtained by calibrating the scale with known weights; see the README for details
  61. scale.tare(); // reset the scale to 0
  62. scale2.tare();
  63. //Serial.println("After setting up the scale:");
  64.  
  65. // Serial.print("read scala 1: \t\t");
  66. // Serial.println(scale.read()); // print a raw reading from the ADC
  67. // Serial.print("read scala 2: \t\t");
  68. // Serial.println(scale2.read());
  69.  
  70. //Serial.print("read average: scala 1\t\t");
  71. //Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
  72. //Serial.print("read average: scala 2\t\t");
  73. // Serial.println(scale2.read_average(20));
  74.  
  75. // Serial.print("get value: scala 1 \t\t");
  76. //Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
  77. // Serial.print("get value: scala 2 \t\t");
  78. // Serial.println(scale2.get_value(5));
  79.  
  80. //Serial.print("get units: unita 1 \t\t");
  81. //Serial.println(scale.get_units(5), 1);
  82. //Serial.print("get units: unita 2 \t\t");
  83. //Serial.println(scale2.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
  84. // by the SCALE parameter set with set_scale
  85.  
  86. //Serial.println("Readings:");
  87. }
  88.  
  89. void loop() {
  90. /*
  91. Serial.print("one reading: scala 1\t");
  92. Serial.print(scale.get_units(), 1);
  93. Serial.print("\t| average:\t");
  94. Serial.println(scale.get_units(10), 5);
  95. Serial.print("one reading: scala 2\t");
  96. Serial.print(scale2.get_units(), 1);
  97. */
  98. Serial.println(scale2.get_units(10), 5);
  99.  
  100. /*
  101. peso1 = (scale.get_value());
  102. peso2= (scale2.get_value());
  103. peso = (peso1 + peso2) ;
  104. Serial.print("peso:") ;
  105. Serial.print(peso) ;
  106. Serial.println("");
  107. */
  108.  
  109.  
  110.  
  111. delay(2000);
  112. }
Advertisement
Add Comment
Please, Sign In to add comment