I have a python script to run some leds, and I'm having a problem with
it! When I ssh into my pi zero, then sudo python3 python script.py, it doesn't run, no leds are lit.
But if I open a terminal in the pi desktop and run the same command
line, it works and the leds light up.
Anyone know why this happens.
Hello RobH!
Tuesday November 10 2020 17:40, you wrote to All:
> I have a python script to run some leds, and I'm having a problem with
> it! When I ssh into my pi zero, then sudo python3 python script.py, it
> doesn't run, no leds are lit.
> But if I open a terminal in the pi desktop and run the same command
> line, it works and the leds light up.
> Anyone know why this happens.
Who owns the script.py and where is it ?
Remember sudo takes root priv. and the directory so try :
sudo python3 /home/pi/script.py or whater the user name is along with the correct python run command is.
Vincent
I have a python script to run some leds, and I'm having a problem with it! When I ssh into my pi zero, then sudo python3 python script.py, it
doesn't run, no leds are lit.
But if I open a terminal in the pi desktop and run the same command
line, it works and the leds light up.
Anyone know why this happens.
I ssh'd into my pi zero, then I created the script with : sudo nano
script.py then copied some other python script into the new script.py.
I then ran sudo python3 script.py from within the directory the said
script is in, which is the Downloads directory.
Nothing happens, no errors, no leds lit.
If I open a terminal window on the pi desktop and run the exact same
sudo python3 script.py, it runs and the leds light up
RobH <rob@despammer.com> wrote:
I have a python script to run some leds, and I'm having a problem with it! >> When I ssh into my pi zero, then sudo python3 python script.py, itBecause you have written some very clever code that differentiates
doesn't run, no leds are lit.
But if I open a terminal in the pi desktop and run the same command
line, it works and the leds light up.
Anyone know why this happens.
between a local login and an ssh login! :-) :-)
More seriously I can't think of any obvious answer, we need more
information, or at least *you* need more information. Put some print statements around the code that turns the LEDs and see if it's reached
in bith cases.
On Tue, 10 Nov 2020 20:08:09 +0000, RobH <rob@despammer.com> declaimed the following:
I ssh'd into my pi zero, then I created the script with : sudo nanoMy first question is: WHY use "sudo". Isn't the regular user account a member of a group that has access to GPIO?
script.py then copied some other python script into the new script.py.
I then ran sudo python3 script.py from within the directory the said
script is in, which is the Downloads directory.
Nothing happens, no errors, no leds lit.
pi@rpi3bplus-1:~$ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi
My second would be: Show us the CODE AND the commands you are performing... Don't just "say" what you did -- cut&paste directly from the SSH console into a message.
If I open a terminal window on the pi desktop and run the exact same
sudo python3 script.py, it runs and the leds light up
Again -- show us (cut&paste) the exact command sequence being performed.
However...
pi@rpi3bplus-1:~/Downloads$ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi
pi@rpi3bplus-1:~/Downloads$ sudo groups
root
pi@rpi3bplus-1:~/Downloads$
... the root user (sudo) does NOT appear to have access to GPIO, SPI, I2C, etc.
Without seeing the script one can not tell if errors are being swallowed or just being ignored.
On 10/11/2020 20:28, Dennis Lee Bieber wrote:
On Tue, 10 Nov 2020 20:08:09 +0000, RobH <rob@despammer.com> declaimed
the
following:
I ssh'd into my pi zero, then I created the script with : sudo nanoMy first question is: WHY use "sudo". Isn't the regular user
script.py then copied some other python script into the new script.py.
I then ran sudo python3 script.py from within the directory the said
script is in, which is the Downloads directory.
Nothing happens, no errors, no leds lit.
account a
member of a group that has access to GPIO?
pi@rpi3bplus-1:~$ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev
gpio
i2c spi
My second would be: Show us the CODE AND the commands you are
performing... Don't just "say" what you did -- cut&paste directly from
the
SSH console into a message.
If I open a terminal window on the pi desktop and run the exact same
sudo python3 script.py, it runs and the leds light up
Again -- show us (cut&paste) the exact command sequence being
performed.
However...
pi@rpi3bplus-1:~/Downloads$ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev
gpio
i2c spi
pi@rpi3bplus-1:~/Downloads$ sudo groups
root
pi@rpi3bplus-1:~/Downloads$
... the root user (sudo) does NOT appear to have access to GPIO, SPI,
I2C,
etc.
Without seeing the script one can not tell if errors are being
swallowed or just being ignored.
This is the script:
pi@raspberrypi:~/Downloads $ sudo nano ledstest.py
import board
import neopixel
from time import sleep
pixels = neopixel.NeoPixel(board.D18, 56, brightness =1)
pixels.fill((0, 0, 0))
sleep(2)
pixels.fill((0, 0, 255))
pixels.show()
pi@raspberrypi:~/Downloads $ sudo python3 ledstest.py pi@raspberrypi:~/Downloads $
On 10/11/2020 19:38, Chris Green wrote:
RobH <rob@despammer.com> wrote:
I have a python script to run some leds, and I'm having a problemBecause you have written some very clever code that differentiates
with it!
When I ssh into my pi zero, then sudo python3 python script.py, it
doesn't run, no leds are lit.
But if I open a terminal in the pi desktop and run the same command
line, it works and the leds light up.
Anyone know why this happens.
between a local login and an ssh login! :-) :-)
More seriously I can't think of any obvious answer, we need more
information, or at least *you* need more information. Put some print
statements around the code that turns the LEDs and see if it's reached
in bith cases.
Putting
print.pixels.fill((0, 0, 0))
sleep(2)
print.pixels.fill((0, 0, 255))
print.pixels.show()
produces this error:
File "ledstest.py", line 6, in <module>
print.pixels.fill((0, 0, 0))
AttributeError: 'builtin_function_or_method' object has no attribute
'pixels'
But as I said, the script runs perfectly well in a terminal on the pi
desktop
Thanks
On 10/11/2020 20:43, RobH wrote:I'll repeat my previous question: WHY are you using SUDO?
pi@raspberrypi:~/Downloads $ sudo nano ledstest.py
import board
import neopixel
from time import sleep
pixels = neopixel.NeoPixel(board.D18, 56, brightness =1)
pixels.fill((0, 0, 0))
sleep(2)
pixels.fill((0, 0, 255))
pixels.show()
File "ledstest.py", line 6, in <module>
print.pixels.fill((0, 0, 0))
AttributeError: 'builtin_function_or_method' object has no attribute
'pixels'
pi@rpi3bplus-1:~$import board
import neopixel
import time
pixels = neopixel.NeoPixel(board.D18, 56, brightness = 1)
pixels.fill((0, 0, 0))
time.sleep(2)
pixels.fill((0, 0, 255))
pixels.show()
time.sleep(2)
exit()
On Tue, 10 Nov 2020 20:48:51 +0000, RobH <rob@despammer.com> declaimed the following:
On 10/11/2020 20:43, RobH wrote:I'll repeat my previous question: WHY are you using SUDO?
pi@raspberrypi:~/Downloads $ sudo nano ledstest.py
Develop using the default account, and only use SUDO when the system tells you that you don't have privileges to perform some action. (Okay --
it seems Adafruits neopixel library does claim it needs to be run as root; likely due to the need to set up DMA, but editing the script sure doesn't need to be done using "sudo")
import board
import neopixel
from time import sleep
pixels = neopixel.NeoPixel(board.D18, 56, brightness =1)
That's a pretty long Neopixel strip, if it has 56 pixels on it.
pixels.fill((0, 0, 0))
sleep(2)
The above fill appears to be a do nothing as you don't issue a .show() {You are filling the pixel array with all-OFF, sleeping 2 seconds, and then...
pixels.fill((0, 0, 255))
pixels.show()
... filling the array with all-BLUE, then issuing a .show() command to send these to the Neopixel strip. You also do not have anything delaying the program after this .show().}
The Neopixel library has a built-in clean-up method which sets everything back to OFF and .show() it when your "pixels" object is garbage collected, and that occurs immediately after your pixels.show() statement, since the program itself ends at that point.
And to save some traffic...
File "ledstest.py", line 6, in <module>
print.pixels.fill((0, 0, 0))
AttributeError: 'builtin_function_or_method' object has no attribute
'pixels'
Of course that fails. print() is a function which takes as argument the item to be printed.
print(pixels.fill((0, 0, 0)))
Note that if the .fill() call does not return any status, this will print
None
Try running in interactive mode (entering each line at the prompt, as shown here. NOTE: I don't have a Neopixel strip attached, I'd have to hook
an oscilloscope to D18 to see if anything happens -- more than I want to
try at this moment.
=-=-=
pi@rpi3bplus-1:~$ sudo python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
pi@rpi3bplus-1:~$import board
import neopixel
import time
pixels = neopixel.NeoPixel(board.D18, 56, brightness = 1)
pixels.fill((0, 0, 0))
time.sleep(2)
pixels.fill((0, 0, 255))
pixels.show()
time.sleep(2)
exit()
=-=-=
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 285 |
Nodes: | 16 (2 / 14) |
Uptime: | 64:27:56 |
Calls: | 6,488 |
Calls today: | 1 |
Files: | 12,096 |
Messages: | 5,274,794 |