飞腾派
直播中

卢松涛

12年用户 469经验值
擅长:嵌入式技术
私信 关注
[经验]

【飞腾派4G版免费试用】红绿灯项目-2飞腾派 openkylin 进行IO控制

接上文[【飞腾派4G版免费试用】2飞腾派 openkylin 进行IO控制-灯闪(https://bbs.elecfans.com/jishu_2405776_1_1.html)

红绿灯项目
wKgZomV-Y2iAFAWKAAHp83gUMf02871.jpg

GPIO1_12 归属于 gpiochip1,gpiochip1 对应的编号从 480 到 495,GPIO1_12 偏移 12,所以对应的编号为 480+12=492。绿

GPIO1_11 归属于 gpiochip1,gpiochip1 对应的编号从 480 到 495,GPIO1_11 偏移 11,所以对应的编号为 480+11=491。黄

GPIO3_1 的编号为 448+1=449。红
接ssh
1704888503413.png
编辑新脚本rgb.sh

#!/bin/sh

LEDr_GPIO=/sys/class/gpio/gpio449
LEDg_GPIO=/sys/class/gpio/gpio492
LEDy_GPIO=/sys/class/gpio/gpio491

if test -d $LEDr_GPIO; then

    echo "GPIO449 already exported"

else

    echo 449 > /sys/class/gpio/export

fi
if test -d $LEDg_GPIO; then

    echo "GPIO492 already exported"

else

    echo 492 > /sys/class/gpio/export

fi
if test -d $LEDy_GPIO; then

    echo "GPIO491 already exported"

else

    echo 491 > /sys/class/gpio/export

fi
echo out > $LEDr_GPIO/direction
echo out > $LEDg_GPIO/direction
echo out > $LEDy_GPIO/direction
while true; do

    echo 0 > $LEDr_GPIO/value
    echo 0 > $LEDg_GPIO/value
    echo 0 > $LEDy_GPIO/value 
    echo 1 > $LEDr_GPIO/value       
    sleep 5
    echo 0 > $LEDr_GPIO/value
    echo 1 > $LEDg_GPIO/value
    sleep 5
    echo 0 > $LEDg_GPIO/value
    echo 1 > $LEDy_GPIO/value         
    sleep 0.5
    echo 0 > $LEDy_GPIO/value         
    sleep 0.5    
    echo 1 > $LEDy_GPIO/value         
    sleep 0.5
    
done

文件加X执行权

openkylin@openkylin:~$ cd /sys
openkylin@openkylin:/sys$ ls
block  bus  class  dev  devices  firmware  fs  kernel  kylin_authentication  kylin_kmod  module  power
openkylin@openkylin:/sys$ cd class
openkylin@openkylin:/sys/class$ dir
ata_device   devfreq         gpio           iommu     nvme            pps           sas_device      scsi_host   udc
ata_link     devfreq-event   graphics       lcd       nvme-fabrics    ptp           sas_end_device  sound       uio
ata_port     dma             hwmon          leds      nvme-subsystem  pwm           sas_expander    spi_master  usb_role
backlight    drm             i2c-adapter    mdio_bus  pci_bus         rapidio_port  sas_host        tcmdev      vc
bdi          drm_dp_aux_dev  i2c-dev        mem       pci_epc         regulator     sas_phy         tee         virtio-ports
block        extcon          ieee80211      misc      phy             remoteproc    sas_port        thermal     vtconsole
bluetooth    fc              infiniband     mmc_host  pktcdvd         rfkill        scsi_device     tpm         wakeup
bsg          fcloop          infiniband_cm  mtd       powercap        rpmsg         scsi_disk       tpmrm       watchdog
devcoredump  firmware        input          net       power_supply    rtc           scsi_generic    tty
openkylin@openkylin:/sys/class$ cd gpio
openkylin@openkylin:/sys/class/gpio$ didr
-bash: didr:未找到命令
openkylin@openkylin:/sys/class/gpio$ ls
export  gpiochip416  gpiochip432  gpiochip448  gpiochip464  gpiochip480  gpiochip496  unexport
Last login: Fri Aug 25 14:38:38 2023 from 192.168.2.201
openkylin@openkylin:~$ sudo ./rgb.sh
GPIO449 already exported
GPIO492 already exported
GPIO491 already exported

灯正常闪微信图片_20240110210646.jpg

达到预期。脚本rgb.sh编程相当简洁方便。红绿灯项目完成。

c9b2791b49c2a03aab79a489404c5702

更多回帖

发帖
×
20
完善资料,
赚取积分