It provides a tare() function, which « resets » the scale to 0. Many other implementations calculate the tare weight when the ADC is initialized only. I needed a way to be able to set the tare weight at any time. Use case: place an empty container on the scale, call tare() to reset the readings to 0, fill the container and get the weight of the content.

It provides a power_down() function, to put the ADC into a low power mode. According to the datasheet, « When PD_SCK pin changes from low to high and stays at high for longer than 60μs, HX711 enters power down mode ». Use case: battery powered scales. Accordingly, there is a power_up() function to get the chip out of the low power mode.

It has a set_gain(byte gain) function that allows you to set the gain factor and select the channel. According to the datasheet, « Channel A can be programmed with a gain of 128 or 64, corresponding to a full-scale differential input voltage of ±20mV or ±40mV respectively, when a 5V supply is connected to AVDD analog power supply pin. Channel B has a fixed gain of 32. ». The same function is used to select the channel A or channel B, by passing 128 or 64 for channel A, or 32 for channel B as the parameter. The default value is 128, which means « channel A with a gain factor of 128 », so one can simply call set_gain(). Also, the function is called from the constructor.

The constructor has an extra parameter « gain » that allows you to set the gain factor and channel. The constructor calls the « set_gain » function mentioned above.

The « get_value » and « get_units » functions can receive an extra parameter « times », and they will return the average of multiple readings instead of a single reading.

How to Calibrate Your Scale

Call set_scale() with no parameter.

Call tare() with no parameter.

Place a known weight on the scale and call get_units(10).

Divide the result in step 3 to your known weight. You should get about the parameter you need to pass to set_scale.

NOTE: This CPU version AD module all data or command input and output formats are used RS232, 9600 baud (no parity, 1 stop bit), TTL level. This module can not be connected directly to the serial port on the host computer, the need for level conversion via RS232 chip.

1) 02H output current channel 1 final weight (16 decimal integer)

Format: A502A7 (envoyez à la carte la commande)

Module returns: 02H D1 D2 D3 D4 D5 D6 state code verification code

Description:This module sends A502A7, where A5 is the command header, 02H is the command ID, A7 is XOR checksum value A5 and 02. The final weight of the module returns the current measured data channels, wherein the secondary data on behalf of the 02H corresponding A502A7 this command returns, D1-D6 final weight data, D1 is the high byte, D6 is the low byte, the status code (2) refers to the current operating status of the module status and data, notes there are detailed instructions, check code (3) in front 8-byte XOR value.

The instruction will be given when the following system state (in the state code, there are flags), indicates that the data is invalid or not implemented this directive:

Under a calibration status (since calibration state is ready to enter the weight value, even the value of the weights are not yet determined it will not output the final weight. Like you go to measure the diameter of a wire, then even hand the caliper still do not know whether the Right, it can not measure, even if measured, the readings may be inaccurate)

b current channel has not been calibrated, there is no weight data of the time. (Available to read weight command to read the data and see)

c module receives serial data out or microcontroller module and HX711 internal communication error. (This is a global city being given instructions are valid for all subsequent commands will not be repeated this section)

2)03H final weight of continuous output current (hexadecimal integer) channels

Format: A503A6

Module returns: 03H D1 D2 D3 D4 D5 D6 state code verification code

Description: Continuous output instruction is equivalent to repeat this module automatically output a command execution, for example: this directive A503A6 final weight of continuous output current channel hex, then the equivalent of automated, repetitive execution 02H output once the current channel the final weight of 16 hexadecimal this command, but the command ID codes 02 to 03, meaning the other data are the same. Continuous output commands can be interrupted or change any other command.

The instruction in the following system status error:

a calibration state

b current channel has not been calibrated, there is no weight data of the time.

Description: the equivalent of automatic repeat A504A1 instruction, but instruction code to 05.

The instruction in the following system status error:

a calibration state

b current channel has not been calibrated, there is no weight data of the time.

5) 06H output once the final weight of the current channel (16 hex with two decimals)

Format: A506A3

Module returns: 06H D1 D2 D3 D4 D5 D6 state code verification code

Description: This hex with two decimal places the following meanings:

For example, the module data returned is 06 00 00 00 01 6F DF 07 B0, represents the final weight is 016FDFH, converted to decimal it is 94175, indicating the current weight is 941.75 grams, because this representation is relatively quick for secondary processing, such as: for fast arithmetic operations, but also for a quick comparison of size and so on, so we own this format, but does not use floating point format. (Of course, here units: grams, is just one example, what specific unit depends on the actual nature of the application and weight, if used to calibrate the temperature sensor, then the weight is the temperature value for a particular time, if used to measure the voltage , this unit is V, if used to load, this unit is the Newton or kg, and so on). Data Header 06H indicates that this data is for A506A3 this directive and returned status code indicates that the current is 07 A channel is a positive number, weight effectively, the latest data, error-free and so on.

The instruction in the following system status error:

a calibration state

b current channel has not been calibrated, there is no weight data of the time.

6) 07H continuous output current path of the final weight (16 hex with two decimals)

