Here is my Arduino sketch:
#include <HX711.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
HX711 hx(9, 10, 128, 0.002229);
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
Serial.begin(9600);
hx.set_offset(-9635);
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.begin(16,2);
}
void loop() {
if(digitalRead(0) == LOW){
lcd.clear();
lcd.setCursor(2,0);
lcd.print("tare recieved");
hx.tare();
}
double sum = 0;
for (int i = 0; i < 10; i++) {
sum += hx.bias_read();
if(sum < 0) {
sum = 0.00;
}
}
sum = sum/10;
lcd.clear();
lcd.setCursor(4,0);
lcd.print("Weight");
lcd.setCursor(5, 1);
lcd.print(sum);
lcd.print("g");
Serial.println(sum);
delay(10);
}
Here is an example output as seen on the Arduino Serial Monitor:
150.34
150.39
150.40
150.37
150.38
The Problem is when the data reaches node-serialport the value is split up on multiple lines.
comport.on("data", function (data) {
console.log(data.toString());
}
When i log the data... it comes back like this:
1
50.4
5
150.
49
15
0.47
150.
48
15
0.45
Is there anyway to have Arduino only send the data if it is the full value and not the split up values?