Use Raspberry Pi 5 GPIO - Push button input - LED output - ChatGTP for code - GPIOD [PART 2 OF 2]

Поділитися
Вставка
  • Опубліковано 21 жов 2024
  • On a raspberry pi 5 we test a push button on input16 and LED on output 25. This is done with the libgpiod library, which has been tested and works on a raspberry pi 5 and raspberry pi 4. The old method (sysfs) has been deprecated. The C++ program turns on output25 (LED) when input16 (button) is turned on. Then ChatGTP is used to modify the C++ code to blink the LED on and off when the button is latched. Finally, ChatGTP is used to convert the C++ program to python, and the python program is run with the gpiozero library (which runs slower than gpiod).
    install libgpiod
    sudo apt-get install libgpiod2 libgpiod-dev
    sudo apt install gpiod
    check gpio line configuration
    gpioinfo
    For Raspberry Pi 5 use gpiochip4 (For Raspberry Pi 4 use gpiochip0)
    monitor input 16 button press
    gpioget gpiochip4 16
    set output 25 high
    gpioset gpiochip4 25=1
    set output 25 low
    gpioset gpiochip4 25=0
    CODE: github.com/sol...
    Access gpio with gpiod:
    www.ics.com/bl...
    lloydrochester...
    adafruit-playg...
    old way sysfs, deprecated
    www.ics.com/bl...
    Pi pinout: vilros.com/pag...
    Push button link: www.adafruit.c...

КОМЕНТАРІ • 18

  • @simonkarlsson6198
    @simonkarlsson6198 3 місяці тому +1

    Thank you for this video!
    I asked ChatGPT for help since there is almost no libary for pi5 but the code it gave was for chip 0. that means it didn't work.. but since you said that it's chip 4 it worked :D

  • @charleslaw2561
    @charleslaw2561 4 місяці тому

    Finally. pi 5 uses gpiochip4 and my pi3 uses gpiochip0. I do not mind the horrible quality video/physical screen recording because you supplied the code. There is much less help for C/C++. Thanks. Note: I had a problem with lgpio library. My 5->3.3 input voltage dividers were not working because the input pins were drawing 0.3 amps! I assume the input impedance is configurable now. You would think that requesting a line to be type input would default to a high impedance.................

  • @Matt-04
    @Matt-04 8 місяців тому

    But what if I need blazing fast gpio speeds to control stepper motors? And what if the code is too complicated to convert from c++ to python? What do I do?

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

      Check out the existing stepper libraries and functions that come with the arduino IDE. docs.arduino.cc/learn/electronics/stepper-motors/ Usually stepper motors are driven by an embedded system running C/C++ (for example MKS GenL board or Duet 6HC board or arduino), which runs faster than python. Python generally runs slower because it is dynamically typed and runs on an interpreter.

    • @Matt-04
      @Matt-04 8 місяців тому

      So the answer is I can’t with raspberry pi 5. That’s what I was unfortunately not wanting to hear 😢. I’ve been controlling my steppers with an Arduino mega but it’s not fast enough. I have a rp5.

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

      @@Matt-04 are you able to share your project? Have you looked into linuxcnc? linuxcnc.org/

    • @Matt-04
      @Matt-04 7 місяців тому

      @@samwechsler it’s all over my channel if you wanna see it. I’ve since decided to just use a teensy 4.1 as it has the speed I need 🔥. Thanks for taking the time to respond to me tho 👍.

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

    I have a problem with method "echo 24 >/sys/class/gpio/export" it no run in pi5 so What need I had do

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

      "echo 24 >/sys/class/gpio/export" uses sysfs, which will not work with pi 5 due to the new GPIO chip. Use gpiod as per ths video.

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

      @@samwechsler thanks for your suggestions so I am a student so I have a little knowledge about embed system. If you have a good document about gpiod can you share me or making a video detail about gpiod. Thanks you so much.

    • @YanNaingAyeMdy
      @YanNaingAyeMdy 6 місяців тому

      Try to list gpio chips "ls /sys/class/gpio" and add its base address, for example chip4 with base address 571 for pin24, use gpio595 such as "echo 595 >/sys/class/gpio/export".

  • @Chris-uo3rj
    @Chris-uo3rj 7 місяців тому

    How do i turn pins on/off using c++?

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

      Are you using a Raspi 4 or 5? Do you have the hardware setup with the LED and resistor in series on GPIO25? Were you able to manually set pin 25 with the gpioset command in the terminal? I'd start here if I were you, blink GPIO output25: github.com/solarsamuel/raspi5_IO/blob/main/blink25.cpp

    • @Chris-uo3rj
      @Chris-uo3rj 7 місяців тому

      @@samwechsler i have pi 5