Hi guys
Im trying to get Unojoy to work with my loadcell. I can do it wit the HX711 lib but its so eratic its unusable. Now im trying to use the ADC one which seems stable but i dont know what i am doing wrong.
Where i could just put this for one the other will give an error. How can i fix the not declared in scope error? I can print it so why not use it to update the variable?
controllerData.rightStickX = scale.get_units() * 3 ; // this works fine with hx711 lib
With ADC
controllerData.rightStickY = Loadcell.getData(); // why dont this work? not declared in scope.
#include <HX711_ADC.h>
#include <EEPROM.h>
//HX711 constructor (dout pin, sck pin):
HX711_ADC LoadCell(3, 2);
const int eepromAdress = 0;
int Ldata = 1;
long t;
#include "UnoJoy.h"
void setup(){
float calValue; // calibration value
calValue = 696.0; // uncomment this if you want to set this value in the sketch
#if defined(ESP8266)
//EEPROM.begin(512); // uncomment this if you use ESP8266 and want to fetch the value from eeprom
#endif
//EEPROM.get(eepromAdress, calValue); // uncomment this if you want to fetch the value from eeprom
Serial.begin(38400);
LoadCell.begin();
long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time
LoadCell.start(stabilisingtime);
LoadCell.start(stabilisingtime);
if(LoadCell.getTareTimeoutFlag()) {
Serial.println("Tare timeout, check MCU>HX711 wiring and pin designations");
}
else {
LoadCell.setCalFactor(calValue); // set calibration value (float)
Serial.println("Startup + tare is complete");
}
//setupPins();
setupUnoJoy();
}
void loop(){
LoadCell.update();
//get smoothed value from data set
if (millis() > t + 250) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
t = millis();
}
// Always be getting fresh data
dataForController_t controllerData = getControllerData();
setControllerData(controllerData);
// Zaxis_value = (scale.get_units());
// Serial.println(controllerData.rightStickY );
Serial.println(LoadCell.getData());
}
void setupPins(void){
// Set all the digital pins as inputs
// with the pull-up enabled, except for the
// two serial line pins
for (int i = 4; i <= 12; i++){
pinMode(i, INPUT);
digitalWrite(i, HIGH);
}
}
dataForController_t getControllerData(void){
// Set up a place for our controller data
// Use the getBlankDataForController() function, since
// just declaring a fresh dataForController_t tends
// to get you one filled with junk from other, random
// values that were in those memory locations before
dataForController_t controllerData = getBlankDataForController();
// Since our buttons are all held high and
// pulled low when pressed, we use the "!"
// operator to invert the readings from the pins
// Set the analog sticks
// Since analogRead(pin) returns a 10 bit value,
// we need to perform a bit shift operation to
// lose the 2 least significant bits and get an
// 8 bit number that we can use
/* controllerData.leftStickX = analogRead(A0) >> 2;
controllerData.leftStickY = analogRead(A1) >> 2;
controllerData.rightStickX = analogRead(A2) >> 2;
controllerData.rightStickY = analogRead(A3) >> 2;
*/
// controllerData.leftStickX = analogRead(A0) >> 2;
// controllerData.leftStickY = analogRead(A1) >> 2;
// controllerData.rightStickX = scale.get_units() * 3 ; //this works fine with hx711 lib
controllerData.rightStickY = Loadcell.getData(); // why dont this work? not declard in scope.
// controllerData.Zaxis = scale.read();
// And return the data!
return controllerData;
}