Erratic reading of analog with explore hat pro


#1

I’m Jan and I do a lab support for IoT students
Currently we are using RPi with Explore Hat Pro for simple exercises using Node-RED
There is a problem with erratic reading of ADC as described here


#2

Ahoy!

I actually got your email regarding this, but I’ve got no good solution to the problem yet because the last time I tried to even set up Node-RED to test and fix it, everything broke and I haven’t touched Node since.

It seems you might have a different issue, though, since the erratic values are coming from that ADC input. Could you possibly run a Python script to read that input and see if you get a similar result?

Just something like:

import explorerhat
import time

while True:
    print(explorerhat.analog.one.read())
    sleep(0.01)

#3

Hi,

Thanks for replying.

When using a python API, I have a stable and correct analog reading.

Following that my approach is:

In node-RED I use system exec node to execute periodically the python code:

import explorerhat
print(explorerhat.analog.one.read())

that gives the output to stdin:

root@raspberrypi:~# python /root/.node-red/my_code/analog_test1.py
Explorer HAT Pro detected…
2.328

Explorer HAT exiting cleanly, please wait…
Stopping flashy things…
Stopping user tasks…
Cleaning up…
Goodbye!
Segmentation fault
root@raspberrypi:~#

Is there a way to suppress an unwanted text?

(as I need only the value 2.328)

so I need to extract a sub-string as per attached flow below, wasting time

The flow I created is:

[
{
“id”: “9307b5e0.b67288”,
“type”: “tab”,
“label”: “Read Analog 1”
},
{
“id”: “fca14468.a9cdd”,
“type”: “debug”,
“z”: “9307b5e0.b67288”,
“name”: “”,
“active”: true,
“console”: “false”,
“complete”: “payload”,
“x”: 535.3333129882812,
“y”: 62,
“wires”: []
},
{
“id”: “65af5a36.1af244”,
“type”: “exec”,
“z”: “9307b5e0.b67288”,
“command”: “python3 /root/.node-red/my_code/analog.py “,
“addpay”: true,
“append”: “”,
“useSpawn”: false,
“timer”: “20”,
“name”: “Read Analog 1”,
“x”: 338.33331298828125,
“y”: 111.83334350585938,
“wires”: [
[
“3fa4fa02.4758ce”
],
[],
[]
]
},
{
“id”: “a2880596.0f82d”,
“type”: “inject”,
“z”: “9307b5e0.b67288”,
“name”: “”,
“topic”: “”,
“payload”: “”,
“payloadType”: “date”,
“repeat”: “2”,
“crontab”: “”,
“once”: true,
“x”: 146.33331298828125,
“y”: 110.33334350585938,
“wires”: [
[
“65af5a36.1af244”
]
]
},
{
“id”: “3fa4fa02.4758ce”,
“type”: “function”,
“z”: “9307b5e0.b67288”,
“name”: “”,
“func”: “var str = msg.payload;\nvar res = str.substring(32, 36);\nmsg.payload = parseFloat(res);\n//msg.payload = res;\nreturn msg;”,
“outputs”: 1,
“noerr”: 0,
“x”: 345.5,
“y”: 58.333335876464844,
“wires”: [
[
“fca14468.a9cdd”,
“56164c32.4ead5c”
]
]
},
{
“id”: “56164c32.4ead5c”,
“type”: “ui_chart”,
“z”: “9307b5e0.b67288”,
“name”: “”,
“group”: “9fb0a875.681e08”,
“order”: 0,
“width”: 0,
“height”: 0,
“label”: “chart”,
“chartType”: “line”,
“legend”: “false”,
“xformat”: “HH:mm:ss”,
“interpolate”: “linear”,
“nodata”: “”,
“ymin”: “”,
“ymax”: “”,
“removeOlder”: 1,
“removeOlderPoints”: “”,
“removeOlderUnit”: “3600”,
“cutout”: 0,
“colors”: [
#1f77b4”,
"#aec7e8",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
“x”: 559.5,
“y”: 140.3333511352539,
“wires”: [
[],
[]
]
},
{
“id”: “9fb0a875.681e08”,
“type”: “ui_group”,
“z”: “”,
“name”: “Default”,
“tab”: “1033145.0ce0aec”,
“disp”: true,
“width”: “6”
},
{
“id”: “1033145.0ce0aec”,
“type”: “ui_tab”,
“z”: “”,
“name”: “Home”,
“icon”: “dashboard”
}
]