Name 'DigitalOutput' is not defined

Supporting 2.7 and 3.2+
Post Reply
khun
Phidgetly
Posts: 29
Joined: Tue Oct 27, 2020 8:44 am
Contact:

Name 'DigitalOutput' is not defined

Post by khun »

Hi!

I was able to get a light sensor turning on the light in our carport working with a Phidget 0/16/16 board from a Raspberry Pi a while ago.

Now I wanted to expand things, reinstalled the libraries to be up-to-date and suddenly things don't work! Very annoying!

All installation parts seem to have gone well.

Here is the start of my Python code, which has worked well for a year or so:

from Phidget22.Phidget import *
from Phidget22.Devices.DigitalOutput import *
from Phidget22.Devices.DigitalInput import *
from Phidget22.Devices.Log import *
from Phidget22.LogLevel import *
from threading import Timer
import time

PhidgetSerialNumber = 346483;
phOutput = [DigitalOutput() for i in range (0, 16)]

But now I suddenly can't connect to this Phidget and Thonny shows an error in line 10: Name 'DigitalOutput' is not defined. I don't understand what has happened and how to solve this!

Any help much appreciated!
khun
Phidgetly
Posts: 29
Joined: Tue Oct 27, 2020 8:44 am
Contact:

Re: Name 'DigitalOutput' is not defined

Post by khun »

I forgot to mention that Phidget22admin shows that the Phidget is indeed connected and working OK...
khun
Phidgetly
Posts: 29
Joined: Tue Oct 27, 2020 8:44 am
Contact:

Re: Name 'DigitalOutput' is not defined

Post by khun »

I suddenly realized there was a semicolon at the end of one line there (habit from C++), so I thought I found the problem. Alas, removing it didn't help...
khun
Phidgetly
Posts: 29
Joined: Tue Oct 27, 2020 8:44 am
Contact:

Re: Name 'DigitalOutput' is not defined

Post by khun »

Finally I realized that if I do "sudo bash" and run "python MyScript.py", it works!

So somehow I am suddenly not running Thonny Python IDE as administrator anymore? I must have done so before, because when I first programmed this code, it worked. Do I have to give my user "pi" on this Raspberry some kind of permission to the Phidget libraries that has been lost in the update process?
khun
Phidgetly
Posts: 29
Joined: Tue Oct 27, 2020 8:44 am
Contact:

Re: Name 'DigitalOutput' is not defined

Post by khun »

Problem solved: I edited the shortcut for starting Thonny to have "sudo" first in the command line. But why this suddenly became necessary, I still don't understand!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests