A test program for hx711 built for mbed Os framework.

Dependencies:   mbed HX711

main.cpp

Committer:
Eugene0469
Date:
2019-06-25
Revision:
26:6e6f41635ff2
Parent:
25:611277904537

File content as of revision 26:6e6f41635ff2:

#include "mbed.h"
#include "Hx711.h"



float   calibration_factor = -1.0f; // this calibration factor is adjusted according to my load cell
int32_t units_raw;
float   units;
float   ounces;
int     offset = 0;

Hx711 scale(D4, D5);

//void delay(int delay){
//    for(int i=0; i<delay;i++)    
//}

int main() {
      printf("HX711 calibration sketch\n");
      printf("Remove all weight from scale\n");
      printf("After readings begin, place known weight on scale\n");
      printf("Press + or a to increase calibration factor\n");
      printf("Press - or z to decrease calibration factor\n");
      
      offset = (int)scale.read();
      scale.set_offset(offset);
      printf("Reading: %d \n",offset);
      scale.set_scale(calibration_factor);   
    while(1) {
      wait_ms(1000);

      units_raw = scale.readRaw();
      units = scale.read();
      if (units < 0)
      {
        units = 0.00;
      }
//      ounces = units * 0.035274f;
      printf("Raw reading: %d grams. \n",units_raw);
      printf("Actual reading: %f grams. \n",units);
//      printf("Calibration_factor: %f\n",calibration_factor);
      wait_ms(10000);
    }
}