Format: A507A2

Module returns: 07 D1 D2 D3 D4 D5 D6 state code verification code

Description: the equivalent of automatic repetition of execution A506A3 instruction, but instruction code to 07.

The instruction in the following system status error:

a calibration state

b current channel has not been calibrated, there is no weight data of the time.

7) 08H output once the final weight of the current channel (with two decimal places)

For example, the module data returned is 08 00 00 00 00 00 09 41 78 07 3F, represents the ultimate is 941.78 grams, that is to say here is the value of D8 two decimal places. The D1-D8 are BCD, convenient for direct display.

The instruction in the following system status error:

a calibration state

b current channel has not been calibrated, there is no weight data of the time.

8) 09H consecutive final weight of the current channel (with two decimal places)

Description: This instruction is equivalent to the automatic execution of repetitive A508AD instruction, but instruction code to 09.

The instruction in the following system status error:

a calibration state

b current channel has not been calibrated, there is no weight data of the time.

9)0AH current filter output value 1 (hexadecimal integer) channels

Format: A50AAF

Module returns: 0AH D1 D2 D3 state code verification code

Explanation: Because reading came from HX711 24bit data is not directly used to calculate, but the first by the average calculation, removing the maximum, minimum, and other digital filtered before used to calculate. Here, the filtered value is filtered by the average value, which is not related to values and weights, even without the weight parameter, the value is valid.

Note: Due HX711 has two channels, sometimes take two sensors (equivalent to one for two), and the data two sensors should be used, so the birth of this directive. Put it down on the equivalent of: reading a current channel decimal (A504A1) → to switch to another channel → read once the current channel decimal (A504A1) → then switch back to the original channel, the combination of the four actions. This function is very useful in some situations require multiple sensor data, can save hardware, software resource expenditure.

Instruction in the following system status is given:

Under a calibration status, and only once the data is returned.

b current channel has not been calibrated, there is no weight data of the time.

Description: This instruction is equivalent to automatically repeat A50EAB, just 0E to 0F.

Instruction in the following system status is given:

Under a calibration status, and only once the data is returned.

b current channel has not been calibrated, there is no weight data of the time.

13) C0H current channel zero

Format: A5C065

Module returns: 74 C0 state code verification code

Description: The reading of the current channel as a zero base current channel. Zero function is similar to an ordinary electronic scales on the market. Please keep the implementation of zero sensor output stabilizes, not changes in weight, vibration, or temperature changes, the implementation of zero when the signal changes. All beginning with C or D command ID and system parameters are related to the command, the data returned data first half of this command bits are 7 high at the beginning, the lower half of representatives of the entire header returns the total number of data bytes, such as return data header this command is 74, it means this data, a total of four bytes. The second byte of the data value for C0 represent A5C065 command returned. This structure helps to check the host computer to prevent erroneous order execution system appears. Ensure system reliability execute commands.

14) C1H A, B channels at the same time zero

Format: A5C164

Module returns: 74 C1 state code verification code

Description: The reading of the current A, B channels, respectively, as A, B channel zero base. This command is invalid in the calibration status, error.

Description: Here’s « version + current channel, » the meaning is: the first half bytes firmware version, is 0-F, after nibble is not switched on automatically perform the selected parameter conditions under running channel, is A or B , A represents the A channel, B represents B-channel. Weight H is the high byte weights, weight L is the low byte.

Explanation: The state of filtering described in the notes there. Cumulative depth is the cumulative number of software filters. For example, the depth is 05, it means continuous reading five times HX711 data averaging once again, this average is the filtered value of the current channel said earlier. « Version + current channel, » the meaning is: the first half bytes firmware version, is 0-F, after nibble is not switched on automatically perform the selected parameter conditions under running channel, is A or B, A represents A channel, B represents B channel, for example: set to start automatically in the B-channel 05H command D1H command example below, and then the power automatically after a period of operation for some needed A5D10074 command to cancel the autostart function, which When the module is run, if read with this command filter channel’s depth B: « Version + current channel » A byte displays the current channel, the next boot will select the A channel, rather than B. That D1H command set working channel has priority. This command can not be executed in the calibration status, error.

19) C7H sliding filtering methods

Format: A5 C7 depth checksum

Module returns: 74 C7 status code verification code

Description: This command role is to make the current channel is switched to sliding filter mode, and comes with the size of the input data filter buffer (depth).

Slide the filter also called mean shift filtering is a method of reducing random white noise while maintaining a good way most agile step response, using mean shift method allows the output data rate and input data rate remains the same. This approach can significantly increase the effective resolution of the final results, without affecting the update rate of the output data. The only drawback of this approach is due to produce a pipeline to calculate the average delay longer settling time. This command can not be executed in the calibration status, error. Cumulative minimum depth 04H, maximum 0AH.

20) C8H using the average filter

Format: A5 C8 depth checksum

Module returns: 74 C8 state code verification code

