Not possible to read all values in SenseHat-Node

Hello together,

Last week I gave an IoT Course in Azure by using Raspberry Pis with a Sensehat. For connection, processing and data output to the cloud I was using Node-Red. Before I updated to the newest version of Pi-OS and Node-Red. But I got a problem with the Sensehat-Node. In the old version (0.) I could read enviroment, motion and joystick parallel. But now it seems to be stucked to use all groups together. If there are activated all three groups only enviroment or motion will be processed or seen in the debug node.
In the end I had to correct the exercises to read only one group. So my question is, if there exists a solution or bug-fix for this problem.

I was using a Pi Version 3 and 3B+.

Best regards from Dresden
Stephan

This is a known problem with python3. There was a change in python3 that causes the problem with the node`s code.

If you do a search on the forum using sensehat you will find the reports of the problem. I topknot a stab at updating the code along time ago but I’m not a python coder :worried:

1 Like

Hey,

thanks for the fast answer. I was googeling for the error a few hours and also searching in the forum for a few minutes. Could not find something until I search for "python Sensehat". Then I saw your post. :slight_smile:

Do you have any idea what the error in the Python code could be? Any hint or idea would be helpful. I know Python and maybe I find the time to debug the code.

Here is a link to the code:

Thanks for sharing the link, but I found the source code a few hours ago and are looking for some suspicious lines in the moment. So far everything seems fine. It is a tough problem without debugging options.... :confused:

I found something interesting. When I change the two variables in the python code to "True" it seems to work:

hf_enabled = True
lf_enabled = True

(Line 68). Could you check it with your device, please? :slight_smile:

I'll check it out tomorrow since I have a test running on the Pi with the sensehat on it.

Nope, that doesn't fix the issue.

The issue is that when you have all three options checked in the node, 'environment' is never returned.
Here is a simple test flow so you can see the number of msgs returned.

Remember the if you change sensor hat.py you must restart Node-RED before testing again.

NOTE: you will have to install 'node-red-contrib-counter' for this flow.

[{"id":"a94be90051639b30","type":"switch","z":"72bc62f170dc8752","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"environment","vt":"str"},{"t":"eq","v":"joystick","vt":"str"},{"t":"eq","v":"motion","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":450,"y":420,"wires":[["00565d90f8b06675","a3fdd7a258d8506b","1d8cadbb78ae0076","5628700cc303ddec"],["f79dfaa36cd93353","808f259f9bfd243b"],["cec6e96f900abe26"]]},{"id":"2f281db51b977dbd","type":"rpi-sensehat in","z":"72bc62f170dc8752","name":"","motion":true,"env":true,"stick":true,"x":280,"y":420,"wires":[["a94be90051639b30"]]},{"id":"808f259f9bfd243b","type":"counter","z":"72bc62f170dc8752","name":"joystick","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":620,"y":420,"wires":[["2db1fdc0ca54e01e"]]},{"id":"5628700cc303ddec","type":"counter","z":"72bc62f170dc8752","name":"environment","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":630,"y":360,"wires":[["e6014bc89d73560d"]]},{"id":"cec6e96f900abe26","type":"counter","z":"72bc62f170dc8752","name":"motion","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":610,"y":480,"wires":[["d1b47431a5a8936e"]]},{"id":"e6014bc89d73560d","type":"debug","z":"72bc62f170dc8752","name":"environment","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"count","targetType":"msg","statusVal":"payload","statusType":"auto","x":810,"y":360,"wires":[]},{"id":"2db1fdc0ca54e01e","type":"debug","z":"72bc62f170dc8752","name":"joystick","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"count","targetType":"msg","statusVal":"payload","statusType":"auto","x":800,"y":420,"wires":[]},{"id":"d1b47431a5a8936e","type":"debug","z":"72bc62f170dc8752","name":"motion","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"count","targetType":"msg","statusVal":"payload","statusType":"auto","x":790,"y":480,"wires":[]}]

Hmmm, strange, because on my Pi it is working. See the screenshot. But I also changed the hf_interval to 0.9. Further I inserted some print() commands in the while-loop at the end. But I do not think this should have an effect.

  1. What pi are you using?
  2. what OS and version are you running?
  3. what version of python on the pi?
  4. is NR also running on the pi?
    If not, where is it running?
    What version of NR and node.js are you running? (See startup log)
  • Node-RED Version: v3.0.2
  • Node.js Version: v16.19.1
  • Linux version 6.1.21-v7+ (dom@buildbot) (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1642 SMP Mon Apr 3 17:20:52 BST 2023
  • Raspberry Pi 3 Model B Plus Rev 1.3
  • Python 3.9.2 (default, Mar 12 2021, 04:06:34)

I installed last weekend the newest version of PiOS and after that Node-Red and the SenseHat-Node. Node-Red is running on the Pi, but I am looking at the website from my Mac via local network.

Hope that helps.

Hmmm, I'm running it on a
Pi 3 Model B Rev 1.2
using Buster (lite)
python 3.7.3
NR 3.0.2
Node.js 16.19.1

So NR and Node.js are the same and the rest is different. I'll try and flash another SD card but it will have to wait, grandkids depending (grin)

Well this is very interesting! With the updates done, when I run the flow (none of your edits to the code) it only shows motion and joystick data. But, if I send a character to display on the LEDs, suddenly the environment data starts showing up too!

Can you add this flow to your flow and see if activating the LEDs causes the others all to work.

[{"id":"1a13a2b31e5e71f3","type":"inject","z":"72bc62f170dc8752","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"*,*,red","payloadType":"str","x":150,"y":80,"wires":[["3149dd2b6fb6bf43"]]},{"id":"3149dd2b6fb6bf43","type":"rpi-sensehat out","z":"72bc62f170dc8752","name":"","x":630,"y":100,"wires":[]},{"id":"601c24e43f84de73","type":"inject","z":"72bc62f170dc8752","name":"clear LEDs","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":" ","payloadType":"str","x":160,"y":120,"wires":[["3149dd2b6fb6bf43"]]}]

Hey again,

so I reveserd my changes, (hf,lf_enabeld set to False and hf_interval to 0.09) and the old bug was there again. Then I tried with your "character-flow" and it was working.

Maybe it is a malfunction of the initalisation process. That would explain "my" and "your" solution. I guess something is wrong with the

  if data[0] == "X":
    if data[1] == '0':
      hf_enabled = False
    else:
      hf_enabled = True
  elif data[0] == "Y":
    if data[1] == '0':
      lf_enabled = False
    else:
      lf_enabled = True

part.

So I reduced the changes further and found out the only line to change is "lf_enabled=true". After this it works for me. So I assume strongly that your "character-flow" sets data[0]=="Y" and data[1] something unequeal 0.

Good International Teamwork by the way :wink:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.