Code Monkey home page Code Monkey logo

hx711-universal-library's Introduction

HX711-Universal-Library

A universal C library for the HX711 ADC, independant of the microcontroller vendor. Any microcontroller’s GPIO pins should work. The user only needs to write 3 small functions. Two functions, for writing and reading to and from a pin, and a microsecond delay function. These functions are then hooked up to the library using function pointers. Many HX711 ADCs can be used at once, since they would use different functions for pin reading and writing.

The function examples would be:

void delay_us(uint16_t delay)
{
    TIM6->CNT = 0; // this timer would be constantly running
    while (TIM6->CNT < delay);
}

void write_hx711_clock_1(bool level)
{
    switch (level) {
    case true:
        GPIOA->ODR |= 1 << 9;
        break;
    default:
        GPIOA->ODR &= ~(1 << 9);
        break;
    }

}

bool read_hx711_data_1(void)
{

    return (GPIOA->IDR & (1<<8)) != 0x00u;

}

Then just initialize the main HX711 struct i.e.:

  HX711_ADC_t test_hx711 = { 0 };
  test_hx711.delay_us = &delay_us;
  test_hx711.read_data_pin = &read_hx711_data_1;
  test_hx711.write_clock_pin = &write_hx711_clock_1;
  test_hx711.gain_select = HX711_ADC_GAIN_128;
  
  HX711_ADC_Init(&test_hx711);

Finally, read the result with a function like:

int32_t read_res = HX711_ADC_Read(&test_hx711);

hx711-universal-library's People

Contributors

stefan-milivojcev avatar

Watchers

 avatar

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.