This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to read Dout from Hx711

Hello

I'm now going to read PD_SCK and Dout from Hx711

but i can only get the value from PD_SCK, no value from Dout

here is my code, using NRF52810 and HX711, hope someone can help

#define HX711_SCK         BSP_BOARD_LED_3 //11
#define HX711_DOUT        BSP_BOARD_LED_4 //12

#define HX711_SCK_ON      bsp_board_led_on(BSP_BOARD_LED_3) 
#define HX711_SCK_OFF     bsp_board_led_off(BSP_BOARD_LED_3) 
#define HX711_DOUT_Read   nrf_gpio_pin_read(BSP_BOARD_LED_4)


 for (;;)
    {
        
        //read HX711
    
      long count = 0;
      int i;

      while(HX711_DOUT_Read);
          HX711_DOUT_Read;
      for(i = 0; i < 24; i++)
      {
          
          HX711_SCK_ON;
          count = count << 1;
          nrf_delay_us(60);
          HX711_SCK_OFF;
          nrf_delay_us(60);
          if(HX711_DOUT_Read) 
          {
            count++;  
          }    
      }
       nrf_delay_ms(1);
       HX711_DOUT_Read;
       nrf_delay_ms(1);
       HX711_SCK_ON;
       if(count & 0x800000)
       {
          count |= (long) ~0xffffff;
       }
       HX711_SCK_OFF;
  } 
    
}

  

Parents
  • Hello,

    I'm now going to read PD_SCK and Dout from Hx711

    but i can only get the value from PD_SCK, no value from Dout

    Have you checked with the Hx711 datasheet that you are sending the necessary signals for it to begin transmitting its data? If I remember correctly the Hx711 requires a certain sequence prior to starting.

    Could you also elaborate on how you have connected your Hx711 to your nRF52810? A connection diagram would be preferable.

    Looking forward to resolving this issue together!

    Best regards,
    Karl

  • I connect hx711 PD_SCK to 52810 11, DOUT to 52810 12,  the code upthere I've found some problem, I need to change DOUT to input pin, and when I finish changing, LA can read the signal, but in my program HX711_DOUT_Read seems didn't work, can't found why

    #define HX711_SCK         nrf_gpio_cfg_output(SCK)// set SCK output
    #define HX711_DOUT        nrf_gpio_cfg_input(DOUT, NRF_GPIO_PIN_NOPULL)// set DOUT input
    
    #define HX711_SCK_ON      nrf_gpio_pin_set(SCK) // set SCK high
    #define HX711_SCK_OFF     nrf_gpio_pin_clear(SCK) // set SCK low
    #define HX711_DOUT_Read   bsp_board_button_state_get(DOUT) // read DOUT high or low
    
    
    static void leds_init(void)
    {
        bsp_board_init(BSP_INIT_LEDS);
    }
    
    
    
    
    
    
    
    
    int main(void)
    {
        // Initialize.
        leds_init();
        bsp_board_led_on(BSP_BOARD_LED_0);
    
    
        for (;;)
        {
            
            //read HX711
        
          long count = 0;
          int i;
    
          while(HX711_DOUT_Read);
           
          for(i = 0; i < 24; i++)
          {
              
              HX711_SCK_ON;
              count = count << 1;
              nrf_delay_us(2);
              HX711_SCK_OFF;
              nrf_delay_us(2);
             
    
            
             
              if(HX711_DOUT_Read) 
              {
                count++;  
              }    
          }
           
           
           
           HX711_SCK_ON;
           nrf_delay_us(2);
           if(count & 0x800000)
           {
              count |= (long) ~0xffffff;
           }
           HX711_SCK_OFF;
           nrf_delay_us(10);
    
      } 
        
    
    }
    

Reply
  • I connect hx711 PD_SCK to 52810 11, DOUT to 52810 12,  the code upthere I've found some problem, I need to change DOUT to input pin, and when I finish changing, LA can read the signal, but in my program HX711_DOUT_Read seems didn't work, can't found why

    #define HX711_SCK         nrf_gpio_cfg_output(SCK)// set SCK output
    #define HX711_DOUT        nrf_gpio_cfg_input(DOUT, NRF_GPIO_PIN_NOPULL)// set DOUT input
    
    #define HX711_SCK_ON      nrf_gpio_pin_set(SCK) // set SCK high
    #define HX711_SCK_OFF     nrf_gpio_pin_clear(SCK) // set SCK low
    #define HX711_DOUT_Read   bsp_board_button_state_get(DOUT) // read DOUT high or low
    
    
    static void leds_init(void)
    {
        bsp_board_init(BSP_INIT_LEDS);
    }
    
    
    
    
    
    
    
    
    int main(void)
    {
        // Initialize.
        leds_init();
        bsp_board_led_on(BSP_BOARD_LED_0);
    
    
        for (;;)
        {
            
            //read HX711
        
          long count = 0;
          int i;
    
          while(HX711_DOUT_Read);
           
          for(i = 0; i < 24; i++)
          {
              
              HX711_SCK_ON;
              count = count << 1;
              nrf_delay_us(2);
              HX711_SCK_OFF;
              nrf_delay_us(2);
             
    
            
             
              if(HX711_DOUT_Read) 
              {
                count++;  
              }    
          }
           
           
           
           HX711_SCK_ON;
           nrf_delay_us(2);
           if(count & 0x800000)
           {
              count |= (long) ~0xffffff;
           }
           HX711_SCK_OFF;
           nrf_delay_us(10);
    
      } 
        
    
    }
    

Children
  • mirsaider said:
    I need to change DOUT to input pin, and when I finish changing

    I assumed that the code you posted in your initial ticket was incomplete. You will indeed need to configure the GPIO's you use.
    Please share your complete code.

    mirsaider said:
    LA can read the signal, but in my program HX711_DOUT_Read seems didn't work, can't found why

    This is a great start. Now, we must make sure that you are sending the correct sequence on your PD_SCK, for the Hx711 to start sending its data.
    With your current code, what are you seeing on the logic analyzer?
    Have you seen the Hx711 datasheet, and made sure to follow their instructions on how to read out data from the Hx711? - I.e could you tell me what the Hx711 is expecting to receive, and how this differs from what you are currently sending?

    Best regards,
    Karl

Related