Learn C Programming on a Raspberry Pi Your first C program
HTML-код
- Опубликовано: 7 фев 2025
- Today we start a little journey into the world on C programming and how you can learn on the Raspberry Pi, You will see how easy it is. Just be careful and accurate with your typing. You will want to know, why C. Well I will show that compiled code is more efficient than scripts. You can script as well I have no problem with scripts but you should be able to code a little too.
That was a great tutorial. I also learnt a lot of Linux command line tricks that I had no idea existed. Thank you so much.
No matter what others say I really enjoyed this and found useful as a beginner. Thanks.
Very nice, very nice.
Good sir thank you for the easy to follow tutorial. I know nothing about programming but after your video I feel like you've opened a few doors for me to understand it more. Thank you!
Hi Andrew, I know you must have hundreds of "Thank you"s for your kind and well constructed and well pronounced videos but I must say... Here is another one. As a teacher myself these are hard to find, usually smothered with "Err"s and "Uhm"s and no concentrated focus but yours are really great. Thanx Buddy. :¬)
Thank you, you really do honour me and I appreciate your thanks
This video was very good, not only was it good as a start in programming C but for some good tips in daily life at the command prompt. Would love to see more :-)
Excellent tutorial.
Simple steps.
Simple instructions.
A great tutorial! Thank you very much!!!
Are you using 2 bit audio recording equipment?
You are brilliant, you should keep making videos for all things linux, C and JS please!!!!!! :D
This was perfect for me at where I am right now but this would be hard and weird as a beginner I think
So well done - thanks.
Excellent, I am so glad you enjoyed the video, thanks for the comment
3 things I am concerned about (1) File I/O (2) TCP Client and Server creation and I/O (3) Threads
Helped me a lot for scool
Great Presentation #UrbanPenguin please post more videos and I am eager to know have you posted it's continuation part already if yes can you please put the links here.. Thanks in advance
This is a great tutorial! I agree @Peter Wobacz.
Thank you so much
good tutorial and usefully for any embedded system ;)
You Can use Editor for writing the C code and execute it very esay!!!!
pwd >>>> Current Dir
mkdir -p src/c >>> make dir
cd!$ >> goto that dir
goto editor and press CNTR+X ->> Y
and save it with extention *.c
and then write command for executing
gcc -o hell hell.c
Execute:
./hell
Thank you Andrew. I wonder if you can help on C based bluetooth programming?
Once I do hello.c and go into the text file ... and try and do multi comment it gives me e468: pattern not found
I am a 76 year old man who is Not up to date any more. But my grandchildren gave me his pi and I tried to Programm it.
Good luck and enjoy
The Urban Ecolife I've tested Bash benchmarking on my Mac the timing was pretty much like C timing. I guess it is not the case on Raspberry?
Sorry for the noob question, but what "program" does one code in? do you have to download a coding program from the internet for windows 10 or is there a program within windows in which you can write and execute code?
vi and nano are inbuilt text editors or IDE's (Integrated development environment) you write the code using one of them. On Windows you would use something like Visual Studio Community Edition (free version).
How do you get to the command interface? I'm very new to programming so it might be a dumb question.
Great video, but can u make on on how to MAKE a raspberry pi OS? I personally would love that because I don't really like any of them.
another well done video. Thanks for sharing. 73, N0AGI
Can I programmed Keil and mplab by using raspberry?
at the end when I pressed escape it didn't do anything
Thanks you
bro that c script fucked up before i typed anything started getting errors andi pressed enter and then i got stuck were it would only let me type at the bottom then i started pressing exit and other keys now i can write on one line press enter jump to the next but i can never change stuff on the line im on until i press enter
and i cant exit
Thank you but when I did your example it said it needed "int" before main.
It should but doesn't need it:
int main () {
}
IS more correct but defines an output parameter that we don't use.
int main () {
...
return 0;
}
@@theurbanpenguin I got the same warning, and thought first I had made some mistake in the code, but then found the solution here: adding "int" got rid of the warning. Maybe it's because of some change in later versions of gcc?
(I have used gcc and nano before for some simple programs, but it's years from the last time, and I thought it would be time to refresh memories on how exactly to do it. Though this time I used graphical text editor, which I also thought to be culprit for the warning, or more specifically its default encoding or line change settings, but it turned out to be the "int" thing.)
What about other languages, like Ada, C++? It would be cool to have Qt on this device as well.
I think you can do C++ programming; you have to install the compiles possibly. There is Mathematica as well!
Just following this as I have both an early raspberry B and a later raspberry2. My times for the script 7 compiled C are different. In order script followed by compiled C,
Raspberry pi B 2011: script: real 30ms. Compiled C: 14ms.
Raspberry pi 2 2014: script: real 16 ms. Compiled C: 7ms.
how come these are different from your figures? My guess is that the processing time is definitely different between the generation of boards and the clocking speed.
Is there a profiling tool that can test the efficiency of the compile code for c and the script code for the shell scripts?
Robert Mackintosh A faster processor will give you a faster time. The Pi 2 has a quad core and 900 mHx the B just thenone core and 700 Mhz.
***** Depending upon his CPU governor setting though, his RPi2 might only have been running at 600MHz. I think you'd have to run a (more rigorous) benchmark in order to really make a fair comparison.
Also, if you create a little Makefile, you can turn on multiple core compilation with the -j flag.
Tom B Forgot to mention, you can install the package cpufrequtils to get access to the tools to see which governor setting is in use. I think raspi-config will tell you as well, but program cpufreq-info (in cpufrequtils package) gives you a lot of interesting information on your processor.
When I go to enter in a command it says “E348: no string under cursor” plz help
same thing here I can not do anything without getting that error. This is frustrating because everything I try to learn concerning programming is different than it is in the video. Things would be the same until a certain point and I come across and error that I can not figure out.
@@diondiamonds hes tels u what to do just listen
@@lukaspfitscher8737 i did but i got an error. Things were different i watched this video like 5 times.
Is argc optional?
Whenever I try to start writing with /* it starts at the bottom of my screen why is that?
Maybe go into insert first. In vin i is for insert. If you use / it is a search and shows at the bottom of the page. Or use nano as an easier editor if you are not used to vi.
so after you have finished the program how do you save and exit because I pressed esc, colon, x and it didn't work
@@MrTruBeatz-TheGifted Esc then :wq should do it
so C is compatible with raspberry pi right?
C can be used on every CPU in common use. ;)
can you write in c++?
Yes.
How did that help me with a raspberry pi?
If you can write C or C++ it just helped you a lot.
How can you call main() a method?....Theres no such thing in C - its a function. Methods only exist on OO programming.
The way you explained the whole C program concept in the video does not meet the programming standard and the GNU standard.
1/ Create a dir for the project in your $HOME dir as follow:
myProjectName/src
2/ Create your C source program files in src dir
3/ Using c/C dir name does NOT allow by UNIX/Linux OS standard as single letter name only for clarity and OS convention
4/ Under C source coding proc "extern statement" get confused if related source laying somewhere else or other dirs
I built my first program ''LED Blink'', but I don't know how run it automatically and forever...
try a while loop
Thanks, I found a solution here:
www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs
Abderrahim Kezzi can u plz guide me how can i make LED BLINK program in C on RaspberryPi
Fahad Uddin
#include
#include
main () {
wiringPiSetup();
pinMode(0,OUTPUT);
for (;;) {
digitalWrite(0,HIGH) ; usleep(500000);
digitalWrite(0,LOW) ; usleep(2000000);
}
}
constant power and an inline resistor.
Mallet or Mallett
Some people don't have the correct aptitude to teach, as seen here. To many "unexplained" details for a first time Linux student. Every thing you type in your command line needs to be explained; for ex: his first step involves creating a directory and he writes "mkdir" and then writes "-P" never explaining what "-P" is or why it needs to be there. He references "arguments" -- what is an "argument?" -- what does it do? Then we Change directories with "cd !$". I get cd but what is the "!$" ? No explanation. When explaining basic stuff you've got to teach the basics then we can quickly follow and learn. I write this comment in hopes that "teachers" will slow down and listen to themselves when they teach . Once you create confusion by omitting details you begin to unravel understanding and effective teaching.
He is here to guide you, not carry you. You need to do your own research on things you are struggling with and use his teaching as a reference.
he completely explains what the p argument is 'create path'. some people do not have the aptitude to listen.
But what is an "argument"? what does it do? what does it mean? all he says is it "tells the program what to work upon". that is meaningless.
@@michaelfitton4645 All good questions. Try cracking a book!
Hey penguin, i got to gcc -o hello hello.c , pressed enter and got this message.. Hello.c:6:2 error: invalid preprocessing directive #Include helo.c: in function 'main'
hello.c:9:9: warning: incompatible implicit declaration of built in function @printf@[Enabled by default] Any response would be much appreciated, (im a noob)
You may prefer to use the nano text editor if you are new to Vi but I would persevere with Vi. The link here takes you to the written version of the course where you can copy the code from. It is all just practice. theurbanpenguin.com/wp/?p=2463
Thanks man :D
Can i do 'c' programing with opencv library in Raspberry Pi..??
Greetings. I would like to write an USB webcam program for the Raspberry Pi to detect and measure the edges of a square object. Which program language should I use? Thanks.
if you did not give up on this... I would start by looking at the source code of cheese a webcam app. wiki.gnome.org/Apps/Cheese
I mean school
Thank you
coding
misleading when using the program as a function
Hey, any leads to where i could find tutorials on how to write functions into the terminal?
What this has to do with Raspberry Pi? It's just C programming in Linux and has nothing to do with Raspberry Pi... Lame!
By the same logic, all C tutorials have nothing to do with Linux because Linux is a Unix flavor, so they're only about C programming in Unix. The Pi was designed for young people in mind and the RPi foundation favours scripting language (python, etc) over compiled languages. It makes perfect sense to introduce compiled languages to students with the tools they have at the moment.
marcthenarc I agree!
raspbian or noobs ?
Noobs is a simple installer that allows you to choose your OS, default Raspbian. This provides the easiest way of setting up the Pi but will likely install Raspbian
I'm not able to setup my pi on my laptop. Can someone help please?
This had absolutely nothing to do with Raspberry Pi.
Thereisnobegining this is the code you put in a raspberry time. Next time *_please_* try to be nicer
Not only will this code run on the Raspberry Pi. The entire lesson could have been done on the Raspberry Pi. May I suggest that you know what you're talking about - before you comment.