diff --git a/main.cpp b/main.cpp index 32191c5..cfb249f 100644 --- a/main.cpp +++ b/main.cpp @@ -9,6 +9,10 @@ #include "DHT.h" #endif +#if MBED_CONF_APP_HX711_ENABLED +#include "HX711.h" +#endif + using namespace events; uint8_t rx_buffer[LORAMAC_PHY_MAXPAYLOAD]; @@ -45,11 +49,22 @@ AnalogIn bat(MBED_CONF_APP_BATTERY_ADC); DHT dht(MBED_CONF_APP_DHT_DATA, MBED_CONF_APP_DHT_TYPE); #endif +#if MBED_CONF_APP_HX711_ENABLED +HX711 loadcell(MBED_CONF_APP_HX711_CLK, MBED_CONF_APP_HX711_DATA); +#endif + //DigitalOut led(LED1, 1); int main(void) { lorawan_status_t retcode; + +#if MBED_CONF_APP_HX711_ENABLED + loadcell.setScale(MBED_CONF_APP_HX711_SCALE); + loadcell.setOffset(MBED_CONF_APP_HX711_OFFSET); + loadcell.powerDown(); +#endif + // Initialize LoRaWAN stack if(lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) { printf("\r\n LoRa initialization failed! \r\n"); @@ -117,6 +132,12 @@ static void send_message() { } #endif +#if MBED_CONF_APP_HX711_ENABLED + loadcell.powerUp(); + cayenne.addAnalogInput(2, loadcell.getUnits(5)); + loadcell.powerDown(); +#endif + // No data to send if(cayenne.getSize() == 0) { return; diff --git a/mbed_app.json.sample b/mbed_app.json.sample index b635389..c74e272 100644 --- a/mbed_app.json.sample +++ b/mbed_app.json.sample @@ -27,7 +27,11 @@ "battery-adc": { "value": "NC" }, "dht-enabled": { "value": "false" }, "dht-type": { "value": "DHT::DHT22" }, - "dht-data": { "value": "NC" } + "dht-data": { "value": "NC" }, + "hx711-clk": { "value": "NC" }, + "hx711-data": { "value": "NC" }, + "hx711-scale": { "value": "1.0f" }, + "hx711-offset": { "value": 0 } }, "target_overrides": { "*": { @@ -276,7 +280,12 @@ "battery-adc": "PA_2", "dht-enabled": true, "dht-data": "D8", - "dht-type": "DHT::DHT22" + "dht-type": "DHT::DHT22", + "hx711-enabled": true, + "hx711-clk": "D7", + "hx711-data": "D6", + "hx711-scale": "21000.0f", + "hx711-offset": -2000 } }, "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\""] diff --git a/sensors/HX711.lib b/sensors/HX711.lib new file mode 100644 index 0000000..89c8669 --- /dev/null +++ b/sensors/HX711.lib @@ -0,0 +1 @@ +https://github.com/atoy40/mbed-hx711/#92640d4fcfc8f2128c3f3f54031cfafed5733bc8