Using Serial.read() with Arduino | Part 2

Поділитися
Вставка
  • Опубліковано 20 жов 2024

КОМЕНТАРІ • 89

  • @esmirhodzic981
    @esmirhodzic981 3 роки тому +29

    one of the best tutorials ive ever seen...The format, content, even the voice is cool ...Thank you

  • @davesee
    @davesee Рік тому +4

    Thank you so much for these videos! I struggled so much trying to send serial data via hc-05 bluetooth module connection and this helped me immensely. I tried quite a few other tutorials but none of them broke down serial communication the way yours did. Very well done and very much appreciated!

    • @programmingelectronics
      @programmingelectronics  Рік тому

      Awesome to hear Dave! This stuff can be confusing sometimes, so seeing a couple walk throughs never hurts. Best of luck on your project!

  • @TinyMaths
    @TinyMaths 2 місяці тому +1

    Parts 1 & 2 have cleared up hours of head scratching after trying to read tutorials on sending data via serial in Stackoverflow and Arduino forums. I come from a JavaScript background, but the devil is in some of the minor details which go unexplained in a lot of forums out there (probably because prior knowledge of arduino programming and concepts is assumed).
    Those minor details given here made it much easier to understand code elsewhere that had me flummoxed. Thank you; you've earned my sub.

  • @jezzeryuen
    @jezzeryuen 3 роки тому +5

    The best tutorial ever. I have watched a bunch of other videos, they all just throw codes at me without really get to understand the fundamentals. This video explained every bit of the code "bit by bit". Definately filled all the questions marks I had previously!

  • @blackartista
    @blackartista 3 роки тому +3

    It's impossible not to subscribe after this smooth tutorial

  • @ericspooner
    @ericspooner 2 роки тому +1

    Very good tutorial, and helped me get started on Serial for sure. I did find one thing that might need to be tweaked. Every loop if you exceed the MAX_MESSAGE_SIZE you will lose 1 char out of the buffer. This is because we call Serial.read() before checking the max length of the array. There are many ways to solve this, I ended up doing the check for the max message size before a serial read to prevent losing one position out of the buffer. Using the identical else to clean up anre print the buffer, so I didn't read an extra byte from the buffer. Thanks again for the great content!

  • @noellorenzopagatpat780
    @noellorenzopagatpat780 2 роки тому +1

    I'm having trouble understanding Serial Communication. This is a life saver! Thankyou!

  • @robertcameronjones
    @robertcameronjones 2 роки тому +4

    Dude, you are a wicked good teacher. One of the best I've seen in 30 years in the electronics game.

  • @MathiasBacher
    @MathiasBacher 2 роки тому +2

    The quality of your tutorials is incredible. Thank you!

  • @fnkho5609
    @fnkho5609 Рік тому +1

    Hi, it is the best teaching I ever watch. One question, why did you add '\0' at the end of the message?

  • @jonvannatto
    @jonvannatto 3 роки тому +6

    Thank you for the simple to understand and detailed explanation of this. It's super helpful.

  • @TheInfinitymijinion
    @TheInfinitymijinion 3 роки тому +4

    Thank you so much!
    with this I can control a servo wirelessly using node-red serial out
    you just saved my thesis dear sir!

  • @goku445
    @goku445 Рік тому +1

    Great teacher sir.

  • @ED99LAM
    @ED99LAM Рік тому +1

    very informative to understand Serial. thanks

  • @hughaskew6550
    @hughaskew6550 3 роки тому +6

    Why are you declaring your variables inside of the loop? It looks like message[] and message_pos will be created anew with every incoming byte.

    • @programmingelectronics
      @programmingelectronics  3 роки тому +7

      Great question Hugh! Those are static variables, so they will only be declared and initialized the first time through the loop.

    • @hughaskew6550
      @hughaskew6550 3 роки тому +1

      @@programmingelectronics Thanks. I'm more familiar with database programming and didn't understand the "static" declaration.

  • @tavoroyale8333
    @tavoroyale8333 2 роки тому +1

    Very useful, subscribed!

  • @robertrobert5583
    @robertrobert5583 2 роки тому +1

    Thanks for another great tutorial, Michael. I was following closely but expected line 26 to have an OR || rather than an AND &&:
    26 If (inByte != ‘
    ’ && (message_pos < MAX_MESSAGE_LENGTH - 1))
    I thought would be,
    26 If (inByte != ‘
    ’ || (message_pos < MAX_MESSAGE_LENGTH - 1))
    If I have spotted an error, then it is all thanks to having completed your course. But if I have misunderstood I wonder if you could set me right? Many thanks.

  • @Thomas-bs2em
    @Thomas-bs2em 2 роки тому +1

    Super Great Video! but I dont see anything in your code to indicate which pin incoming data would coming in?
    (also i'm kind of a noob)

    • @programmingelectronics
      @programmingelectronics  2 роки тому

      Great question!! The serial Input here is coming in via USB which is connected to pins 0 and 1 on the Arduino. Hope that helps some!

  • @suheylk6514
    @suheylk6514 2 роки тому +1

    It was a great explanation. Thank you so much.

  • @themecue9732
    @themecue9732 2 місяці тому

    Great. now how do I compare the “message” to a constant in an if statement to actually use it?

  • @reynaldowify
    @reynaldowify 3 роки тому +3

    Hi, thanks
    However, my doubts are not yet satisfied
    I still wonder if arduino mega has different buffers for the different serial ports
    Also, there are plenty of tutorials how to send ASCII characters with serial communication, and my goal, is really understand if i can take the incoming bytes as such, instead to deal with ASCII; most of all, thinking in communication between arduinos instead a PC. For example, an arduino controlling a maschine, with instructions that another one can get from internet via wifi , or any sensor arrangement, or a arduino that controlls others that operate maschines, etc.
    Arduino is a excellent device to control real world equipment, that allows us to not have to depend on specific control devices already made, that mostly are not the exactly what we need, or are too expensive, or does not fit our needs in implementation
    Sadly, seems that arduino is used almost as a toy, instead of the real capabilities it offers Just a thought
    Again , thanks

  • @periklisdrakousis6537
    @periklisdrakousis6537 Рік тому +2

    I have a q. Are you sure we have to put the char message and message_pos inside the while loop?

    • @scientificnotatione10
      @scientificnotatione10 Рік тому +1

      Good q.

    • @programmingelectronics
      @programmingelectronics  Рік тому +1

      Great question. You could set those up as global variables if you wanted.

    • @periklisdrakousis6537
      @periklisdrakousis6537 Рік тому

      @programmingelectronics I suppose they should go just outside the while loop and inside the void loop. That way you can reset them to default in each loop. Leaving them inside the while loop the pos is always 0 and the message always changes. I can't understand if it works properly.

    • @programmingelectronics
      @programmingelectronics  Рік тому +1

      @@periklisdrakousis6537 The variable is set as static, and so it is only initialized once (then that initialization is skipped over after that), which is why it works like it does.

    • @periklisdrakousis6537
      @periklisdrakousis6537 Рік тому

      @@programmingelectronics ok thk u.

  • @tranminhhien9150
    @tranminhhien9150 Рік тому +1

    i'm sorry but, i'm confused.
    static char message[12] consists of 11 characters and a NULL character
    when you typed "sub sandwich" = 12 characters, where is the NULL character?

  • @rickybrenay6249
    @rickybrenay6249 Рік тому

    Get it “cereal bowl”…. Lolo😂😂

  • @arifmartoyo
    @arifmartoyo 8 місяців тому

    Thank you very much....

  • @s10jam
    @s10jam 2 роки тому +3

    And today I feel even more cheated by my college tuition when I see your extremely clear and understandable videos right on the internet.

  • @behzadabf
    @behzadabf 2 роки тому +1

    how perfectly described... wow..

  • @jroot1279
    @jroot1279 3 роки тому +1

    Excellent tutorial. However, I was expecting some sort of example towards the end to show how this program works.

  • @quynhphamduong1098
    @quynhphamduong1098 10 місяців тому

    Can ESP32 code by Ardunio IDE use this code sir ?

  • @icjay1793
    @icjay1793 Рік тому

    how to send data from arduino uno to my esp8266 nodemcu and how to connect the to components ?

  • @utuberard1919
    @utuberard1919 2 роки тому

    Thanks for the great tutorial series. Is there a way we could put a reset in the program when serial communication between master & slave (Simplex) could not sync. I have a master that sends multiple bytes Ex. "A" contains int val of 2, B has 5, C has7 value and so on. When I power up both master & slave at the same time it all syncs fine. But when you power up one after the other it does not sync even after waiting. When you press reset of slave, one or several times it syncs. I'm using Arduino mega for both master & slave using Serial 2 port. Is there a way to put a software reset when it does not sync for say about 2 seconds. I'm using arduinoJson to serialize & deserialize. I think it's also useful to have a reset when the serial wire was accidentally disconnected. Thanks you.

  • @terryterry1655
    @terryterry1655 2 роки тому

    so i can create a while loop to read msg.payload from node red before running the rest of the sketch ?

  • @ProcrastinatingGameCat
    @ProcrastinatingGameCat 3 роки тому +1

    9600 bits per second og bytes per second. At about 3:10 in the video you said one thing and wrote the other in the subtitle?

  • @dalwinderssi4094
    @dalwinderssi4094 2 роки тому

    thanks or serial communication class, i tried to implement that i got following message extern int atoi(const char *__s) __ATTR_PURE__; initializing argument 1 of 'int atoi(const char*)'. now i do not know what is the solution to that. please give some hint , THANKS
    ^~~~

  • @critonify
    @critonify 3 роки тому

    Hi Can I use Serial.read() to input long data type?

  • @elektron2kim666
    @elektron2kim666 2 місяці тому +1

    Got something going with a GPS module and a Cardputer.

  • @michaelpatterson1096
    @michaelpatterson1096 2 роки тому

    Is anyone testing this with the Arduino sketch editor? I copied the code in and tinkered in the serial monitor with No line editing, newline, carriage return, Both NL & CR and none of them parse the data into neatly organized output. It doesn't work for me. Bummer.

  • @chandraprakashsharmasharma8668
    @chandraprakashsharmasharma8668 2 роки тому

    We need to do same data read from lcdI2c

  • @irshadirshu0722
    @irshadirshu0722 2 роки тому

    bro in this code .how to make if condition .eg a charecter is sented to serial monitor (‘A’).the charecter is after sent i want print (serial.println(“enter”)
    you understand this?
    please help 🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

  • @benalihicham1513
    @benalihicham1513 3 роки тому

    hi, if i want to send let's say 6000 int from laptop to arduino how i can do this ? because arduino buffer take only 64 byte !

    • @programmingelectronics
      @programmingelectronics  3 роки тому

      Great question! When you use the read function, it clears the serial receive buffer - so depending on the timing you need, you could send a couple, then read a couple, and work through the 6k ints that way... of course, it might depend on what you're doing with the ints when they arrive...

  • @TheUnofficialMaker
    @TheUnofficialMaker 2 роки тому +1

    where is the next video?

    • @programmingelectronics
      @programmingelectronics  2 роки тому +1

      Hi V J, I believe it is this one:
      sprintf() with Arduino
      ua-cam.com/video/wCfH9VlJKrY/v-deo.html

  • @devendrasuthar5530
    @devendrasuthar5530 3 роки тому +1

    when we will see next part?

  • @terryterry1655
    @terryterry1655 2 роки тому

    error..number not declared after atoi() statement

  • @anujajacob9487
    @anujajacob9487 3 роки тому

    Using the same code, if I type a random word and type Enter then the serial monitor displayed the same word I typed in, but on the next line, it gave a zero, is it because the atoi() function doesn't work, or what gets stored in the variable number, when assigned with atoi(message)?

    • @programmingelectronics
      @programmingelectronics  3 роки тому

      Great question, by chance, in your serial monitor window do you have something other than "New Line" selected in the drop down?

  • @Tod248
    @Tod248 Рік тому +1

    Are you the voice actor for two point hospital XD

  • @sunilkumar-ls2yb
    @sunilkumar-ls2yb 2 роки тому

    no need to do this kind of read procedure. various functions of serial read is already available for reading string char and numbers

  • @altesocke1727
    @altesocke1727 2 роки тому +1

    Ahh a real tuturial. Not this garbage where a guy with a mobile phone-microphone talks and shows the full code for a few seconds and then shows the outro. Make more of this kind of tutorials.

  • @ahmadjaradat3011
    @ahmadjaradat3011 7 місяців тому

    one of the best tutorials ive ever seen...The format, content, even the voice is cool ...Thank you

  • @blackartista
    @blackartista 3 роки тому +2

    It's impossible not to subscribe after this smooth tutorial

    • @programmingelectronics
      @programmingelectronics  3 роки тому

      Glad it was helpful! Are there any specific Arduino topics you would like covered?

    • @blackartista
      @blackartista 3 роки тому

      @@programmingelectronics I think topic on proper use of PWM, interrupts, multiple serials(once I was programming rfid,fingerprint,gps and gsm and I was getting trouble on which serial initialize first later on I managed to rearrange properly but I didn't know why arrangement of which serial matter), and serial plotter as well Thanks

    • @MichaelJamesAdventure
      @MichaelJamesAdventure 3 роки тому +1

      @@blackartista awesome! Thanks for these ideas!