Pinado
Posts: 16
Joined: Mon Jul 15, 2019 8:51 pm
Location: Colorado, USA

Code Help Please

Tue Aug 06, 2019 3:41 pm

Hello all, I am trying to set up a couple of HATS on my raspberry pi and I am having trouble with the code and, because I dont speak python very well, I dont know what the problem is. The code I have right now is

Code: Select all

from sense_hat import SenseHat
from datetime import datetime

sense = SenseHat()
def get_sense_data():
    sense_data = []
    sense.get_temperature()
datetime.now()
while True:
    print(get_sense_data())
and this is what I get back when I try to run it :
Traceback (most recent call last):
File "/home/pi/Desktop/DAQ HAT.py", line 4, in <module>
sense = SenseHat()
File "/usr/lib/python3/dist-packages/sense_hat/sense_hat.py", line 39, in __init__
raise OSError('Cannot detect %s device' % self.SENSE_HAT_FB_NAME)
OSError: Cannot detect RPi-Sense FB device

Any help is appreciated!

scotty101
Posts: 4100
Joined: Fri Jun 08, 2012 6:03 pm

Re: Code Help Please

Tue Aug 06, 2019 4:10 pm

Try adding dtoverlay=rpi-sense to your /boot/config.txt file as described in the below topic that contains the same error message.

https://www.raspberrypi.org/forums/view ... p?t=173113
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Pinado
Posts: 16
Joined: Mon Jul 15, 2019 8:51 pm
Location: Colorado, USA

Re: Code Help Please

Tue Aug 06, 2019 4:24 pm

This is probably a stupid question, but I dont have much experiance with coding,
Where should I enter that code into the list?

Andyroo

Re: Code Help Please

Tue Aug 06, 2019 5:47 pm

There are two schools of thought when adding things to files that already exists:

1) Put it at the start so you can find it.
2) Put it at the end so you can find it
3) Put it close to something similar or what it replaces

(did I say I could count? :lol: )

Basically check if the line exists in the file but starts with a ‘#’, if so remove the hash as it’s a comment. This leaves it where it was but ‘switched on’.

If not, I normally put commands at the end of the file with one or more comment lines giving the reason why I have added the line(s). You may think you will remember what the line does BUT I do not and find comments handy (it’s a age thing :roll: )

Pinado
Posts: 16
Joined: Mon Jul 15, 2019 8:51 pm
Location: Colorado, USA

Re: Code Help Please

Tue Aug 06, 2019 6:08 pm

Okay. Thank you all!

pfletch101
Posts: 630
Joined: Sat Feb 24, 2018 4:09 am
Location: Buffalo, NY, USA

Re: Code Help Please

Fri Aug 09, 2019 8:07 pm

Andyroo wrote:
Tue Aug 06, 2019 5:47 pm
If not, I normally put commands at the end of the file with one or more comment lines giving the reason why I have added the line(s). You may think you will remember what the line does BUT I do not and find comments handy (it’s a age thing :roll: )
I vote for the end (and for the comments :) ), too. Many applications apply the last value they see attached to a parameter which is defined more than once in a config file, and these are generally read from the top, down. Particularly for big config files (weewx, motion,...), where you may miss an occurrence of the parameter you are setting already in the file, putting your version at the bottom gives you the best prospect of it working as you expect.

Return to “General programming discussion”