Wrote a simple program to blink the onboard led on RP2040. The Thonny Interpreter is: MicroPython (Raspberry Pi Pico). Program has error on line 5. Copied at end of program is the Editor/Run error. If I comment out line 5, another error shows up on line 9 to effect that tuple object has no attribute 'toggle'. Perhaps Thonny has developed an internal error, so I uninstalled it and re-installed Thonny from a fresh download. Same results.
5/29/23, 9:11 AM test led.py *
file:///C:/Users/Administrator/Downloads/thonny-4.0.2-windows-portable/user_data/temp/thonny_ohh9o858.html 1/1
1 import machine
2 from machine import Pin, Timer
3 led = machine.Pin(25), Pin.OUT #onboard led
4 led2 = Pin(16, Pin.OUT) #external led
5 led.on()
6 led2.off()
7
8 def blink(_):
9 led.toggle()
10 led2.toggle()
11 tm = Timer(period = 500, mode = Timer.PERIODIC, callback = blink)
12
13 # >>> %Run -c $EDITOR_CONTENT
14 #Traceback (most recent call last):
15 # File "<stdin>", line 5, in <module>
16 #AttributeError: 'tuple' object has no attribute 'on'
17 #>>>
Pi Pico Thonny Issue
Moderators: adafruit_support_bill, adafruit
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
- dastels
- Posts: 15608
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Pi Pico Thonny Issue
It's nothing to do with Thonny.
led is defined as I suggest you change that to to have the same structure as the definition of led2.
Dave
led is defined as
Code: Select all
machine.Pin(25), Pin.OUT
Code: Select all
Pin(25, Pin.OUT)
Dave
- GilbertGagne
- Posts: 13
- Joined: Mon Nov 09, 2020 12:53 pm
Re: Pi Pico Thonny Issue
Removed 'machine.' from led = machine.Pin(25), Pin.OUT
Same results.
Its gotta be something with Thonny as these statements are directly from Mazidi's book, "Raspberry Pi Pico, Interfacing and Programming with MicroPython"
Same results.
Its gotta be something with Thonny as these statements are directly from Mazidi's book, "Raspberry Pi Pico, Interfacing and Programming with MicroPython"
- dastels
- Posts: 15608
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Pi Pico Thonny Issue
The other difference is to put Pin.OUT as the second argument to the Pin constructor.
Dave
Dave
- GilbertGagne
- Posts: 13
- Joined: Mon Nov 09, 2020 12:53 pm
Re: Pi Pico Thonny Issue
Found problem: Line 3 was missing a right bracket after Pin.OUT
3 led = machine.Pin(25, Pin.OUT) #onboard led
No more error!
Thanks to everyone for looking.
3 led = machine.Pin(25, Pin.OUT) #onboard led
No more error!
Thanks to everyone for looking.
- dastels
- Posts: 15608
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Pi Pico Thonny Issue
As I had pointed out.
Dave
Dave
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/