Python Forum
raspberry pico second core ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
raspberry pico second core ?
#1
hello,

why am I working on the 2nd core?
I am working with a stepper motor that makes a movement from left to right, which takes about 25,000 pulses, 1 pulse is about 1 millisecond.
for every 100 pulses I want to send a message over the UART, which takes about 75 milliseconds.
but the movement of the stepper motor must remain smooth.
so I think: I send a start veriable every 100 pulses to the 2nd core, and let the message be sent there.
I think that should just work.
I am testing that in the code below.
Now I actually have 2 questions:
1 - Does that work with the method I want to use?
2 - I get an error message in this code: where is the error comming from ? the global with test is working fine.
thank you in advance.
Traceback (most recent call last):
  File "<stdin>", line 33, in <module>
SyntaxError: identifier redefined as global
from machine import Pin
import machine
import utime
import time
import _thread

button=Pin(22, Pin.IN, Pin.PULL_DOWN)

led_15              = Pin(15, Pin.OUT)
led_15. value(0)
led_16              = Pin(16, Pin.OUT)
led_16. value(0)

test = False

def core1_task():
    global test
        
    while True:
        time.sleep_ms (5)
        if test == True:
            led_15. value(1)
            time.sleep_ms (1)
            led_15. value(0)
            print ("meassage frome core_1")
            test = False
        _thread.exit()
        
once = 0

while True:
    global once
    
    led_16. value(1)
    time.sleep_ms (1)
    led_16. value(0)
    time.sleep_ms (5)
    
    if button() == 0 and once == 0:
        once = 1
        test = True
        _thread.start_new_thread(core1_task, ())        
        
    print ("meassage frome core_0")
I'm not French, but from the netherlands
Reply
#2
global is only used inside functions. The purpose of global is to tell python that the variable(s) is in the global scope, and assignment to the variable should not create a local variable inside the function. The code where you use "once" is not inside a function. Any variables assigned in the while loop are global.

Interestingly, this is a syntax error:
once = 0
while True:
    global once
    if once == 0:
But this is not. It raises a NameError when run, but it is not a syntax error.
while True:
    global once
    if once == 0:
Reply
#3
Thank you.
I'm not French, but from the netherlands
Reply
#4
thank you
I'm not French, but from the netherlands
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  hardware timer raspberry pico trix 4 286 Jun-27-2024, 09:29 AM
Last Post: Larz60+
Question Sonar Code in Thonny for Pi Pico iansmiler 1 451 Nov-22-2023, 12:27 PM
Last Post: deanhystad
  Illegal instruction (core dumped) when import pandas. amandacstr 1 2,343 Dec-31-2022, 11:31 PM
Last Post: stevendaprano
  ImportError: /home/ali/Documents/test/charm/core/crypto/AES.cpython-39-x86_64-linux-g Anldra12 0 1,341 Apr-28-2022, 07:13 AM
Last Post: Anldra12
  Segmentation fault (core dumped) hobbyist 1 10,880 Jun-07-2021, 12:56 PM
Last Post: supuflounder
  Python script in Ubuntu core Nithin_Kumar 1 3,468 May-11-2021, 01:14 AM
Last Post: Skaperen
  I want to install core mod. Blue Dog 3 3,398 Jul-18-2017, 08:02 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020