From Single Program to Multi-program With 2040

by David_Lin in Circuits > Microcontrollers

374 Views, 2 Favorites, 0 Comments

From Single Program to Multi-program With 2040

DSC_2542.jpg

HOW TO WRITE PROGRAM IN MULTI-PRG WITH SINGLE CORE ONLY ?

i'm wondering about what's the difference between arduino nano and pi pico?

compare between the Arduino nano and the Pi pico 2040.

you will find out that the pico is very powerful than the nano is ,

who write the code with pythhon!

program1:

measuretemp2()

shift_out_16_bits()

sleep(0.001)

program2:

GAME()

sleep(0.001)

both spend keep program1 and program2 balance.

How to Run Multi-program in Pico With Single Core Only!?

DSC_2561.JPG

A. what is the different between Arduino nano and Pi pico?

Ans: the answer is coding difference:

1. the Arduino is using the C like language.

2. the Pi pico is using the micro python language.

B. what is the different between C and python ?

1. the most difference is multi-Program:

1.Arduino NONE.

2.PI pico YES.

2. the second one is multi-Core:

1.Arduino NONE.

2.PI pico YES.

3. the third one which is Delay and Sleep does:

1. Arduino Delay means nop (None OPeartion).

2. PI pico Sleep means another program's awake time.

Why ?

DSC_2479.jpg
DSC_2542.jpg

compare between the Arduino nano and the Pi pico 2040.

when run programs in MCU the pico can run more than 25 programs in memory and at the same time

with python!

the nano's memory is not enough for more than 2 programs, even for 2 programs with the MCU.

for example:

when we write the code to do nothing in nano and pico

nano uses the Delay() means to do ***NOP*** ( None O Peration )

pico use the Sleep() means to goto to ***SLEEP***(the other programs are awaken at this time!)

(the left picture above is run temp program to seven segment display with single program single core)

so that is why , the pico can but the nano can not !

(the right picture above is run 2 programs both the temp program and the GAME program at the same time

with single core only)

HOW DOES IT WORK?

multi-program with pi pico.

use "Sleep" ! with python !

the video above is auto run many programs in one tiny board (but not at the same time)

EX:

.

.

. #cut out from GAME()

if (i % 25000 == 0):

temp = measure_temp2() ________#call function:ADC(4) temp

temp10 = digitMap[int(temp)//10 ___#call function:number to 7 segment10

temp1 = digitMap[int(temp-10*(int(temp)//10))] #call function:number to 7 segment1

shift_out_16_bits(temp10*128+temp1+16384*2) _#call function:74595 SHIFT_OUT

time.sleep(0.001) # remain the 7 segment display 1ms

i = 0

else:

time.sleep(0.001)

i = i + 1

. # resume GAME()

.

.

DEMO

2021年3月14日

the video above is running multi-program at the same time.

have fun !