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.

Комментарии • 93

  • @Mr-tl4sg
    @Mr-tl4sg 6 лет назад +3

    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.

  • @piotrlobacz
    @piotrlobacz 11 лет назад +28

    No matter what others say I really enjoyed this and found useful as a beginner. Thanks.

  • @innovationsurvival
    @innovationsurvival 5 лет назад +1

    Very nice, very nice.

  • @BobbyStout
    @BobbyStout 8 лет назад +1

    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!

  • @JoeEvansSound
    @JoeEvansSound 10 лет назад +3

    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. :¬)

    • @theurbanpenguin
      @theurbanpenguin  10 лет назад +1

      Thank you, you really do honour me and I appreciate your thanks

  •  4 года назад

    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 :-)

  • @RightToSelfDefense
    @RightToSelfDefense 6 лет назад

    Excellent tutorial.
    Simple steps.
    Simple instructions.

  • @dexter2935
    @dexter2935 4 года назад

    A great tutorial! Thank you very much!!!

  • @thoughtyness
    @thoughtyness 9 лет назад +11

    Are you using 2 bit audio recording equipment?

  • @aidanmillar-powell3187
    @aidanmillar-powell3187 10 лет назад +2

    You are brilliant, you should keep making videos for all things linux, C and JS please!!!!!! :D

  • @tristunalekzander5608
    @tristunalekzander5608 4 года назад

    This was perfect for me at where I am right now but this would be hard and weird as a beginner I think

  • @ilearn4970
    @ilearn4970 5 лет назад

    So well done - thanks.

    • @theurbanpenguin
      @theurbanpenguin  5 лет назад

      Excellent, I am so glad you enjoyed the video, thanks for the comment

  • @colinmaharaj
    @colinmaharaj 8 лет назад +2

    3 things I am concerned about (1) File I/O (2) TCP Client and Server creation and I/O (3) Threads

  • @melissakolbow7858
    @melissakolbow7858 7 лет назад

    Helped me a lot for scool

  • @sumana6120
    @sumana6120 7 лет назад +1

    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

  • @TheLeopulido
    @TheLeopulido 6 лет назад

    This is a great tutorial! I agree @Peter Wobacz.

  • @walterp7125
    @walterp7125 9 лет назад

    good tutorial and usefully for any embedded system ;)

  • @rbhavsar
    @rbhavsar 10 лет назад +2

    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

  • @commanderbensisko
    @commanderbensisko 10 лет назад

    Thank you Andrew. I wonder if you can help on C based bluetooth programming?

  • @JusticeOnce
    @JusticeOnce 9 лет назад +1

    Once I do hello.c and go into the text file ... and try and do multi comment it gives me e468: pattern not found

  • @ottohorst9127
    @ottohorst9127 6 лет назад

    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.

  • @Fadin19
    @Fadin19 11 лет назад

    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?

  • @joshuabrose
    @joshuabrose 7 лет назад +1

    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?

    • @DodgyBrothersEngineering
      @DodgyBrothersEngineering 6 лет назад +1

      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).

  • @jaysonmckeownsr9913
    @jaysonmckeownsr9913 7 лет назад

    How do you get to the command interface? I'm very new to programming so it might be a dumb question.

  • @BenNottelling
    @BenNottelling 9 лет назад

    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.

  • @N0AGI
    @N0AGI 9 лет назад

    another well done video. Thanks for sharing. 73, N0AGI

  • @Electroniceducaton
    @Electroniceducaton 6 лет назад

    Can I programmed Keil and mplab by using raspberry?

  • @jamieplayz771
    @jamieplayz771 8 лет назад +2

    at the end when I pressed escape it didn't do anything

  • @AbouchYassine
    @AbouchYassine 10 лет назад +2

    Thanks you

  • @Indi_DevJames
    @Indi_DevJames 6 лет назад

    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

  • @lovermonkey
    @lovermonkey 6 лет назад

    Thank you but when I did your example it said it needed "int" before main.

    • @theurbanpenguin
      @theurbanpenguin  6 лет назад

      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;
      }

    • @enginerd80
      @enginerd80 6 лет назад

      @@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.)

  • @mradaChris
    @mradaChris 11 лет назад

    What about other languages, like Ada, C++? It would be cool to have Qt on this device as well.

    • @Fadin19
      @Fadin19 11 лет назад

      I think you can do C++ programming; you have to install the compiles possibly. There is Mathematica as well!

  • @RobertMackintosh
    @RobertMackintosh 9 лет назад

    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?

    • @theurbanpenguin
      @theurbanpenguin  9 лет назад

      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.

    • @bluehornet6752
      @bluehornet6752 9 лет назад

      ***** 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.

    • @bluehornet6752
      @bluehornet6752 9 лет назад

      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.

  • @TheCanadianYeti.
    @TheCanadianYeti. 5 лет назад +1

    When I go to enter in a command it says “E348: no string under cursor” plz help

    • @diondiamonds
      @diondiamonds 5 лет назад

      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.

    • @lukaspfitscher8737
      @lukaspfitscher8737 4 года назад

      @@diondiamonds hes tels u what to do just listen

    • @diondiamonds
      @diondiamonds 4 года назад +1

      @@lukaspfitscher8737 i did but i got an error. Things were different i watched this video like 5 times.

  • @spencertron88
    @spencertron88 10 лет назад

    Is argc optional?

  • @itreallydoblikethatsometim7136
    @itreallydoblikethatsometim7136 7 лет назад +1

    Whenever I try to start writing with /* it starts at the bottom of my screen why is that?

    • @theurbanpenguin
      @theurbanpenguin  7 лет назад +1

      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.

    • @MrTruBeatz-TheGifted
      @MrTruBeatz-TheGifted 7 лет назад +1

      so after you have finished the program how do you save and exit because I pressed esc, colon, x and it didn't work

    • @pokibali
      @pokibali 3 года назад

      @@MrTruBeatz-TheGifted Esc then :wq should do it

  • @the4ghzpc
    @the4ghzpc 9 лет назад

    so C is compatible with raspberry pi right?

    • @dangputerz
      @dangputerz 7 лет назад

      C can be used on every CPU in common use. ;)

  • @marquiziosaldana9201
    @marquiziosaldana9201 8 лет назад

    can you write in c++?

  • @jaysonmckeownsr9913
    @jaysonmckeownsr9913 7 лет назад

    How did that help me with a raspberry pi?

  • @Bengismo
    @Bengismo 7 лет назад

    How can you call main() a method?....Theres no such thing in C - its a function. Methods only exist on OO programming.

  • @imrank340
    @imrank340 4 года назад

    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

  • @abderrahimkezzi
    @abderrahimkezzi 11 лет назад

    I built my first program ''LED Blink'', but I don't know how run it automatically and forever...

    • @theurbanpenguin
      @theurbanpenguin  11 лет назад

      try a while loop

    • @abderrahimkezzi
      @abderrahimkezzi 11 лет назад

      Thanks, I found a solution here:
      www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs

    • @FahadUddin1
      @FahadUddin1 10 лет назад +1

      Abderrahim Kezzi can u plz guide me how can i make LED BLINK program in C on RaspberryPi

    • @theurbanpenguin
      @theurbanpenguin  10 лет назад +1

      Fahad Uddin
      #include
      #include
      main () {
      wiringPiSetup();
      pinMode(0,OUTPUT);
      for (;;) {
      digitalWrite(0,HIGH) ; usleep(500000);
      digitalWrite(0,LOW) ; usleep(2000000);
      }
      }

    • @TheLeopulido
      @TheLeopulido 6 лет назад +1

      constant power and an inline resistor.

  • @peterm6482
    @peterm6482 7 лет назад

    Mallet or Mallett

  • @robyounce4636
    @robyounce4636 9 лет назад +2

    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.

    • @h3sh926
      @h3sh926 8 лет назад +3

      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.

    • @dangputerz
      @dangputerz 7 лет назад +1

      he completely explains what the p argument is 'create path'. some people do not have the aptitude to listen.

    • @michaelfitton4645
      @michaelfitton4645 6 лет назад

      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.

    • @phillB
      @phillB 6 лет назад +1

      @@michaelfitton4645 All good questions. Try cracking a book!

  • @AnotherNinja1
    @AnotherNinja1 10 лет назад

    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)

    • @theurbanpenguin
      @theurbanpenguin  10 лет назад

      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

    • @AnotherNinja1
      @AnotherNinja1 10 лет назад

      Thanks man :D

  • @satishvekariya9172
    @satishvekariya9172 10 лет назад

    Can i do 'c' programing with opencv library in Raspberry Pi..??

  • @qzorn4440
    @qzorn4440 10 лет назад

    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.

    • @dangputerz
      @dangputerz 7 лет назад

      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

  • @melissakolbow7858
    @melissakolbow7858 7 лет назад

    I mean school

  • @canthold._ar5732
    @canthold._ar5732 5 лет назад

    coding

  • @ascii1107
    @ascii1107 8 лет назад

    misleading when using the program as a function

    • @nishanth_n
      @nishanth_n 7 лет назад +1

      Hey, any leads to where i could find tutorials on how to write functions into the terminal?

  • @PopescuMarian
    @PopescuMarian 11 лет назад +2

    What this has to do with Raspberry Pi? It's just C programming in Linux and has nothing to do with Raspberry Pi... Lame!

    • @marcthenarc
      @marcthenarc 11 лет назад +5

      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.

    • @Fadin19
      @Fadin19 11 лет назад

      marcthenarc I agree!

  • @jasminrecupero8533
    @jasminrecupero8533 8 лет назад

    raspbian or noobs ?

    • @theurbanpenguin
      @theurbanpenguin  8 лет назад +2

      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

    • @ratulmohindra
      @ratulmohindra 8 лет назад

      I'm not able to setup my pi on my laptop. Can someone help please?

  • @Thereisnobegining
    @Thereisnobegining 7 лет назад +1

    This had absolutely nothing to do with Raspberry Pi.

    • @csicee
      @csicee 6 лет назад +1

      Thereisnobegining this is the code you put in a raspberry time. Next time *_please_* try to be nicer

    • @phillB
      @phillB 6 лет назад +2

      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.