Page 1 of 1

Name 'DigitalOutput' is not defined

Posted: Sat Feb 18, 2023 1:08 pm
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!

Re: Name 'DigitalOutput' is not defined

Posted: Sat Feb 18, 2023 1:21 pm
by khun
I forgot to mention that Phidget22admin shows that the Phidget is indeed connected and working OK...

Re: Name 'DigitalOutput' is not defined

Posted: Sat Feb 18, 2023 1:26 pm
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...

Re: Name 'DigitalOutput' is not defined

Posted: Sun Feb 19, 2023 8:15 am
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?

Re: Name 'DigitalOutput' is not defined

Posted: Sun Feb 19, 2023 8:24 am
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!