Lectura de una celda de Carga HX711.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Hx711.h"
00003 
00004 #define n_muestras 10
00005 
00006 DigitalOut led(LED1);
00007 
00008 Hx711 LoadCeld(A1, A0, 1, 1.0);
00009 
00010 Serial rs232(USBTX, USBRX);    // USB Serial Terminal
00011 
00012 
00013 
00014 
00015 
00016 
00017 float escala = 0.0;
00018 float offset; 
00019 float calibration_factor = 1000; //Ajustar este valor para calibrar el peso exacto
00020 int averageSamples = 300;
00021 
00022 int main(void)
00023 {
00024      
00025      
00026     for(int i = 0; i < n_muestras; i++ )
00027     {
00028         while(!LoadCeld.is_ready());
00029         
00030         offset = ( offset + LoadCeld.readRaw());
00031 
00032     }
00033     
00034     offset = (offset / n_muestras);
00035     LoadCeld.set_offset(offset);
00036     LoadCeld.set_scale(1.0);
00037     rs232.printf("Offset: %.2f \n", offset);
00038     rs232.printf("Offset: %.2f \n", LoadCeld.get_offset());
00039     offset = 0.0;
00040     
00041     //scale.tare(); //Reset the scale to 0
00042     
00043     //long zero_factor = scale.averageValue(averageSamples); // Saca promedio de varias lecturas para estabilizar la medida
00044      
00045     while (true) {
00046         
00047         
00048         for(int i = 0; i < n_muestras; i++ )
00049         {
00050             while(!LoadCeld.is_ready());
00051             
00052             escala = ( escala + LoadCeld.read());
00053 
00054         }
00055         escala = (escala / n_muestras);
00056         rs232.printf("Peso: %.2f \n", escala); 
00057         escala = 0.0;
00058         //scale.setScale(calibration_factor); 
00059         //float weight = scale.getGram();
00060         //rs232.printf("Peso: %.2f\n", weight);
00061         //lcd.locate(0,0);
00062         //lcd.printf("Peso: %.2f Grms", weight);
00063         led = !led; // toggle led
00064         wait(0.2f);
00065     }
00066 }