![](/media/cache/profiles/Cristian_Castro_-_Foto.jpg.50x50_q85.jpg)
Lectura de una celda de Carga HX711.
main.cpp@0:5d67331a6e7e, 2017-05-05 (annotated)
- Committer:
- franni
- Date:
- Fri May 05 20:16:31 2017 +0000
- Revision:
- 0:5d67331a6e7e
- Child:
- 1:392a3fb6d177
Celda de Carga HX711
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
franni | 0:5d67331a6e7e | 1 | #include "mbed.h" |
franni | 0:5d67331a6e7e | 2 | #include "HX711.h" |
franni | 0:5d67331a6e7e | 3 | #include "TextLCD.h" |
franni | 0:5d67331a6e7e | 4 | |
franni | 0:5d67331a6e7e | 5 | DigitalOut led(LED_BLUE); |
franni | 0:5d67331a6e7e | 6 | HX711 scale(PTC9, PTC8); |
franni | 0:5d67331a6e7e | 7 | |
franni | 0:5d67331a6e7e | 8 | Serial rs232(USBTX, USBRX); // USB Serial Terminal |
franni | 0:5d67331a6e7e | 9 | TextLCD lcd(PTE20,PTE21,PTE22,PTE23,PTE29,PTE30, TextLCD::LCD16x2); // Rs, E, d4, d5, d6, d7 |
franni | 0:5d67331a6e7e | 10 | |
franni | 0:5d67331a6e7e | 11 | float calibration_factor = 1000; //Ajustar este valor para calibrar el peso exacto |
franni | 0:5d67331a6e7e | 12 | int averageSamples = 100; |
franni | 0:5d67331a6e7e | 13 | |
franni | 0:5d67331a6e7e | 14 | int main(void) |
franni | 0:5d67331a6e7e | 15 | { |
franni | 0:5d67331a6e7e | 16 | |
franni | 0:5d67331a6e7e | 17 | scale.setScale(0); |
franni | 0:5d67331a6e7e | 18 | scale.tare(); //Reset the scale to 0 |
franni | 0:5d67331a6e7e | 19 | |
franni | 0:5d67331a6e7e | 20 | long zero_factor = scale.averageValue(averageSamples); // Saca promedio de varias lecturas para estabilizar la medida |
franni | 0:5d67331a6e7e | 21 | |
franni | 0:5d67331a6e7e | 22 | while (true) { |
franni | 0:5d67331a6e7e | 23 | scale.setScale(calibration_factor); |
franni | 0:5d67331a6e7e | 24 | float weight = scale.getGram(); |
franni | 0:5d67331a6e7e | 25 | rs232.printf("Peso: %.2f\n", weight); |
franni | 0:5d67331a6e7e | 26 | lcd.locate(0,0); |
franni | 0:5d67331a6e7e | 27 | lcd.printf("Peso: %.2f Grms", weight); |
franni | 0:5d67331a6e7e | 28 | led = !led; // toggle led |
franni | 0:5d67331a6e7e | 29 | wait(0.2f); |
franni | 0:5d67331a6e7e | 30 | } |
franni | 0:5d67331a6e7e | 31 | } |