Hello, i am pretty new in the node red topic and currently trying to get the weight of my hx711 load sensor in node-red but i am not able to do it. I saw that there is the palette node-red-contrib-hx711 which looked easy to use but i only get 0 values even with the given flow of its github entry. I also tried it directly over python on my raspberry pi - there it works to read the load but i am unable to get the data into nodered
nodered v 3.1.3
nodejs 18.19.0
flow:
[
{
"id": "5d3ceb36.b1a4a4",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "ccb72235.6747",
"type": "inject",
"z": "5d3ceb36.b1a4a4",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "2",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "Initialize",
"payloadType": "str",
"x": 360,
"y": 200,
"wires": [
[
"42a327b2.f97038"
]
]
},
{
"id": "25eb352f.bccd5a",
"type": "rbe",
"z": "5d3ceb36.b1a4a4",
"name": "",
"func": "narrowband",
"gap": "0.5",
"start": "",
"inout": "in",
"septopics": true,
"property": "payload",
"topi": "topic",
"x": 750,
"y": 260,
"wires": [
[
"ccc66ff.aaaca9"
]
]
},
{
"id": "42a327b2.f97038",
"type": "hx711",
"z": "5d3ceb36.b1a4a4",
"name": "",
"hx_data": "29",
"hx_sck": "31",
"hx_scale": "216",
"hx_gain": "64",
"hx_offset": "0",
"hx_avrg": "1",
"x": 590,
"y": 260,
"wires": [
[
"25eb352f.bccd5a"
]
]
},
{
"id": "285228f5.b48c18",
"type": "inject",
"z": "5d3ceb36.b1a4a4",
"name": "Tare",
"props": [
{
"p": "tare",
"v": "",
"vt": "date"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 350,
"y": 260,
"wires": [
[
"42a327b2.f97038"
]
]
},
{
"id": "ccc66ff.aaaca9",
"type": "smooth",
"z": "5d3ceb36.b1a4a4",
"name": "",
"property": "payload",
"action": "mean",
"count": "30",
"round": "",
"mult": "single",
"reduce": false,
"x": 940,
"y": 260,
"wires": [
[
"73277f82476c5f13"
]
]
},
{
"id": "635f5cfa7963a221",
"type": "ui_chart",
"z": "5d3ceb36.b1a4a4",
"name": "",
"group": "301ee099fd1bc275",
"order": 0,
"width": 0,
"height": 0,
"label": "chart",
"chartType": "line",
"legend": "false",
"xformat": "HH:mm:ss",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "",
"ymax": "",
"removeOlder": 1,
"removeOlderPoints": "",
"removeOlderUnit": "3600",
"cutout": 0,
"useOneColor": false,
"useUTC": false,
"colors": [
"#1f77b4",
"#aec7e8",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"outputs": 1,
"useDifferentColor": false,
"className": "",
"x": 1130,
"y": 260,
"wires": [
[]
]
},
{
"id": "6603f14bc05d712b",
"type": "python-function-ps",
"z": "5d3ceb36.b1a4a4",
"name": "",
"pythonPathType": "local",
"pythonPath": "python3",
"globalPythonName": "",
"importPathList": [
"/home/smartshelf2/hx711py"
],
"fnCodePre": "\n# user code here.\n",
"fnCode": "#! /usr/bin/python2\n\nimport time\nimport sys\nimport RPi.GPIO as GPIO\nfrom hx711 import HX711\n\nhx = HX711(5, 6)\n\n# I've found out that, for some reason, the order of the bytes is not always the same between versions of python, numpy and the hx711 itself.\n# Still need to figure out why does it change.\n# If you're experiencing super random values, change these values to MSB or LSB until to get more stable values.\n# There is some code below to debug and log the order of the bits and the bytes.\n# The first parameter is the order in which the bytes are used to build the \"long\" value.\n# The second paramter is the order of the bits inside each byte.\n# According to the HX711 Datasheet, the second parameter is MSB so you shouldn't need to modify it.\nhx.set_reading_format(\"MSB\", \"MSB\")\n\n# HOW TO CALCULATE THE REFFERENCE UNIT\n# To set the reference unit to 1. Put 1kg on your sensor or anything you have and know exactly how much it weights.\n# In this case, 92 is 1 gram because, with 1 as a reference unit I got numbers near 0 without any weight\n# and I got numbers around 184000 when I added 2kg. So, according to the rule of thirds:\n# If 2000 grams is 184000 then 1000 grams is 184000 / 2000 = 92.\nhx.set_reference_unit(450)\n#hx.set_reference_unit(referenceUnit)\n\nhx.reset()\n\nhx.tare()\n\nprint(\"Tare done! Add weight now...\")\n\n# to use both channels, you'll need to tare them both\n#hx.tare_A()\n#hx.tare_B()\n\n# These three lines are usefull to debug wether to use MSB or LSB in the reading formats\n# for the first parameter of \"hx.set_reading_format(\"LSB\", \"MSB\")\".\n# Comment the two lines \"val = hx.get_weight(5)\" and \"print val\" and uncomment these three lines to see what it prints.\n\n# np_arr8_string = hx.get_np_arr8_string()\n# binary_string = hx.get_binary_string()\n# print binary_string + \" \" + np_arr8_string\n\n# Prints the weight. Comment if you're debbuging the MSB and LSB issue.\nval = max(0, int(hx.get_weight(5)))\nprint(val)\nmsg = val\n\n# To get weight from both channels (if you have load cells hooked up \n# to both channel A and B), do something like this\n#val_A = hx.get_weight_A(5)\n#val_B = hx.get_weight_B(5)\n#print \"A: %s B: %s\" % ( val_A, val_B )\n\n#hx.power_down()\n#hx.power_up()\n#time.sleep(0.1)\nGPIO.cleanup()\nreturn msg",
"fnCodePost": "\n# user code here.\n",
"x": 610,
"y": 360,
"wires": [
[]
]
},
{
"id": "49be8df916300aee",
"type": "ui_button",
"z": "5d3ceb36.b1a4a4",
"name": "",
"group": "301ee099fd1bc275",
"order": 1,
"width": 0,
"height": 0,
"passthru": false,
"label": "button",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 330,
"y": 360,
"wires": [
[
"6603f14bc05d712b"
]
]
},
{
"id": "73277f82476c5f13",
"type": "debug",
"z": "5d3ceb36.b1a4a4",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 830,
"y": 360,
"wires": []
},
{
"id": "cbfdd0f743202280",
"type": "python-function-ps",
"z": "5d3ceb36.b1a4a4",
"name": "",
"pythonPathType": "local",
"pythonPath": "python3",
"globalPythonName": "",
"importPathList": [],
"fnCodePre": "\n# user code here.\n",
"fnCode": "import RPi.GPIO as GPIO\n\n# Sets up pins as outputs\ndef setup():\n GPIO.cleanup()\n GPIO.setmode(GPIO.BCM)\n GPIO.setup(29, GPIO.OUT)\n\nif __name__ == '__main__':\n setup()\n GPIO.output(29, GPIO.HIGH)",
"fnCodePost": "\n# user code here.\n",
"x": 590,
"y": 440,
"wires": [
[]
]
},
{
"id": "301ee099fd1bc275",
"type": "ui_group",
"name": "Group 1",
"tab": "58f9a81bce3d8e2d",
"order": 1,
"disp": true,
"width": 6
},
{
"id": "58f9a81bce3d8e2d",
"type": "ui_tab",
"name": "Tab 1",
"icon": "dashboard",
"order": 1
}
]