Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Hx711 with pic16f877A

Michel09

Newbie level 5
Joined
May 24, 2024
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
56
I want to create a digital weighing indicator based on the hx711. I made the wiring diagram on proteus and I did the C code on mikroC. However I can't read anything on the serial monitor. I will put the C code and the diagram in proteus. I need your help please
schema.png


MODERATOR ACTION:

Paste on the body of the thread the code took from within the attached file, enclosed with Syntax tags.


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
#define _XTAL_FREQ 20000000
#define DT_PIN RB1_bit
#define SCK_PIN RB0_bit
#define DT_TRIS TRISB1_bit
#define SCK_TRIS TRISB0_bit
 
long offset=0;
float scale =1;
float known_weight=1000;
void init_hx711(void);
long read_hx711(void);
void tare(void);
void calibrate(float known_weight);
float get_weight(void);
 
 
void main() 
{
     UART1_Init(9600);
     delay_ms(100);
     DT_TRIS=1;
     SCK_TRIS=0;
     init_hx711();
     calibrate(known_weight);
     tare();
     //calibrate(float known_weight);
 
     
while (1)
{
  float weight = get_weight();
 
  char weight_str[10];
  char LuRaw[10];
  UART1_Write_Text("Raw value:  ");
  FloatToStr(read_hx711(), LuRaw);
  UART1_Write_Text("  g\r\n");
   UART1_Write_Text("calibration");
  UART1_Write_Text("Poids:  ");
  FloatToStr(weight, weight_str);
  UART1_Write_Text(" g\r\n");
  delay_ms(1000);
 
}
 
     }
void init_hx711(void) 
{
     SCK_PIN=0;
}
long read_hx711(void) 
{      int i;
     long count =0;
     while (DT_PIN);
     for(i =0; i<24; i++)
     {  SCK_PIN=1;
        delay_us(1);
        count=count <<1;
        SCK_PIN=0;
        delay_us(1);
        if(DT_PIN) count++;
       }
     SCK_PIN =1;
     delay_us(1);
     SCK_PIN=0;
     delay_us(1);
     count^=0x800000;
     
     return count;
}
void tare (void) 
{
     long sum=0;
     int i;
     for(i =0;i<10;i++) 
     {
             sum+=read_hx711();
             delay_ms(100);
     }
     
}
 
void calibrate( float known_weight){
     long raw_value= read_hx711()-offset;
     scale= raw_value/known_weight;
     }
float get_weight(void) {
      long raw_value= read_hx711() - offset;
      return raw_value/scale;
      }

 

Attachments

  • Mon_code.txt
    1.7 KB · Views: 23
Last edited by a moderator:
You did not mention if there is some activity on the uC TX pin.
There is an osciloscope there, connected to nothing.
 
the oscilloscope is there to visualize the output signals from the hx711 but I disconnected it
 
There is the different signals. Yellow's signal it's for the clock and red's signal for the data output
 

Attachments

  • lecture.png
    lecture.png
    157.4 KB · Views: 26
You increased the time base instead of decreasing it, doesn't it seem clear that it is now more difficult to identify details in the pulse than before?
 
should I return to the microsecond domain?
The scale was not in the microsecond domain at any time. You need to check if the little pulse seen there represents a serial data stream; If the baudrate configured in the uC is wrongly set, by amplifying the pulse in time (reducing the scope time scale) you can determine if this pulse is a mere artifact or if it is in fact a serial data, so I let you answer the question yourself.
 
The scale was not in the microsecond domain at any time. You need to check if the little pulse seen there represents a serial data stream; If the baudrate configured in the uC is wrongly set, by amplifying the pulse in time (reducing the scope time scale) you can determine if this pulse is a mere artifact or if it is in fact a serial data, so I let you answer the question yourself.
during compilation the compiler generated a warning related to the baud which exceeded 15 or 9615. could this be a problem because I immediately modified the baud of the serial monitor but still nothing. what is your opinion on my code please
 
You can check these docs.
 
You can check these docs.
I have already read the second document and I checked we have the same code but I do not understand why I do not obtain the chronogram illustrated in the datasheet
 
You seem to be systematically disregarding my tips about trying to determine what is and isn't working; leaving this thread, good luck.
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top