reptile Posted December 17, 2017 Share Posted December 17, 2017 Hi All, Its been a week learning, battling and reading posts on armbian forum which was very much helpful - i now starting to master orange pi and armbian! However i can't seem to understand how to trigger the two on board LEDs (Red & Green), in one of the armbian images i tested this was implemented but not in the armbian version suggested for he Orange PI Zero Plus 2 H5: https://www.armbian.com/orange-pi-zero-2-h5/ It seems that my leds folder is empty, where to download or how to populate the missing files? ls /sys/class/leds Empty folder uname -r 4.14.4-sunxi64 modprobe gpio-sunxi modprobe: FATAL: Module gpio-sunxi not found in directory /lib/modules/4.14.4-sunxi64 ls /sys/class/gpio export gpiochip0 gpiochip352 unexport ls /sys/class backlight devcoredump drm hidraw ieee80211 mdio_bus mtd pps regulator scsi_disk spi_master udc watchdog bdi devfreq extcon hwmon input mem net ptp rfkill scsi_generic spi_slave vc zram-control block devfreq-event gpio i2c-adapter iommu misc phy pwm rtc scsi_host thermal virtio-ports bsg dma graphics i2c-dev leds mmc_host power_supply rc scsi_device sound tty vtconsole Many thanks! Link to comment Share on other sites More sharing options...
reptile Posted December 18, 2017 Author Share Posted December 18, 2017 ok, 2nd day and starting to better understand this, will explain it loudly for myself and anyone else: Though the answer was there from the beginning, too bad that it wasn't clear for meL http://linux-sunxi.org/GPIO First we need to "create" or "attach" the GPIO port using this command: sudo echo XX > /sys/class/gpio/export The XX is a complex calculation of the GPIO: On 6/25/2016 at 8:04 PM, martinayotte said: (position of letter in alphabet - 1) * 32 + pin number so for Orange PI Zero plus 2 H5 (should be same for h3/h2) the RED led would on GPIO PA17 and GREEN LED on GPIO PL10 (Info from here: http://linux-sunxi.org/Xunlong_Orange_Pi_Zero_Plus_2 ) The calculation would be (Letter A is 1, the "P" not counted): (1 -0) * 32 + 17 = 17 (For RED LED) while for Green LED: (12 - 1) * 32 + 10 = 362 sudo echo 362 > /sys/class/gpio/export sudo echo 17 > /sys/class/gpio/export Now lets check the status of the GPIOs: cat /sys/kernel/debug/gpio gpiochip1: GPIOs 0-223, parent: platform/1c20800.pinctrl, 1c20800.pinctrl: gpio-9 ( |reset ) out hi gpio-14 ( |sysfs ) out hi gpio-17 ( |sysfs ) in lo gpio-110 ( |sysfs ) in lo gpio-166 ( |cd ) in hi IRQ gpio-204 ( |usb0_id_det ) in lo IRQ gpiochip0: GPIOs 352-383, parent: platform/1f02c00.pinctrl, 1f02c00.pinctrl: gpio-358 ( |? ) out lo gpio-362 ( |sysfs ) in lo The GPIOs should be "out" direction (i guess because we are outputting to it), so lets fix them: sudo echo out > /sys/class/gpio/gpio362/direction sudo echo out > /sys/class/gpio/gpio17/direction Now that the direction is correct, lets try to switch them on or off: sudo echo 1 > /sys/class/gpio/gpio362/value sudo echo 0 > /sys/class/gpio/gpio362/value sudo echo 1 > /sys/class/gpio/gpio17/value sudo echo 0 > /sys/class/gpio/gpio17/value Now that the LEDs are controllable, The next challenge would be adding some rhythm to the led per hardware occasions such as heart beet, read/write.. i hope it will be easier than above 2 Link to comment Share on other sites More sharing options...
chwe Posted December 18, 2017 Share Posted December 18, 2017 do you want to control the GPIO from console/bash? Or is something like c/python more familiar to you? In case you wanna go for: C @Larry Bank has a nice project for you... In case you're more the python guy... (but then you've to write a mapping.h for your board, doesn't need that much time...) Link to comment Share on other sites More sharing options...
reptile Posted December 18, 2017 Author Share Posted December 18, 2017 I thought to use in few scenarios: -Slow Blink red on boot until rc.local -Steady or Fast red blink in rc.local depend on network connection status -Green blink in python script when all is working I'm not sure how to do it on boot, but my starting point is the simple shell echo command that i could use in rc.local and python using the line: os.system('echo 1 > /sys/class/gpio/gpio362/value') then somehow to blink it like in arduino Though it just seem too easy and good to be true, so I'm looking around for some more complex examples of blink and "direct access" to GPIOs from python Thanks for the links, i think the pyGPIO could be my neat start to blink led in python. Link to comment Share on other sites More sharing options...
martinayotte Posted December 18, 2017 Share Posted December 18, 2017 11 hours ago, reptile said: The XX is a complex calculation of the GPIO That isn't so omplex ... Link to comment Share on other sites More sharing options...
chwe Posted December 18, 2017 Share Posted December 18, 2017 14 hours ago, reptile said: Thanks for the links, i think the pyGPIO could be my neat start to blink led in python. https://github.com/chwe17/pyGPIO/blob/master/pyGPIO/gpio/mapping/template26.h there's your template.. you have to look into the schematics and fill it with the right numbers.. e.g. PH17, PA8 etc... Only Quote { "GPIO2", SUNXI_GPX(Z), 3 }, X and Z should be replaced to keep the library consistent... As soon as you send a PR, I'll add the board to the 'supported boards' and you can test it. Link to comment Share on other sites More sharing options...
reptile Posted October 18, 2018 Author Share Posted October 18, 2018 As an update, on OrangePI H5 Zero Plus (the one with the LAN) the LED triggering command is a bit different (though i am using the same OS that was on Zero plus 2) echo 1 > /sys/class/leds/orangepi:green:pwr/brightness echo 0 > /sys/class/leds/orangepi:green:pwr/brightness echo 1 > /sys/class/leds/orangepi:red:status/brightness echo 0 > /sys/class/leds/orangepi:red:status/brightness Link to comment Share on other sites More sharing options...
Recommended Posts