Skip to content

Instantly share code, notes, and snippets.

@vschlegel
Created October 2, 2019 07:26
Show Gist options
  • Save vschlegel/e6c408b367bbade20a5b0b5a5fe3a8cb to your computer and use it in GitHub Desktop.
Save vschlegel/e6c408b367bbade20a5b0b5a5fe3a8cb to your computer and use it in GitHub Desktop.
De Matze isch en dubel
#include "LowPower.h"
#include "HX711.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
// Configuration
int sleeptime = 2; //seconds
const byte address[6] = "00001"; //tx-address
// Scale-Calibration
float offset = 196149.89; // raw-value with no load
float multiplier = 43260.02; // (raw-vlaue with 100kg load - raw-value with no load / 100)
struct airdataStruct{
byte protokoll = 1;
int id = 1;
float gewicht;
} airdata;
int currentsleep = 0;
HX711 scale(A1, A0);
RF24 radio(7, 8); // CE, CSN
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(115200);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.stopListening();
}
void loop()
{
if (currentsleep == sleeptime) {
currentsleep = 0;
scale.power_up();
float reading = scale.read();
reading = (reading-offset)/multiplier;
Serial.println(reading);
delay(5);
scale.power_down();
airdata.gewicht = reading;
radio.write(&airdata, sizeof(airdata));
}
else {
currentsleep++;
LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment