Michel09
Newbie level 5
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
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
Last edited by a moderator: