GithubHelp home page GithubHelp logo

read function is slow about hx711 HOT 16 CLOSED

bogde avatar bogde commented on June 30, 2024
read function is slow

from hx711.

Comments (16)

LwServices avatar LwServices commented on June 30, 2024

I have study this code. Now I quite understand your code. The issue is that you try to get all bits in one cyclus of the main function loop. This cause trouble and the CPU Idle a lot and this slow my other code down.
Now i have started a new approuch one bit each cycle.

const byte hx711_data_pin = A7;
const byte hx711_clock_pin =A6;
bool bOut,bOut1,bOut2;
bool bIn,newData,readingHX;
byte data1,data2,data3;
unsigned long currentTime;
unsigned long lastUpdate1,lastUpdate2;
int i,d,j;
long int dd;
void setup() {
// put your setup code here, to run once:

pinMode(hx711_clock_pin,OUTPUT);
pinMode(hx711_data_pin,INPUT);
// digitalWrite(hx711_data_pin, HIGH);
Serial.begin(9600);
readingHX=1;
}

void loop() {

if(readingHX){
if(bOut2){
bOut2=0;
digitalWrite(hx711_clock_pin,0);
}else{
bOut2=1;
digitalWrite(hx711_clock_pin,1);
bIn=digitalRead(hx711_data_pin);
j=23-i;
if(i<24){
dd |= bIn<<(j);
}
i++;
}
}else{
i=0;
}
if(i==24){
readingHX=0;
dd ^= 0x80;
Serial.println(dd,BIN);
dd=0;
digitalWrite(hx711_clock_pin,0);
}
}

from hx711.

CFTechno avatar CFTechno commented on June 30, 2024

Would it not been easier to use
if (scale.is_ready()) Lvalue = scale.read() ;

from hx711.

bogde avatar bogde commented on June 30, 2024

@leszek77 do you still need any help with this?

from hx711.

LwServices avatar LwServices commented on June 30, 2024

yes, but i try to figure out by my self.

from hx711.

kasperv79 avatar kasperv79 commented on June 30, 2024

Hi.
@leszek77, did you finalise your version?

from hx711.

LwServices avatar LwServices commented on June 30, 2024

i didn\t continue to work on it

from hx711.

theharshalpatil avatar theharshalpatil commented on June 30, 2024

@bogde I'm facing the same issue. Is there a way to increase the speed at which the data is fetched?

from hx711.

Srijal97 avatar Srijal97 commented on June 30, 2024

For anyone reading this in the future, that while (!is_ready()); in read() caused the code to block and would waste a lot of processor cycles so I modified it by removing the while loop, and instead repeatedly checking in the main loop if chip is_ready(). I created separate functions read_direct() [Without the blocking while loop], and get_units_direct() [Which calls read_direct() directly] and added this to my main loop:

if (scale.is_ready()){
    tension = scale.get_units_direct();
}

from hx711.

MugetsuX avatar MugetsuX commented on June 30, 2024

@Srijal97 Hey there, i'm facing the same problem with the while (!is_ready()); function. I'm not a programmer and can't figure out how to change the while loop to an if function. Could you give some more detail on how you have set up your code? I'm using the multi-library to connect 4 loadcells:
https://github.com/compugician/HX711-multi/blob/master/HX711-multi.cpp

Thanks a lot :-)

from hx711.

Srijal97 avatar Srijal97 commented on June 30, 2024

@MugetsuX Hey, if you could just drop me an email on the ID from my GitHub profile, I'll send you the modified library and example code showing what I mean!

from hx711.

jeroentjeee avatar jeroentjeee commented on June 30, 2024

@Srijal97 Hi Sir, I tried your way of fixing this problem, however i'm not quite getting it done. could you also send me the modified libraby?

thanks a lot

from hx711.

andrelouk avatar andrelouk commented on June 30, 2024

@Srijal97 could you send me your modifications to the library. thank you very much.. im doing a rapid acquisition from the load cell, and i need to get the value as fast as possible. Thank you very much..

from hx711.

Srijal97 avatar Srijal97 commented on June 30, 2024

@Srijal97 could you send me your modifications to the library. thank you very much.. im doing a rapid acquisition from the load cell, and i need to get the value as fast as possible. Thank you very much..

Please find the files here: Srijal97/HX711

from hx711.

andrelouk avatar andrelouk commented on June 30, 2024

from hx711.

eleksis avatar eleksis commented on June 30, 2024

@Srijal97 thanks for sharing the code. If i can suggest...you should make fork of this project and publish your code on your github profile, that's what github is for...

from hx711.

Srijal97 avatar Srijal97 commented on June 30, 2024

@Srijal97 thanks for sharing the code. If i can suggest...you should make fork of this project and publish your code on your github profile, that's what github is for...

I have done that now, thank you!

from hx711.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.