Description: This command role is to make the current channel is switched to the average filter mode, and comes with an input cumulative frequency (depth). Depth ranging between 04-C8H. The greater the depth of the corresponding output time more slowly, especially when using the average value of continuous output filtering methods, to wait inside the module reads the cumulative number of times HX711 time will have data output. For example: HX711 data output rate is set to 80Hz (behind module J1 open), the average cumulative depth to C8H, which is 200 decimal, and is currently executing a continuous output of any command, then each time interval data output reached 200×0.0125s = 2.5 seconds, and if it is A, B continuous output alternately, that this time will be extended, because there will be a stable of four data cycles HX711 provisions after switching channels. If HX711 data output rate is set to 10Hz (behind module J1 shorted), then the output data for each interval will be longer. This command can not be executed in the calibration status, error. Cumulative minimum depth 04H, maximum C8H.

21) C9H current channel into the calibration status

Format: A5C96C

Module returns: 74 C9 status code verification code

Description: Bring the system to the sensor calibration mode, ready to enter the weight.

22) CAH input weight by weight (hexadecimal integer)

Format: A5 CA weight weight L H checksum

Module returns: 74 CA state code verification code

Description: This command role is to input the weight value in the current channel calibration mode, where H is the high byte weights, weights ranging between 1-FFFEH. The general flow sensor calibration: First enter the calibration state, and then make the current channel to zero (if not zero), followed by applying a certain exact weight on the sensor (specific point can be accurately 1kg heavier weights, or 10 degrees difference in temperature, or 10mv voltage, etc., see the case may be), and finally enter this command, the calibration was successful. Enter in the normal mode, the command will error, at zero time will error, can not perform.

23) CBH input weight by weight (decimal integer)

Format: A5 CB weight 1 weight 2 weight 3 checksum

Module returns: 74 CB status code verification code

Description: This function is equivalent to the weight and the weight of the hexadecimal integer input, but here the weight value is decimal BCD, weight 1 is high byte. For example the weight of a weight of 945 grams, then this command is: A5CB00094522. Enter in the normal mode, the command will error, at zero time will error, can not perform.

24) CCH dropouts calibration status

Format: A5CC69

Module returns: 74 CC status code verification code

Note: If you enter A5C96C command to enter the calibration status, but for some reason do not want to calibrate, and you can use this command to quit without affecting, do not change, do not overwrite the original weight data. Enter this command in normal mode will report an error, it can not be performed.

25)CDH switch to the A channel 128db

Format: A5CD68

Module returns: 74 CD status code verification code

Description: This command role is to select the A channel, and the gain is set to 128db. This command can not be executed in the calibration mode, error.

26) CEH switch to the A channel 64db

Format: A5CE6B

Module returns: 74 CE status code verification code

Description: This command role is to select the A channel, and the gain is set to 64db. This command can not be executed in the calibration mode, error.

27) CFH switched to the B channel 32db

Format: A5CF6A

Module returns: 74 CF status code verification code

Description: This command role is to select B channel, and the gain is set to 32db. This command can not be executed in the calibration mode, error.

28) D1H the current environment is set to boot automatically execute parameters

Format: A5 D1 Power Run ID verification code

Module returns: 74 D1 state code verification code

Description: This command role is to save the current parameters, and as a parameter the next boot to run automatically, and automatically execute command « Start-Run ID », this command will not save weight parameters, filter mode, filter depth, save only zero base A, B channels. Note that « Power Run ID » can only be 0 at the beginning of the command ID, but not to 00H, and if you send a C at the beginning of the command or 00H command ID, are switched on automatically perform functions will be canceled and delete previously saved about the power parameter is automatically run (if any). If you want to skip boot automatically zero, but do not want to automatically execute any instruction, please « Power Run ID » is set to 0C or 0D both invalid command. This instruction applies to temperature, humidity sensor, measuring voltage is useful to save setting parameters factory calibration. For example: B channel is currently selected, the internal module zero base is 810A9E, then send this command A5D10571, it means next time power is turned on will automatically use the B-channel, and skip boot automatically zero, forced to use the last saved zero base 810A9E, then execute the command immediately 05H (continuous output current weight decimal). This command will be given in the calibration status, it can not be executed.

29) D2H calling boot automatically run the command in the current environment

Format: A5D277

Module returns: 74 D2 state code verification code

Description: This command role is saved before calling the command to start automatically. For example: press D1 assumed command of the situation has been set to start automatically run a command: A5D10571, then the environment is a B-channel, the zero base 810A9E, and this time the boot is also running for some time, and now there would like to see A case channel, or want to see what else parameters, so he entered the command to switch channels, also enter the other commands, but also zero, and that is a big change in circumstances, and so everything you want to learn to understand later Run the command module to start automatically, but do not want the module power, then you can enter this command, will enter the new B-channel selection, and zero base 810A9E, and the module returns 74D207A1, followed by that data 05H command returns, It is equivalent to power-cycle the action. If you do not enter this command to start automatically in the module parameters of the case, there will be a return to the data, but does not execute the command to start automatically, use C5H command read, you know executed within the module boot parameter is valid, if valid Power also know which channel is performed automatically, which command ID. This command will be given in the calibration status, it can not be executed.