Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Artisan HX711
int incomingByte = 0; // for incoming serial data
int incomingWeight = 0; // for incoming scale data
#include "HX711.h"
// Define the data and clock pins for your setup
byte HX711_DOUT = D1;
byte HX711_PD_SCK = D0;
HX711 scale(HX711_DOUT, HX711_PD_SCK); // parameter "gain" is ommited; the default value 128 is used by the library
void setup() {
Serial.begin(19200); // opens serial port, sets data rate to 19200 bps
scale.set_scale(-33000.f); // this value is obtained by calibrating the scale with known weights; see
scale.tare(); // reset the scale to 0
void loop() {
// Check for an incoming command over serial. Kern scales expect a single character ("w", "s", or "t")
// with no CRLF. Acaia scales expect a command starting with BT<something> followed by CRLF.
// We will grab the first byte (because that's all we'll get for a Kern command), to see if it's
// "w", "s", "t", or "B", then react accordingly.
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte =;
// Artisan has implemented a rough approximation of the Kern scale RS232 format.
// Check page 56 here:
// Artisan sends out a "w" command to request a reading and will accept a response as follows:
// <int>g<anything>CRLF
// example: 100g0
// That's 100grams, the trailing zero can be any string, is required, and is ignored.
// No provision is made for reading past the decimal, only integer responses in grams
// will be accepted.
// Check for incoming ASCII "w" (dec 119)
// Kern weigh command (stable or unstable reading)
if (incomingByte == 119) {
int incomingWeight = int(scale.get_units(10) * 100);
// Check for incoming ASCII "t" (dec 116)
// Kern tare command, tare the scale and don't return a response
// Not implemented by Artisan as near as I know, included here for completeness sake
if (incomingByte == 116) {
// Check for incoming ASCII "s" (dec 115)
// Kern stable weigh command (stable reading)
// Not implemented by Artisan as near as I know, included here for completeness sake (but it isn't stable)
if (incomingByte == 115) {
int weightReading = int(scale.get_units(10) * 100);
// Someone developing Artisan must have gotten access to the Acaia SDK
// which means they're better than me as my own requests for access went
// ignored. Given that, I have no idea what the actual Acaia spec
// looks like and it's not published anywhere I can find. This is
// entirely put together based on reading the Artisan source code.
// I'd be shocked if this worked for anything other than Artisan.
// Check for incoming ASCII "B" (dec 66)
// Artisan will send "BTST\r\n" to check if it's connected to an Acaia scale
if (incomingByte == 66) {
// Read the rest of the line until the final LF
String incomingCommand = Serial.readStringUntil('\n');
if (incomingCommand.substring(0,3) == "TST") {
// Artisan will accept any value here EXCEPT "status=DISCONNECTED"
// I have no idea what the "correct" value should be, this is just a guess
// Check for incoming ASCII "G" (dec 71)
// Artisan will send "GWT1,1,1\r\n" to read the value from an Acaia scale
if (incomingByte == 71) {
String incomingCommand = Serial.readStringUntil('\n');
if (incomingCommand.substring(0,7) == "WT1,1,1") {
float weightReading = scale.get_units(10) * 100;
// Artisan ignores the first line
Serial.println(" g");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.