USB Serial Input on the Raspberry Pi Pico

Поделиться
HTML-код
  • Опубликовано: 4 окт 2024

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

  • @H3liosphan
    @H3liosphan 3 года назад +8

    Haha nice, thanks! Here's a small challenge for you, I figured this out over the weekend, make the input non-blocking so code can continue to run even if there's no characters entered on the terminal. This is important if you're driving graphics or something in "the background" so to speak. I've actually posted a code snippet on the Raspberry Pi Pico SDK forum page on the official site.

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

      Hint- you do not need to use the second processing core.

    • @LearnEmbeddedSystems
      @LearnEmbeddedSystems  3 года назад +1

      That is a good point regarding the blocking problem! I think I read in the Pico C/C++ SDK that a non-blocking function was added, perhaps it was you in the forum that drew my attention too it! Another option could be letting one core handle the user I/O if there is no other need for it!

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

      Just saw your follow up - Just browsed the SDK documentation and seen the getchar_timeout_us function, as well as your post on the forums! Nice work :)

    • @H3liosphan
      @H3liosphan 3 года назад +3

      @@LearnEmbeddedSystems Yes in fact the function you're after is called getchar_timeout_us(). It's a bit of a bodge unfortunately because in a real stdio environment you're supposed to use fcntl() to set non blocking flag. FCNTL surprisingly compiles and runs on the pico, but has no effect. Took some sleuthing to figure out all of the special getchar functions undocumented or poorly documented foibles, such as if no chars are in the stdin buffer then it returns a byte 255, it does have a define tho I learned later.

    • @rakurame6990
      @rakurame6990 2 года назад +1

      @@H3liosphan Could you please share the forum post link?

  • @sss22215
    @sss22215 2 года назад +1

    hi as like uart receive interrupt , is there any api for receive interrupt in usb serial terminal ???

  • @arjayUU
    @arjayUU 2 года назад +2

    Can you specify the 'interesting behavior' of scanf for such cases please?

    • @ukicomputers
      @ukicomputers Год назад

      That behavior is if for example yo write if(buffer == "some tetx")://do something it anyway don't beacuse char requires math operations likely - '0' * 100 to give clear output

  • @trentraymond9359
    @trentraymond9359 2 года назад +1

    How can this be reversed so that the pico sends commands. For example, commands send from the pico over a RS232 connection via RJ45?

  • @arrowacrobatics9980
    @arrowacrobatics9980 Год назад

    So happy to see that you can do this with a super basic cmake project rather than adding all that unnecessary bloatware to a microcontroller. Exactly what I need for my projects, short simple and full controll.

  • @ВасилКолев-в2я
    @ВасилКолев-в2я 3 месяца назад

    Is there an asynchronous way for receiving data via USB?

  • @sb-zn4um
    @sb-zn4um Год назад

    Can you suggest what I might do in the case where I want my pico to take an input from an external microcontroller / device (something not built by me) but I also want to see what that input is for the purpose of debugging and actually analysing the input so I can build my project based on it. i.e. a sensor not made by me is outputting some data, I want to extract information from this data but I have no idea what form it will come in, so I need some feedback loop from the pico whereby I can see what data it is receiving. Or maybe routing it through my pc and analysing what format the data is in first is the best option, rather than a feedback loop via the pico. Although I am curious about the feedback way of doing it as it seems useful
    In simpler terms I guess the question is, is there a second output from the pico that can go into my PC?
    Thanks

  • @FoxTvMta
    @FoxTvMta 2 года назад +1

    hey when i run the pputv i freezes with this code!

  • @tavobachi
    @tavobachi 2 года назад

    Hi! Great video! Do you know what the fastest data transmission is between pico and pc?

  • @trejavic
    @trejavic 7 месяцев назад

    is it possible to create a python file to use as serial port instead putty?

  • @montaguemonro565
    @montaguemonro565 3 года назад +2

    Hi! I've been learning and playing with my new pico but feel as though the material i find and the pico documentation really seems to be pushing micropython. Could you advise whether I should be trying to learn C++ or micropython moving forward? Ideally i'd like to build using other boards such as the ESP32 in the future but have no idea if they support micropython. Thanks in advance!

    • @LearnEmbeddedSystems
      @LearnEmbeddedSystems  3 года назад +2

      Hi, you raise a great question, it is difficult to answer. I think it really depends on your previous programming background. Micropython and C are two different ways of achieving the same goal. If you understand C/C++ then you will understand what micropython is doing behind the scenes for you. However if you are relatively new to programming then C may be quite daunting and micropython may provide a smoother (and maybe more enjoyable) learning experience. Micropython does support the esp32 series.
      If I could only learn one, I would learn C as it will be most useful across all microcontroller platforms. However, in reality we can learn more than one programming language, and if you feel more comfortable with one them learn that one first and try and recreate your programs and projects in the other.
      Sorry this is a bit of a non-answer but it's a very circumstantial question so I hope this helps.

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

      pycom has esp32 boards that support micropython

    • @montaguemonro565
      @montaguemonro565 3 года назад +2

      @@LearnEmbeddedSystems Thanks for the help, I have some experience with python and JS so i'll go with MP for now, then see how it goes. :)

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

      Best of luck!

    • @Mr.Leeroy
      @Mr.Leeroy 3 года назад

      @@montaguemonro565 Just learn C if you are serious abouth micros. Anything else on embedded is a lazy way that leads to the begining if you don't quit halfway.

  • @cokeforever
    @cokeforever Год назад

    why would you overlap the lower part of the screen with your "suggested video", when exactly this part of the screen is supposed to show led blinking? )))))

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

    I am attempting to get a USB keyboard plugged into my pico via a mini usb OTG adapter. Do you know this could be accomplished to put the usb port on the pico into host mode and accept keystrokes that print to stdout? i have system powered via vbus and i have swd debug and uart stdin/stdout.

  • @davitmodebadze9707
    @davitmodebadze9707 2 года назад +1

    Hi, nice video. Is there a way to do this with python/circuitpython?

    • @LearnEmbeddedSystems
      @LearnEmbeddedSystems  2 года назад +1

      There most likely is, but I do not use micro/circuit python. Sorry!

  • @ashishshingrut8335
    @ashishshingrut8335 Год назад

    Can we connect any barcode scanner to Pico ?

  • @-rezy9663
    @-rezy9663 3 года назад

    What cable can i use to plug the raspebrry pi pico into the pc

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

    Would there be a way of sending and receiving commands to the Pico's USB using an old mobile phone?
    Doing so, we could then build a stand-alone system that could provide remote telemetry for devices such as weather station hardware... without the need to use a full-fat PC

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

      CircuitPython has an HID module that would work

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

      Yes there are many options, I would recommend a breakout board tyoe which you can send commands over SPI which can essentially send texts of your data at regular intervals! Or in some cases you can use 4G or other data services! Here is an example thepihut.com/products/adafruit-fona-mini-cellular-gsm-breakout-ufl-version

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

    Great!

  • @gregiwal
    @gregiwal 3 года назад +3

    Great. Can you doit same with Micropython instead?

    • @LearnEmbeddedSystems
      @LearnEmbeddedSystems  3 года назад +8

      I am thinking about making 1 long guide of all my C tutorials but written in MicroPython, would most likely be about an hour long but should be comprehensive!

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

      I'd like to see a micro python implementation of this too

    • @cgp9998
      @cgp9998 2 года назад

      @@LearnEmbeddedSystems Id like to see the same but in mycropython! pls

  • @mdmuntaharul6795
    @mdmuntaharul6795 2 года назад

    respberry pi pico as usb to ttl how can i ue this

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

    So I have an application where I would send 2 different and independent PWM values in a single string to RPi Pico from a python code using pyserial to rotate 2 motors on my differential drive bot. How can I split the string and read both values simultaneously in Pico?

    • @krzysztofkubik6531
      @krzysztofkubik6531 Год назад

      did you manage to use USB input for raspberry pi pico in micropython?

    • @atharvabhorpe3128
      @atharvabhorpe3128 Год назад

      @@krzysztofkubik6531 Unfortunately, no. MicroPython and Pico both were very new at that time, so the documentation was very limited. Later Arduino Support was released for Pico and I was successful with the Arduino code for Pico.

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

    I can't see any com port after connecting my pico via usb cable, any ideas?

    • @anthonyandreoli8042
      @anthonyandreoli8042 3 года назад +1

      make sure to add the following to the CMakeLists.txt file @ 1:10
      pico_enable_stdio_usb(blink 1)
      pico_enable_stdio_uart(blink 0)
      (if blink is your project name)

  • @Eslam-Sameh
    @Eslam-Sameh 2 года назад

    I hope one day you make a video for only keyboard and power source without PC

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

    Hiw to debug using ST LINK nad SWD pins on Pico
    Does VS Code support ST LINK debug

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

      You would have to install the tools and configure the launch.json to make it work. I don’t think it is that straight forward but you could give it a go if you have time. www.element14.com/community/community/raspberry-pi/blog/2021/02/07/debugging-the-raspberry-pi-pico-on-windows-10

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

      I tried to give more links but RUclips won’t allow me

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

    How to make neural network in pico

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

      Thank you for the suggestion, I will look into making a video on this topic!

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

      @@LearnEmbeddedSystems your welcome

  • @franciscoayrolo5612
    @franciscoayrolo5612 2 года назад +1

    Hi there. Thanks for the guide. I'm having a weird problem I can't find answers to online. I tried your code, and it compiles and flashes without issues, but then I can't find the Pico anywhere! I tried with putty and minicom, and it's supposed to be on dev/ttyACM0, but there's nothing there.
    If I remove the code that takes input from the PC (basically the getchar) it starts to work just fine. I'm super lost on what could be causing this

    • @Jojo-nf1yk
      @Jojo-nf1yk 2 года назад

      Hi all. I have the same issue. The getchar() seems to block the serial soft like mnicom (linux) or Putty (win). I have no solution so far. I'm searching for one...

    • @Julian-ti1bv
      @Julian-ti1bv 2 года назад +2

      Hey there, I just ran into the same problem and found two solutions that worked for me ( Raspberry Pi OS with minicom )
      No 1: Using "getchar_timeout_us(10000)" instead of "getchar()"
      No 2: Setting up another while loop before the main loop which runs as long as no usb connection is established:
      while( !stdio_usb_connected() ){
      printf("waiting for usb connection
      ");
      sleep_ms(100);
      }
      I hope that works for you as well

  • @poijmc606
    @poijmc606 2 года назад

    My PIco freezes when using getchar(), works for a few seconds only. Does anyone experience same issue?

    • @bxu789
      @bxu789 2 года назад

      Encountered the same program. Pico will accept commands (1 or 0) for a couple of times and then freezes. Make me think that I should use a dedicated USB to RS232 cable to connect to UART0 directly.