Це відео не доступне.
Перепрошуємо.
Programming a Raspberry Pi Pico with C or C++
Вставка
- Опубліковано 4 сер 2024
- In my previous video I showed you how to use the Raspberry Pi Pico with MicroPython. In this video I take a took at using C or C++ and cover how to run code on the second Cortex-M0+ core.
Full instructions and code examples: github.com/garyexplains/examp...
Open GUI apps on Windows Subsystem for Linux (and on Raspberry Pi: • Open GUI apps on Windo...
Introduction to Android app development: www.dgitacademy.com
Let Me Explain T-shirt: teespring.com/gary-explains-l...
Twitter: / garyexplains
Instagram: / garyexplains
#garyexplains
Thank you for a great tutorial. Very useful. As an experiment I wrote C++ and MicroPython programs to toggle an IO pin without any delays. Python managed about 60KHz will lots of jitter, C++ ran at 37MHz without jitter - over 500x faster.
i think you mistakenely switch K and M.... did you wanted to say 60MHz and 37kHz ??
@@yash1152 Unfortunately not. C++ was much faster than Python, probably because C/C++ is compiled to machine code, whereas Python is interpreted at runtime.
@@g0hjq ohwww, ohkayy...... I missed reading the "toggle an IO pin" part, and assumed it was the chip spec on which they were running.
How did you measure jitter? Were you monitoring it on a scope?
@@sorova Yes, it was very easy to see.
This is brilliant Gary thank you for doing this. This really shows the power of what is possible here! Taking full advantage of the dual cores is a very much needed gem of a video thank you!
Gary, this is fantastic! So much knowledge in 20 minutes! I've tried setting up C++ before and failed (I did not use WSL and got errors on cmake), hopefully will succeed with your help.
Extremely interesting stuff , I mean one of the limitations of arduino is that it was single core , so if you had to handle an event you had to use an interrupt which needed to be kept short , but with this one ; one core could do the communication and monitor the pins while the other is making computationally intensive tasks .
Thanks for the demos and detailed information. Really informative videos and inspiring. Mine's on order now!
Thanks Gary, the Pico project gen' was the thing I missed trying to get the USB serial data. Great work keep it up :)
Thanks for useful tutorial. Got up and running on Linux in half an hour. Was getting tired of Arduino and its extremely low RAM. Two cores is pure luxury for a microcontroller, and as your example shows, they are easily utilized. Great!
Great video, I did this onArchlinux and everything worked just fine.
I used this video to really get in to c developing for pico, thanks you very much.
One question for the people out there, someone has found a way to control an i2c oled in c using Pico? I only found tutorials on how to do it with micropython or circuit python
Another excellent video, wonder how long before VC + Platform IO has native Pico support allowing for easier C programming on a PC and other platforms.
Very interesting. Thanks Gary!
Cool guide, Gary! Thanks!
Glad it was helpful!
I am suitably chastened by this brilliant video. Any thoughts I might code in C on a Pico are thoroughly debunked, and I shall very reluctantly pick up the Python handbook and learn another total mess of a programming language instead!! 😂
Kudos to Gary. That's what a proper coder can do. I'm going to tell my boss that the Pico must have been lost in the mail, and hopefully he'll forget about the whole thing 😉
Going to give the Pico a try when they arrive. Should be a fun mcu, and fun to program in C.
The final example of push/pop between cores should have synced both LEDs to be on and off at the same time (per the coded example) but it looks like the same video from previous build was shown with LEDs blinking opposite from each other.
Probably.
Interesting as usual Gary, thank goodness for Thonny and micropython though
Thank you for doing this video. I found some instructions on the web, but they were incomplete. I needed the project generator, and the python-tk (tkinger). That it came together. Easy as Pi. Ok, it is a bit more involved... I don't have the picos yet, but I have the development environment set up and can build a uf2 file.
Hi, I have a question about what is happening at 6:40. When I installed wsl, it created a username and directory that I cannot find in C\Users or anywhere in my file explorer, but I got everything installed up to this point, in a directory called pico, etc. Command 'pwd' shows that a linux 'home' directory was created but I cant find any of this on my system through windows explorer. Not sure how to do the PATH, /mnt/ stuff now. Again, when I installed wsl it just handed me a username (maybe based on my Windows ID, not my pc 'name') without asking me and created some secret directory somewhere; I'm not sure how to proceed. Do I really need the windowing system in general or is it just for the demos?
It might be helpful to specify which version of WSL you are using. How you might set this up could vary between versions. E.g., I believe that on WSL 2, it’s better to use the ‘internal’ Linux file system as WSL2 is VM based. There are/were also issues around serial ports in WSL2. Probably best to stick to WSL1 for this kind of stuff ATM. Great video. Thank you. 👍🏼
Yes you are correct. This is for other readers as I guess you know this already. Wsl2 recommended, Wsl2 better to keep files inside wsl file system. To view files in Explorer then from ubuntu cli then type Explorer.exe. That is a dot following exe to open current directory then copy file to pico
I can't get the serial monitor working, inside Arduino IDE the port option is greyed out and trying to open the terminal errors to "board on null not available"
Very very helpful. Thank you❤
You’re welcome 😊
Thank you!
I wonder if both cores share the same memory or even context within the code. Like if for example I had the pico constantly polling a couple gpio pins with one core and processing and sending their data through serial with the other core, if I saved the state of the gpio on different variables, would I be able to access their values from the second core?
There is lots of good documentation about this on the Raspberry Pi website. The recommended method is to use the FIFOs supplied by the SDK.
Great video as usual, but why run under WSL on a windows machine instead just following the setup instructions for running under windows 10?
I had a go at setting up Visual Studio Code on a PC running Ubuntu by following the instructions for RPi, but encountered too many hurdles and had to give up!
So did you manage to program rpi pico in C under win10? Because this is what I am looking for...
Perfect 👌👌
Thanks 😊
Было полезно, смотрел с переводом, плата пико уже заказана и едет, жду не дождусь когда смогу начать экспериментировать с ней
Very nice. This is something I want to try when I get my own laptop rather than use my works laptop
Can you explain how to write C for core 2 and Python for core 1?
Isn't Arduino on the way, with support for the processor too?
Thanks for sharing your experience with all of us👍😀
Yes, it is
Hi Gary, long time no see. You ever go back to the University of Portsmouth?
Seems like a decent little device.
Very interesting Gary! Can you run Julia on it?
Many many Thanks.
You are most welcome
What about the latest version of Code::Blocks IDE Cross Compiler and gcc-arm-eabi
Thank sir
I get the error: couldn't connect to display "127.0.0.1:0" what should I do?
You must start X-Windows - run Xterm, you should see the icon on the bottom right of your taskbar
Can it be programmed with Rust?
hlo sir i don't know about python i know about c for arduino can i use pi pico
Where is a link to the installation of the x server?
Sorry, I forgot to include it in the description, however it was in the README file in my GitHub. I will fix the description. The link is ua-cam.com/video/ymV7j003ETA/v-deo.html
Wait, after you build Cmake with gcc, shouldn’t you then rebuild Cmake with Cmake?
Great explanation! Looking forward to the rust edition :-)
+1 for the Rust version! Love Rust!
Good lord Linux is about a cryptic as it comes.
Great stuff here, however, I am running into an issue where even if I do the "export PICO_SDK_PATH" command correctly, pico_project.py will pop up and tell me it is unable to locate the pico sdk path. I am very frustrated and have tried everything.
a workaround i have found was to edit pico_project.py and during the check for the sdk path, i simply set sdkPath equal to my pico sdk path. Not ideal, but it works
I have been unable to get this to work. I installed X-Server, but when ti run the ./pico_project.py --gui command, I get an error saying _tkinter.TclError: couldn't connect to display "127.0.0.1"
Me too, the same error...
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1
see: wiki.ubuntu.com/WSL#Running_Graphical_Applications
You must start X-Windows - run Xterm, you should see the icon on the bottom right of your taskbar
@@cdgal You just have saved my day! Really Really Really thanks! ^^
Just to add some, I did [ ua-cam.com/video/iKhGnj69XzQ/v-deo.html ] and worked
Trying this with Ubuntu 21.04 and latest Cmake v3.21.0 and the make process fails, "CMake Error at CMakeLists.txt:107 (message):
The C++ compiler does not support C++11 (e.g. std::unique_ptr)". Re-tried with the same versions of Ubuntu and Cmake as you use in the video, same error.
Problem solved - you must use WSL v1, not WSL v2
Hi - Late to the channel - but love your videos. However - one thing I noticed may be an editing error - at 14:36 when you show the two leds on 2 cores using messaging, the video of the blinking is incorrect - it shows the leds blinking alternately with equal duration, while the code was asynchronous with one led twice as fast as the other! Sorry to be nit-picky, but things like that could confuse beginners. Keep up the great work.
Yes, it was a footage mix up,it has been mentioned in the comments elsewhere.
it compiles but VSCODE gives me errors for the includes and constants... how can I fix that?
I see that you also have "#include "pico/stdlib.h"" underlined like I do. I can not run step by step on vscode I get an error that says pico/stdlib.h: No such file or directory
Is it possible to step through the code and set up breakpoints in vscode using this method? Is so how? Please help! Thank you so much! Great Video!
Did u got any solution? If you got any solution please help. I am also in the same situation.
Thanks for a great tutorial. Sadly I couldn't continue from where you were explaining X11 monitor stuffs. I don't have a raspberry pi to run on. How can I proceed without an other raspberry pi or other machine at all? Thanks a lot!
Okay, so I checked the docs right after I wrote. Letting others with the same problem know and hopefully also get som help on my next problem. So it seems like I don't have to use any GUI, so I instead used the terminal and wrote: "./pico_project.py -usb blinky" which should give me a generated.
but that gives me "Unable to locate the Raspberry Pi Pico SDK, PICO_SDK_PATH is not set" which I actually set when watching the tutorial. Any reason known why this is happening?
I can also see that it is set by "echo $PICO_SDK_PATH"
For those who has the same problem, just edit your /etc/environment file and add the ENV variable
I think you do great videos.
Glad you like them!
thanks alots
Why are the two includes showing error?
What a pain to set up. I'm going to wait for a better Pico IDE.
vs.code together with a second pico set up as a picoprobe connected to the SWD pins make a pretty decent dev environment
Apparently someone has now got the Arduino IDE working with the Pico.
Been 2 years and I'm still having issues getting the SDK to work properly on VS code
I'm not finding anywhere in the internet how to program the raspberry pi Pico registers in c. Do you know how?
Yes, look at my videos about Piccolo OS, there is lots of register programming involved in that.
There are several tools to monitor the Serial Port, for instance: minicom, cutecom, screen ....
Can't we use the other core in micropython?
Sure, of course. See github.com/raspberrypi/pico-micropython-examples/blob/master/multicore/multicore.py
@@GaryExplains thank you xD
@@supreetyadav5021 important to note here muticore fifo implementation on pi pico is mostly hardware, so in case of c++ program can work even faster than on latest intel cpu.
Thank you very much! Very usefull. May I ask you to make a tutorial with a rotary encoder connected via 1 or/and 2 irqs to the pico? I am struggeling with this, because there is no Encoder library.
VS Code has a serial monitor as well.
You can also use Forth and BASIC.
Using putty for serial connection will be more convenient i guess. Opening the whole IDE just for serial monitor is kinda overkill
I think that putty has a problem in that it can't leave the connection open when the board of rebooted. I found it much more difficult to use than the Arduino serial monitor.
@@GaryExplains good point, but still weird that you need two IDE to and debug the code. If connection is dropped, right click on the top left corner of putty and select Restart Session. C/C++ is super powerful, but most of people would prefer easy ways of setting up their programming tools. Are there any lightweight IDEs that support C/C++ and can keep serial connection open?
Gary keep getting this error: E: Unable to locate package tkinter
Sorry, that is a mistake in the instructions, I will fix it soon. Just leave that out of the command.
use this command instead "sudo apt install gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential libssl-dev tk python3-tk"
Do Raspberry Pi Ltd have an ARM licence, or did they use a third party to design and manufacture the RP2040?
It likely has an entry level license to use the Cortex-M0+. Arm has quite a few "quick start" schemes for its Cortex-M range.
Gary you are the man. What is your profession?
UA-camr? 🤔
my is keep crashing.Win version 20H2 Build 19042.1237
Ah, I remember the C development cycle. Edit, save, make, upload, boot, test then repeat.
I've got PicoMite MMBASIC on mine and this same thing is Edit, Run then repeat. A much faster development cycle.
Would be okay if you showed us from scratch, I don't know how you opened that terminal from the start.
It just doesn't work for me....
The xhost + fails, and same goes for the cmake .. and make commands.....
Idk what you did but it just doesn't work for me
Anyone out there one a purely Raspberry Pi Pico C/C++ Visual Studio video? Tired of all the Cmakes/Gits... Just want to build from scratch...
Getting through running all those commands was a nightmare, spent 4 hours just solving random errors. Why does it never just work 🤣
Boku no Pico
Best Anime
So, at 14:34, why wasn't LED_PIN14 flashing twice as fast as LED_PIN25? I smell a rat! LED_PIN14 delays are set to 500ms whilst LED_PIN25 delays are set to 1000ms
Ah, I see what you mean now (following your edit of your comment). Yeah, that means I mixed up the footage when I edited the video. Sorry about that.
*GARY!!!*
*Good Evening Professor!*
*Good Evening Fellow Classmates!*
Stay Safe Out There Everyone!
MARK!
I am the 1K liker
This puts me off ever attempting it.
What an heresy using arduino to monitor rpi pico! 😂😂😂
The multicore example showed code to flash one LED at double the rate of the other, yet that didn't happen. Did you just use the wrong clip in the video?
Yes, I used the wrong clip. Sorry.
@@GaryExplains That's good. It means I did understand what was happening.
I find C tutorials entertaining, is that normal?
I bet it runs about 20 times faster too than Python.
Problems found:
1-unable to connect to display 127.0.0.1:0
To solve just install VcXsrv to windows...
2-pico-project-generator claims about CMAKE_CXX_COMPILER not defined
To solve in the same terminal you run pico-project-generator do this exports:
export CC=arm-none-eabi-gcc
export CXX=arm-none-eabi-g++
3- Now I am strungling with:
/build/newlib-CVVEyx/newlib-3.3.0/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:64: undefined reference to `_exit'
I have no ideia how to solve it yet...
4 - Item #3 was solved starting from scratch and following the Gary instructions from github.com/garyexplains/examples/tree/master/Raspberry%20Pi%20Pico/C in readme.md, and not instructions from video.
I remember solving the 1st one somehow but now I am stuck with it again even though I got everything on.
Edit:
Found it in my history:
export DISPLAY=$(ip route list default | awk '{print $3}'):0
installing GB for programing a 32bit micro controller to blink an LED WTF we are in 2021 not 1990 :-)
Thank you for this video on C on the Pico instead of that _dreaded_ Python shite. I hate Python with a passion because:
1. Python code is not backward compatible. Yep, that's right: all you hard work for a Python ver. 2 script won't do you any good in Python 3. Bye, bye hard work. C has been around since the 1980's and your code'll work forever.
2. It's a scripting language that needs the Python executable. It's not a programming language: you can *not* make actual programs with Python.
3. Python code ain't backward compatible.
4. Python code ain't backward compatible. It's utter and utter shite.
So frustrating! Been searching for a month now how to get started with this snake language. But NOWHERE is there any explanation of how to open the terminal window or WHERE to download it from.
I think I should better stay with arduino?
I am assuming you are taking about the Windows Subsystem for Linux (WSL)? If so, I have several videos about how to set it up, here on this channel.
Many thanks for your reply. I'm on windows 7.
Been looking for a tutorial on how to get started from the point of not having a clue what the very first step is. (Just bought a pico).
All turorials say "open terminal window".... sure... WHERE or WHAT icon do I click to open the terminal window? LOL
oh... and then they type some weird stuff in there at lightning speed.
I have a good understanding of C++ but this snake (python) language scares me.
Nany thanks for your videos and for sharing your kowlege. I'll dig deeper into your previous videos.
Just as a first pointer, you need Windows 10 for WSL.
Oh dear! Many thanks for the heads up.
I guess that'll be the end of my quest getting into anything rasberry or pie things.
I cannot afford win 10.
0 progress. couldn't download most of the packages and execute many commands, I'm on windows 10 and he's just showing ubuntu linux commands
There is plenty of documentation on the Raspberry Pi website about how to install the tools on native Windows. But just to clarify, I am using Windows 10, but I am using WSL, the Windows Subsystem for Linux.
@@GaryExplains Eventually i found a way to make it work, your video did help me in knowing what packages i had to install, I'm sorry if i offended you in any way, didn't mean to show any kind of hate! Keep it up!
First
Where did you learn how to make a project? This is not it the Getting Started C/C++ doc. Also, just my 2 cents, I'm an electrical engineer with an advanced degree and this workflow is kind of ridiculous for a hobbyist product.
Oh, it's way off in chapter 8 lol I should have looked more closely.
Man nothing in my setup matches the documentation. Honestly, just programming a real microcontroller in Code Composer and Flashing with a J-Link is easier than this. I've never been impressed with Raspberry Pi products
This has turned out to be more reasons why I am glad I don't use C!!!
Tell me about it - 6 pages of crap just to use C.
I like your vids a lot but you talk too fast !!! Why rush ?
Jeeeez... there's nothing new or special about this pi. It's 20 year old tech. Why don't they innovate? Here's an idea... build a 5ghz wifi radio, on an ARM cpu for $2.
BTW Gary, I love your videos. Keep them coming. My rant is targeted at the PI foundation.
@@cronchcrunch the ESP32 is a more powerful CPU that has WiFi 2.4 ghz so it can connect to the internet. Why didn't the PI foundation innovate something like that? These PI arm chips are all hype unfortunately. If you know anything about the ARM ecosystem, you'll agree.
@@cronchcrunch I agree. More powerful, in terms of speed, isn't needed. I suggested that more innovation is needed, not power. Hope that clarifies.
@@cronchcrunch learn to read. OP is 5ghz wifi, not 5ghz ARM cpu.
and which other cpu do have multicore hardware fifo implementation?
Needs to be made simpler - some write a GUI like Code Blocks for the pi