HX711 Reading problem - Not getting correct readings

Status
Not open for further replies.

Okada

Banned
Joined
Jun 16, 2016
Messages
1,159
Helped
129
Reputation
252
Reaction score
129
Trophy points
63
Activity points
0
Hi

I am making a weighing Scale and I am using PIC16F877A with 20 MHz Crystal. I am using mikroC PRO PIC Compiler. This is my code but I am only getting two values that is for 0V input to A+ pin of HX711 I am getting 500 and for 5V input to HX711 A+ pin I am getting 1000 as the adc reading. Between those to values I don't get any other readings. The values should vary between 0 and 1000.

What am I doing wrong ? I have referred the C code in the attached PDF. I am testing on hardware.


E+ and E- are not connected to load cell. I am just testing the HX711 module.

A- to GND
A+ to 0 - 5V

B- and B+ are not connected

VCC = 5V
GND = GND
SCK = RD0
DOUT = RC0


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#define LOW  0
#define HIGH 1
 
#define ADC_RESOLUTION 16777216.0
 
#define INPUT  1
#define OUTPUT 0
 
// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
 
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
 
//HX711 Connections
sbit HX711_SCLK at RD0_bit;
sbit HX711_DOUT at RC0_bit;
 
sbit HX711_SCLK_Direction at TRISD0_bit;
sbit HX711_DOUT_Direction at TRISC0_bit;
 
const code char txt1[] = "\r\n";
const code char txt2[] = " Weighing Scale";
 
unsigned char my_flags_a = 0;
unsigned char common_cathode_seven_segment_mask[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
char seven_segment_digit = 0;
char output_string[23], k = 0;
unsigned char enable_timer1_interrupt_flag = 0;
unsigned char mode_flag = 0;
unsigned char digits[6] = {0,0,0,0,0,0};
unsigned long int raw_adc_value = 0, previous_raw_adc_value = 0xFFFFFFFF;
double weight = 0.0;
unsigned char q = 0, t = 0, mask = 0x80;
 
char *CopyConst2Ram(char * dest, const code char *src) {
    char *d;
 
    d = dest;
 
    for(;*dest++ = *src++;);
 
    return d;
}
 
unsigned long Read_HX711() {
    unsigned long count = 0;
    unsigned char i; //, highest = 0, higher = 0, hi = 0, lo = 0;
 
    HX711_DOUT_Direction = OUTPUT;
    HX711_SCLK_Direction = OUTPUT;
 
    HX711_DOUT = 1;
    HX711_SCLK = 0;
 
    HX711_DOUT_Direction = INPUT;
 
    while(HX711_DOUT);
 
    for(i = 0; i < 24; i++) { // gain 128
        HX711_SCLK = 1;
        count <<= 1;
        HX711_SCLK = 0;
 
        if(HX711_DOUT)count++;
    }
 
    HX711_SCLK = 1;
    count ^= 0x800000;
    HX711_SCLK = 0;
 
    return(count);
}
 
void main(void) {
 
    asm clrwdt
 
    CMCON = 0x07;
 
    ADCON0 = 0x40;
    ADCON1 = 0x8F;
 
    TRISA = 0x00;
    TRISB = 0x00;
    TRISC = 0x80;
    TRISD = 0x00;
    TRISE = 0x00;
 
    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    PORTE = 0x00;
 
    Delay_ms(200);
    LCD_Init();
    LCD_Cmd(_LCD_CURSOR_OFF);
    LCD_Cmd(_LCD_CLEAR);
 
    LCD_Out(1,1,CopyConst2Ram(output_string, txt2));
 
    while (1) {
 
        asm clrwdt
 
        raw_adc_value = Read_HX711();
        Delay_ms(2);
 
        if(previous_raw_adc_value != raw_adc_value) {
            weight = ((double)raw_adc_value * 1000.0 / ADC_RESOLUTION);
            FloatToStr_FixLen(weight, output_string, 7);
            strcat(output_string, " Kg");
            LCD_Out(2,1,output_string);
 
            previous_raw_adc_value = raw_adc_value;
        }
    }
}





Edit:

I think I broke the module by inputting 5V to A+ pin. Datasheet mentioned that differential input voltage should be +/-40mV and if I ground A- pin then I should not provide more than 40mV to A+ pin. Right ?

I will order new module.
 

Attachments

  • HX711 Test.rar
    181.8 KB · Views: 98
Last edited:

Hi,

I assume we are reading different datasheets, because I can't find your given values in my "HX711" datasheet.
My datasheet says:
* Common mode input: AGND+1.2 ... AVDD-1.3 V
* Full scale differential input range V(inp)-V(inn): ±0.5(AVDD/GAIN) V

Klaus
 


Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…