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/
Locked
User avatar
GilbertGagne
 
Posts: 13
Joined: Mon Nov 09, 2020 12:53 pm

Pi Pico Thonny Issue

Post by GilbertGagne »

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 #>>>

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: Pi Pico Thonny Issue

Post by dastels »

It's nothing to do with Thonny.

led is defined as

Code: Select all

machine.Pin(25), Pin.OUT
I suggest you change that to

Code: Select all

Pin(25, Pin.OUT)
to have the same structure as the definition of led2.

Dave

User avatar
GilbertGagne
 
Posts: 13
Joined: Mon Nov 09, 2020 12:53 pm

Re: Pi Pico Thonny Issue

Post by GilbertGagne »

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"

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: Pi Pico Thonny Issue

Post by dastels »

The other difference is to put Pin.OUT as the second argument to the Pin constructor.

Dave

User avatar
GilbertGagne
 
Posts: 13
Joined: Mon Nov 09, 2020 12:53 pm

Re: Pi Pico Thonny Issue

Post by GilbertGagne »

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.

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: Pi Pico Thonny Issue

Post by dastels »

As I had pointed out.

Dave

Locked
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/

Return to “Adafruit Raspberry Pi® accessories”