Hi, I am interfacing HX711- 24 bit ADC for Weigh Scale to calculate weight which has DOUT and PD_SCLK for Digital Output and Digital Input. I have the working Arduino code and I need to convert this code for nRF BLE_UART .Can anyone help me out with this?
I have attached the Arduino code with this
long readIndex = 0; // the index of the current reading
long total = 0; // the running total
double average = 0; // the average
void setup()
{
Serial.begin(9600);
Serial.println(" HX711 ");
Serial.println("Before setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
// by the SCALE parameter (not set yet)
scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details
scale.tare(20); // reset the scale to 0
Serial.println("After setting up the scale:");
...................
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20));
// print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
// by the SCALE parameter set with set_scale
Serial.println("Readings:");
for (int thisReading = 0; thisReading < numReadings; thisReading++)
{
readings[thisReading] = 0;
}
}
long c=0;
double w=0;
long x=0;
long y=0;
long z=0;
void loop()
{
Serial.print(" ");
y=scale.read();
Serial.print(y);
Serial.print(" ");
Serial.print(" ");
Serial.print(x);
Serial.print(" ");
z=y-x;
Serial.print(z);
Serial.print(" ");
w=9.132*0.00001*0.00001*0.00001*0.0001*z*z*z-4.537*0.00001*0.00001*0.01*z*z+4.449*0.00001*z;
Serial.print("weight= ");
Serial.println(w);
if (Serial.available() > 0)
{
incomingByte = Serial.read();
if(incomingByte==49)
{
x=y;
Serial.println(" Tare complete ");
}
}
delay(300);
}
Regards.