Improve your Arduino programming skills - Using the ATmega328P registers.

Sdílet
Vložit
  • čas přidán 5. 09. 2024
  • Other “Improve your Arduino programming skills” videos:
    • Improve your Arduino p...
    In this video I explain what a register is and how you can use it to further optimize your Arduino code.
    When using Serial.begin() for example the registers are set automatically and there is a lot of code generated to get the serial port to work. A lot of code that you probably don’t need for every project. Watch what happens if you set the registers manually and thereby exclude the unwanted code.
    In a few simple steps a 2632 bytes Arduino example program is reduced in size to 682 bytes. By using Atmel Studio the same functionality can be achieved with only 194 bytes.
    Download the datasheet of the ATmega328P here:
    www.brokking.ne...
    Video about uploading the program via the bootloader:
    • Atmel Studio 7 - Progr...

Komentáře • 174

  • @roidroid
    @roidroid Před 8 lety +77

    Wonderful video. I love how you don't immediately discard the Arduino environment - but instead slowly upgrade it in steps, and no step is itself too far.
    You're doing this series very well.

  • @MrCrystan
    @MrCrystan Před 8 lety +41

    This is the best thing I've seen on the topic. Could never have learned so much in so little time. Kudos!

    • @MrCrystan
      @MrCrystan Před 8 lety +5

      this also helps allot for programming attiny13a of 1k memory and now I can do so much more than just a blink and a sensor.

  • @GGAbi2012
    @GGAbi2012 Před 7 lety +15

    Every crucial point is thoroughly thought out and implemented in this excellent video. In addition to that it's even perfectly explained with the help of an oscilloscope, sequentially added code sections for better understanding of "code-upgrades" and in my case what I appreciate most is the cross reference to the datasheet. Keep up the good work, I enjoy all your videos

  • @georgeorwell7607
    @georgeorwell7607 Před 6 lety +1

    AWESOME! WOW! This is my second tutorial by Joop Brokking and I am blown away by the clarity, the depth, and the detail, indicating someone with not only deep knowledge of the subject, but also the ability to teach convincingly and effortlessly. kudos

  • @dparson
    @dparson Před 8 lety +5

    Totally loved this tutorial, first time I've seen serial data transfers done with the low level UART registers. I would watch one of these for every chapter of the data sheet :) Thanks a ton for making this!

  • @hasithaeranga5589
    @hasithaeranga5589 Před 2 lety

    perfect teaching style from what we know to what we dont know

  • @hrnekbezucha
    @hrnekbezucha Před 7 lety +9

    Sure, optimization. But I had no idea you can make such a significant difference. That's amazing.

    • @TheSehaa
      @TheSehaa Před 7 lety +2

      its the serial.begin and serial.write function. it eats memory

    • @danielday3162
      @danielday3162 Před 7 lety +3

      The code for the Arduino IDE is C++ which is an object oriented language. Using C or even a lower level language like the AVR instruction set can greatly impact the size of your code.

  • @dinkarjain7489
    @dinkarjain7489 Před 3 lety

    The datasheet is the only thing why normal people were reluctant to program controllers, it seems complex and requires a knowledge of what peripherals and registers are. But this video clarified why serious microcontroller projects use the bare coding style and a great programmer would rather dabble in a datasheet than producing a cheap code that will have an "amateur hour" label. This is something that hobbyists should add to their must-watch list to step up their game. Great work pal, keep it up!!

  • @zxlee1
    @zxlee1 Před 7 lety

    Thanks for creating this "improve your Arduino programming skills" series. I like the way you guide viewer step by step to understand all the details that shows the big improvement using Atmel studio.

  • @izzyblackout1090
    @izzyblackout1090 Před 6 lety +1

    This reminds me of my days with Microchip PIC. Every single bit has to be set up manually. Thank for the infos. Great tutorial. Best method to optimize programming memory

  • @PiefacePete46
    @PiefacePete46 Před 8 lety +53

    Your series really is great! You are taking us into the area of 'dark arts' and switching the lights on. :o)

    • @Joop_Brokking
      @Joop_Brokking  Před 8 lety +1

      Thank you for the compliments!

    • @BustersCNCchannel
      @BustersCNCchannel Před 8 lety +1

      Thank you, your videos are excellent. You make it look too easy :)

    • @bmistry5
      @bmistry5 Před 7 lety

      Great video!
      How about other UART functions?
      i.e. How to write String using Registers?How to read a character?How to read String?
      Please make one video...really interesting topic!

  • @TheExplant
    @TheExplant Před 5 lety +1

    Fantastic tutorial, really clear! Using this in my project, it also operates much faster now that I use this method. Before I followed your video, the Arduino couldn't keep up with the clock speed of the device from which I'm taking input, and now I can just about match it. Thanks for sharing your expertise!

  • @DailyWalk365
    @DailyWalk365 Před 5 lety

    Nice to know that the "void setup(void) {}" in the Arduino IDE is actually part of the "int main(void){}" function just before the "while (1) { }" loop. Again I found an answer to a question I had using AtmelStudio7. Thank you.

  • @freeelectron8261
    @freeelectron8261 Před 5 lety

    Real quality here. Joop knows his stuff and explains it really well.

  • @Anaeijon
    @Anaeijon Před 6 lety

    Another benefit of using the registers when working with multiple digital I/O pins, is, that it ensures all bits in the register are read/written at the same time.
    For example if you have many different LEDs connected to the Arduino Mega and switch them on and of rapidly, while relying on the persistence of vision (for example when building a LED Matrix or Cube), you need to handle the on/off switching off all pins extremely fast.
    If you are using digitalWrite for each pin, it will basically change one pin after another.
    This takes a high number of instructions (including counter etc.) for switching 8 I/O pins.
    Using the output registers instead on the other hand just uses some simple logic to precalculate the whole register and set all pins at once, by putting the precalculated uint8_t onto the Register.

  • @Fredovsky
    @Fredovsky Před 7 lety

    Ok, I rarely comment but this is one of the most useful and clear video on code optimization. Thank you for taking the time to make such quality videos !

  • @acertivedude4956
    @acertivedude4956 Před 7 lety

    This video and the O-scope one have opened my eyes as to how advanced it is possible to get with arduino project code. Thank you!

  • @thanasisathanasi4965
    @thanasisathanasi4965 Před 3 lety

    I would also say it is a wonderful video. Smooth transition from the Arduino Environment to the machine language environment of atmel studio.. Wooowww. Masterpiece. I wish I had a friend like you !!!

  • @edexnorth123
    @edexnorth123 Před 6 lety +1

    this tutorial right here is far superior than the lecture I had taken at collage. By the way *"don't go a shitty collage."* go make a nice cup of coffe and surf the internet for threasures like this one.

  • @mirkomueller3412
    @mirkomueller3412 Před 8 lety +15

    I wish there would be a possibility to press a "big thumbs up" Button - i definitely would press it. Thank you so much !!!

  • @leofranssen
    @leofranssen Před 3 lety

    Lekker accentje Joop.
    Dank je wel voor het zo gul delen van je kennis.
    Groet Leo.

  • @kid-vf4lu
    @kid-vf4lu Před 8 lety

    This is the simplest avr uart tutorial I have seen. Thank you!

  • @EEBBSamarJain
    @EEBBSamarJain Před rokem +1

    Hey there, Great explanation on the topic, I just wanted to ask two things,
    1. How and where to print that variable 'inputs', like do we have something like a serial monitor on atmel where we can print the value 'inputs'?
    2. What should we do when we want to send more than 1 byte of data?

  • @jamest.5001
    @jamest.5001 Před 7 lety

    thanks so much for making this video. I am needing to get a arduino to control a DC boost converter . the boost stage for a inverter project for my offgrid home. I don't do computers. I haven't programmed anything since VCRs was common. I have watched many videos. trying to learn how to program arduinos. But your video is the best I have seen so far. it has been a great help. to get my mind wrapped around how this process works. I guess in a week or so if any of your teaching took! when I buy my first arduino. thanks again this video has been a big help.

    • @4.0.4
      @4.0.4 Před 7 lety

      James stranger Just wanted to motivate you by saying Chinese clones are just as good. You need to get a driver in Windows but there's a version that is signed (can be downloaded from Microsoft servers, so probably safe). The driver is because the serial to USB converter is a cheaper knockoff, but the microcontroller itself (including its serial capabilities) is the same as genuine Arduino.
      The point in Chinese clones is they cost $2. Having a full bag of Arduinos is empowering! Have a look at sites like AliExpress, eBay, DealExtreme, BangGood... whichever has the right prices/shipping (I used three of these already). Also get some modules! Super fun stuff.

  • @vijaykumarkanchukommala2183

    Good video for new learners to start their experience with AVR microcontrollers

  • @rootbeard5449
    @rootbeard5449 Před 8 lety +2

    Very informative video! Moving your code to pure C environment frees up so much space!

  • @LearnElectronicsCanada

    Your videos are quite good. It's nice to see someone preaching the transition to Atmel Studio to improve code/size. You really want to mess with everyone's head... show one last transition to ASSEMBLY. I still have nightmares about trying to debug Assembly on a 6809 processor in the 80's. With the tools available now, it's much easier to debug assembly code.

  • @raymunyaka5409
    @raymunyaka5409 Před 4 lety

    awesome tutorial on AVR micro controllers using arduino and atmel studio. Thankyou very much. From Kenya.

  • @JeanDAVID
    @JeanDAVID Před 6 lety

    Amazing optimization of size at low level of programation

  • @zaprodk
    @zaprodk Před 8 lety +2

    Very good explanation. Well done - I'm inspired to go read the datasheet as night time reading now :D

  • @sergiocastellani9823
    @sergiocastellani9823 Před 7 lety

    Speechless. feel guilty that now i got obsessed with registers and things.... Bravo

  • @lostname605
    @lostname605 Před 8 lety +1

    If you want to practice in setting registers, check out the ds3231 real time clocks. they are cheap and have a great datasheet to get started

  • @ChathuraJayasundaraIMD

    thumbs up if I learn something???? this is like the most amount of knowledge I got about Arduino in one video!!!! thank you sir!!

  • @kevinowenburress2435
    @kevinowenburress2435 Před 7 lety

    if you use the right gpio pins you can read them as a register iirc. then you don't have to poll each gpio pin you can just read them all into a register in one clock cycle. I haven't done benchmarks recently but it is significantly faster than polling each bit.

  • @holdengreene9717
    @holdengreene9717 Před 7 lety

    Great vid!. One suggestion, you should increase the font size in the IDE to make it easier to read. Keep up the great work.

  •  Před 8 lety +1

    Your videos are great. But you have a great responsibility now, I'll get addicted...and I'm going to need more and more.

  • @Walkofsoul
    @Walkofsoul Před 8 lety

    Wow, the difference is huge !

  • @adochshanov
    @adochshanov Před 4 lety

    Always a great pleasure to go deeper and expand the limits of Arduino IDE. Being absolutely new to atmelstudio I wonder whether the software is free to use?

  • @photon2724
    @photon2724 Před 6 lety +2

    improving our Arduino programming skills?!?!?!?!! im a first year engineering student, and we are immediately given an assessment that requires Atmel. Mind you, we have never even touched the Arduino software before. We just left high school. WHAT DO THEY EXPECT FROM US!!!

    • @masaratech
      @masaratech Před 5 lety

      to be fucking geniuss ???!!!!
      Fuck school and long live CZcams!

    • @martinmartinmartin2996
      @martinmartinmartin2996 Před 5 lety +1

      Electronics involve many technologies : optics, lenses, fibre optics, nano-tech, ...Engineering a x100 more!
      Plan for the next 10 yrs
      IMPOSSIBLE to become learned in many technologies ... IMPORTANT to accumulate some idea of 4 or 5 unrelated technologies.
      To learn arduino: read and follow simple CZcams videos . Spend 1/2 hour/day on SIMPLE program explanations. Understand the meaning of 3 to 5 different commands every day , but review the previous commands you learned.
      high school is over ...now its time to Work and Learn !

  • @mcorrive12
    @mcorrive12 Před 7 lety

    Fantastic series Joop! Thanks for all your efforts in producing these videos!

  • @HandfulOfTranquility
    @HandfulOfTranquility Před 7 lety

    You are an excellent teacher! I don't understand programming well (I've only piddled around with Arduino a small amount), but you make the concepts easy to understand and apply, more so than other CZcamsrs I've seen.

  • @scottbechtel7915
    @scottbechtel7915 Před 7 lety

    Mind blown! Didn't know you could use assembly in the Arduino Studio.

    • @ratchet1freak
      @ratchet1freak Před 7 lety

      Here's something to really blow you mind. It's not assembly. Instead those are really just volatile globals bound to the registers.

  • @vizmohanan
    @vizmohanan Před 8 lety

    Great tutorial ! You just demystified the datasheet and gave me confidence to make use of it. Thanks. :)

  • @elfkind5590
    @elfkind5590 Před 7 lety

    THANKS! Please keep them coming! This is one of the best learning channels.

  • @akshayjha9605
    @akshayjha9605 Před 8 lety

    Sir can you please make more videos like this or you can make a complete tutorial series of such programming tutorials because first time fortunately I found this kind of video first time I really came to know where to learn arduino programming and
    improve it more can you please make more videos from programming basics
    Thanks alot :-)

  • @FranzStrasse
    @FranzStrasse Před 8 lety

    Absolutely wonderful. I really did learn something and am inspired to use some of your techniques.

  • @chickenbonelives
    @chickenbonelives Před 6 lety

    This is so new to me it's really rather intense. +1 internets

  • @freddiesnijman
    @freddiesnijman Před 8 lety

    Thanks Joop, excellent. I also have to go and figure it out,but looking forward to go and study your info.

  • @vipinkarhana4030
    @vipinkarhana4030 Před 6 lety

    your video is very helpful and well explained. It shows your deeper understanding. (rarely seen such liked ratio i.e 98%)

  • @faisalal-jariry5665
    @faisalal-jariry5665 Před 8 lety

    An excellent tutorial , would you please zoom in the IDE and text. It is very small to see. Thanks

  • @3dw3dw
    @3dw3dw Před 7 lety

    Always learning so much great material from you.
    Thank you so much Joop!!!

  • @photonthief
    @photonthief Před 8 lety +1

    This is a fantastic tutorial Joop! Thank you so much!

  • @massimogiardina9138
    @massimogiardina9138 Před 6 lety +1

    Thank you soooooo much. I neve4 understood how those registers worked

  • @VentoRacing1
    @VentoRacing1 Před 7 lety

    Great stuff! You have inspired me to work on my arduino coding.

  • @mandelbro777
    @mandelbro777 Před 4 lety

    awesome stuff dude. Thank you so much for the time you've invested sharing this knowledge. It is most appreciated.

  • @danielbycinskij3685
    @danielbycinskij3685 Před 3 lety

    Great video!!! What program do you use to read the datasheet?

  • @Stanh11
    @Stanh11 Před 7 lety

    More tutorials like this please !

  • @EMandMORE
    @EMandMORE Před 7 lety

    Thank you for the excellent video, I'm really impressed. Just a little question: considering Arduino IDE lets you program at "low level" as you show in this video, is it really necessary to move to Atmel IDE? Is maybe because Arduino IDE has other problems? (except the setup and loop functions which take some memory)

    • @Joop_Brokking
      @Joop_Brokking  Před 7 lety

      No, you don't have to move to Atmel. You should use whatever suits your needs.

  • @gideonjonkers2683
    @gideonjonkers2683 Před 3 lety

    Did you know you dont have to use setup and loop in the arduino ide you can directly code int main with a while loop and it will work and atmels version of delay works in arduino ide aswell.

  • @bdureau1
    @bdureau1 Před 6 lety

    very interesting video, can be usefull if your are short of memory. However not really good if you want your code to be portable

  • @niyo7803
    @niyo7803 Před 7 lety

    Sir your video are best, I understand use of register .

  • @jstro-hobbytech
    @jstro-hobbytech Před 3 lety

    I understand what you're saying but how do we put this in practice if we (for simplicity sake) say had a 1602 i2c display showing temp and humidity using a dh11.

  • @abdoo_almyhob184
    @abdoo_almyhob184 Před 5 lety

    just use "char x " instead if "byte x " in variable declaration, both are 8 bits size and works exactly the same.

  • @zyxwvutsrqponmlkh
    @zyxwvutsrqponmlkh Před 7 lety

    I have to wonder why the arduino ide and compiler would not compile to the same code as your optimized code.

  • @glidermike1
    @glidermike1 Před 6 lety

    Joop, Thank you for this video that explained a great deal to me. However, I am using the ATmega 2560 processor which has multiple USARTs and I am finding it difficult to apply the same register manipulations described in your video. I know you have moved on to more exciting things, but is there any chance for a video on this processor, or at least some guidance.

  • @jeanpierredaviau7478
    @jeanpierredaviau7478 Před 4 lety

    I wonder if there is a book on that for the esp32?

  • @zulfqarali8603
    @zulfqarali8603 Před 6 lety

    Hi Joop, could you please share an SPI optimize program example?
    BTW: Greate way to teach.

  • @BernhardHofmann
    @BernhardHofmann Před 7 lety

    Ninja level unlocked.

  • @laureven
    @laureven Před 3 lety

    Great video. Thank You but :) If You had smaller font YOu could fit more text on the screen. :) Regards

  • @yaserbatal6474
    @yaserbatal6474 Před 8 lety

    very informative series of videos. Keep the good job

  • @incxxxx
    @incxxxx Před 4 lety

    I do not have in Tools of Atmel Studio any Arduino Bootloader. How you got it?

  • @BubbaCZekLP
    @BubbaCZekLP Před 8 lety

    Great video Joop! Could you do one on faster reading of ADC?

    • @AndersJackson
      @AndersJackson Před 8 lety

      The speed you can read are mostly decide by the ADC you use, not by the programs.
      That said, the program code will be less without the Arduino IDE.

  • @BuildItnow
    @BuildItnow Před 8 lety

    very informative, thank you!

  • @thorbennielsen3845
    @thorbennielsen3845 Před 6 lety

    Very good. Can we have more?

  • @tonyhoff86
    @tonyhoff86 Před 3 lety

    I am a noooob. So... is the idea here that I would build a program in the IDE and then streamline it later, or should the work really be done at the lower level from the beginning?

  • @meme-hj5rs
    @meme-hj5rs Před 7 lety

    Great explanation
    Keep up the good tutorials

  • @wafikiri_
    @wafikiri_ Před rokem

    Not so intimidating a manual as one I had to use once to modify a mainframe for its remote shutdown. I found the desired schematics portion in Volume 76 of 130.

  • @makesolareasy
    @makesolareasy Před 7 lety

    Hi Joop Brokking. This is completely off your topic on the video. I have code on different steps controlling 3 relays, that must be controlled for different periods of time. What code do I use to to select certain section of my code, if an input is triggered?

  • @erygion
    @erygion Před 5 lety

    New sub here :) great channel, I'll be using many videos for studying.

  • @o_-_o
    @o_-_o Před 5 lety

    How Atmel Studio
    achieves smaller binary?

  • @sonnguyenxuan685
    @sonnguyenxuan685 Před 6 lety

    i'm working on atmega328p project. i use fast pwm at the 16 bit timer. so i want to output 2 pwm at OCnA and OCnB. both of them have a same top value and same OCRnA and OCRnB. does anyone how i can toggle OCnA and then OCnB repeatedly

  • @randysonnicksen9475
    @randysonnicksen9475 Před 6 lety

    Joop, I am wanting to learn how to use a programmer with the arduino uno so that I can debug (monitor variables) without inserting extra print commands which affect the speed of my program. Do you have any experience with this, and how to get started. I can't seem to find an information source that walks through all the steps with good explanation.

    • @Joop_Brokking
      @Joop_Brokking  Před 6 lety

      I used the Atmel Ice for one of my videos: czcams.com/video/o3dcmo-hbQw/video.html
      Works very intuitive and there are useful videos available for the ICE.

  • @briankoton845
    @briankoton845 Před 2 lety

    the pdf link for downloading the file isn't working

  • @Artezko1
    @Artezko1 Před 7 lety

    Does this make any significant impact on the power consumption or just increasing the available memory?

    • @jmullentech
      @jmullentech Před 7 lety

      Atmel Studio has a profiler built in that can check power consumption but I've never played with it. I'd imagine you'd see a difference but I can't imagine it being anything substantial.

  • @rutherford16
    @rutherford16 Před 5 lety

    The link for datasheet is broken, can you fix it??

  • @youreale
    @youreale Před 7 lety

    Amazing content bro! subscribed.

  • @__cm__
    @__cm__ Před 7 lety

    wow!! beautifully explained!

  • @lw8661
    @lw8661 Před 6 lety

    Awesome. THANK YOU!

  • @Wildcats1266
    @Wildcats1266 Před 8 lety +1

    Arduino based quadcopter using Atmel studio feasible? significant gains in stability and response ?

    • @Joop_Brokking
      @Joop_Brokking  Před 8 lety +2

      It's feasible. The difference in stability is mainly gyro / accelerometer depending.

    • @AndersJackson
      @AndersJackson Před 8 lety

      It will allow you to write more C-code before the program memory runs out of Arduino. And you probably need to write the code for the libraries that Arduino IDE has for you.
      You gain some and loose some.

  • @AxelWerner
    @AxelWerner Před 7 lety

    Excelent Topic! Excelent Video!!

  • @daskasspatzle2396
    @daskasspatzle2396 Před 8 lety

    Super explanation, thanks ;-)

  • @teiko142
    @teiko142 Před 6 lety +1

    Instant like + sub, great stuff!!

  • @bastian9945
    @bastian9945 Před 8 lety +1

    one thing bothers me really hard did he really printed the whole datasheet just to show it in the video?

  • @Patillac123
    @Patillac123 Před 8 lety

    Awesome video. Awesome name.

  • @AllanKobelansky
    @AllanKobelansky Před 7 lety

    Well done. Thank you.

  • @imranaalam
    @imranaalam Před 4 lety

    Excellent saying...
    If you really like to make a donation, remember the amount that you want to donate and give it to somebody who needs it a lot more than I do.
    Matthew 25:40

  • @douglasthomson2986
    @douglasthomson2986 Před 6 lety

    Very good. Thanks Joop

  • @ddxxbb1
    @ddxxbb1 Před 7 lety

    Amazing video !

  • @micaiaskauss
    @micaiaskauss Před 3 lety

    Great vid again

  • @coolwinder
    @coolwinder Před 7 lety

    Very very nice!