Jump to content
  • 0

NanoPi Duo RPi.GPIO


sgjava
 Share

Question

I've built https://github.com/auto3000/RPi.GPIO_NP for the Duo running Armbian Ubuntu test image:

 

cd /sys/class/gpio

for i in gpiochip* ; do  echo `cat $i/label`: `cat $i/base` ; done

 

1c20800.pinctrl: 0
1f02c00.pinctrl: 352

 

Has anyone actually got RPi.GPIO working on Duo? I'm trying to get luma.oled cranking and have SPI working fine, but need GPIO working as well.

Link to comment
Share on other sites

18 answers to this question

Recommended Posts

Help Armbian team helping you!

  • 0
On 13.12.2017 at 8:13 PM, raschid said:

Try https://github.com/karabek/nanopi_duo_gpio_pyH3. I have not tried SPI, but I2C works rather nicely.

The mapping of this fork is really a mess... There are GPIOs defined which are not accessible on the Duo. PA15, PA16, PL11 and PG11 which are accessible via pin header aren't defined. Numbering for using connector instead of port is useless, cause also wrong... 

If you need them go to pyGPIO ... :P (or go to pyGPIOs GitHub, search for the nanopiduo mapping, replace the one in this pyA20 fork and stay with it.. :P )

Link to comment
Share on other sites

  • 0

Haha, thanks. I was only testing the power LED blink with that one so far (looks like that was the only change). What I really need is a RPi.GPIO API. I'm looking at https://github.com/rm-hull/OPi.GPIO now, so I can use luma.oled. I've been able to get it to work with CHIP, Pine A64, ODROID C1, etc. with RPi.GPIO replacements. Having a hard time with Duo.

Link to comment
Share on other sites

  • 0

looks quite easy... opi is more or less the same.. not? As long as this:

Quote

Only the basic GPIO functions are replicated, using sysfs: this allows the GPIO pins to be accessed from user space.

matches to your needs.

 

I think, you only have to adjust this one: https://github.com/rm-hull/OPi.GPIO/blob/master/OPi/pin_mappings.py

reading the schematics and calculating sysfs pin numbers from here:

http://linux-sunxi.org/GPIO#Accessing_the_GPIO_pins_through_sysfs_with_mainline_kernel

Link to comment
Share on other sites

  • 0

Yes, this is why I went down this route. I'll see if I can figure out the mappings. If I understand correctly then for example:

 

(position of letter in alphabet - 1) * 32 + pin number

 

CSUART3_TX/SPI1_CS/GPIOA13 would be:

 

(1-1) * 32 + 13 = 13?

Link to comment
Share on other sites

  • 0
2 hours ago, sgjava said:

(1-1) * 32 + 13 = 13?

should be correct

 

From pyGPIOs mapping.h:

			J1		  	 J2
(UART0_RX)		|1| microUSB |1|	 5V	
(UART0_TX)		|·|	 		 |·|	5V						
GND			|·|	 		 |·|	3.3V
GPIO3 (TWI_SCL)		|·|			 |·|	GND	
GPIO2 (TWI_SDA)		|·|			 |·| 	GPIO4 (IR_RX)
GPIO23 (SPI1_CS)	|·|			 |·|	GPIO18 (IOG11)	
GPIO22 (SPI1_CLK)	|·|			 |·|	DM3 D-
GPIO27 (SPI1_MISO)	|·|			 |·|	DM3 D+
GPIO17 (SPI1_MOSI)	|·|			 |·|	DM2 D-	
GPIO15(UART1_RX)	|·|			 |·|	DM2 D+
GPIO14 (UART1_TX)	|·|			 |·|	RDN
(CVBS)			|·|			 |·|	RDP	
(LINEOUT_L)		|·|			 |·|	TXN
(LINEOUT_R)		|·|			 |·|	TXP
(MICP)			|·|			 |·|	LED-LINK
(MICN)			|·|	microSD		 |·|	LED-SPD
*/  {"J1",
        {
            {   "GPIO3",  SUNXI_GPA(11),  4   },
            {   "GPIO2",  SUNXI_GPA(12),  5   },
            {   "GPIO23",  SUNXI_GPA(13),  6   },
            {   "GPIO22",  SUNXI_GPA(14),  7  },
            {   "GPIO27",  SUNXI_GPA(16),  8  },			
            {   "GPIO17",  SUNXI_GPA(15),  9  },
	    {   "GPIO15",  SUNXI_GPG(6),  11  },
            {   "GPIO14",  SUNXI_GPG(7),  10  },
            {
                {   0,  0,  0}
            },
        }
    },
	{"J2",
        {
            {   "GPIO18",  SUNXI_GPL(11),  5   },            
            {   "GPIO4",  SUNXI_GPG(11),  6   },
            {
                {   0,  0,  0}
            },
        }
    },	

 

 

Quote

with XX being the number of the desired pin. To obtain the correct number you have to calculate it from the pin name (like PH18)[1]:

(position of letter in alphabet - 1) * 32 + pin number

E.g for PH18 this would be ( 8 - 1) * 32 + 18 = 224 + 18 = 242 (since 'h' is the 8th letter).

1

 

'GPIO3' --> PA11 --> (1-1)*32 + 11 = 11

'GPIO4'  --> PG11 --> (7-1)32 + 11 = 203   ({   "GPIO4",  SUNXI_GPG(11),  6   },)

 

 

 

Link to comment
Share on other sites

  • 0

Cool, thanks, I was able to read the button (GPIOL3) using:

echo 355 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio355/direction
cat /sys/class/gpio/gpio355/value
echo 355 > /sys/class/gpio/unexport

Now I'm going to try hacking OPi.GPIO :)

Link to comment
Share on other sites

  • 0

just for fun... I forked it and wrote the mapping for a nanopi duo (with minishield). Only the GPIOs no buttons no leds, no board to test... :D

https://github.com/chwe17/OPi.GPIO

 

If it works I might write a wrapper for the mappings from the pyGPIO and adjust the library a little bit to make it 'multiple boards' usable. 

 

Can you test it? 

 

in case you don't have the minishield: BCM naming should work and there is the 'naming scheme':

			J1		  	 J2
(UART0_RX)		|1| microUSB |1|	 5V	
(UART0_TX)		|·|	 		 |·|	5V						
GND			|·|	 		 |·|	3.3V
GPIO3 (TWI_SCL)		|·|			 |·|	GND	
GPIO2 (TWI_SDA)		|·|			 |·| 	GPIO4 (IR_RX)
GPIO23 (SPI1_CS)	|·|			 |·|	GPIO18 (IOG11)	
GPIO22 (SPI1_CLK)	|·|			 |·|	DM3 D-
GPIO27 (SPI1_MISO)	|·|			 |·|	DM3 D+
GPIO17 (SPI1_MOSI)	|·|			 |·|	DM2 D-	
GPIO15(UART1_RX)	|·|			 |·|	DM2 D+
GPIO14 (UART1_TX)	|·|			 |·|	RDN
(CVBS)			|·|			 |·|	RDP	
(LINEOUT_L)		|·|			 |·|	TXN
(LINEOUT_R)		|·|			 |·|	TXP
(MICP)			|·|			 |·|	LED-LINK
(MICN)			|·|	microSD		 |·|	LED-SPD

in case you use the minishield (there you go... :P ): 

mapping_small.thumb.png.4b17fe118586840c19c212358a412f6a.png 

Link to comment
Share on other sites

  • 0
			{   "POWER_LED",  SUNXI_GPL(10),  1   },
			{   "STATUS_LED",  SUNXI_GPA(10),  2  },

POWER_LED is PL10

STATUS_LED is PA10

 

12 minutes ago, sgjava said:

rm-hull:master and chwe17:master are identical.

ooops.. was only on my local git... :P 

 

Now it should be there...  

Link to comment
Share on other sites

  • 0

How would you map the button and led then? I doesn't really have a pin number. I'm just going to hack some in the missing slots and see what happens. I'm trying to get something simple working before I wire up the SPI display I'm testing. I already have spi-dev working fine.

Link to comment
Share on other sites

  • 0
14 minutes ago, sgjava said:

How would you map the button and led then? I doesn't really have a pin number. I'm just going to hack some in the missing slots and see what happens. I'm trying to get something simple working before I wire up the SPI display I'm testing. I already have spi-dev working fine. Send me a PM and maybe I'll send you a Duo and/or mini shield. I'm going to get some v1.1s. I have v1.0 now.

I'll have to dig up the LEDs, but if they're used by the system then you won't be able to access them through the sysfs GPIO interface; you'll have you use the kernel LED driver. The button on the NanoPi Duo is GPIO 355

Link to comment
Share on other sites

  • 0

Look above and you'll see I've figured out the button. The status LED blinks with https://github.com/karabek/nanopi_duo_gpio_pyH3/blob/master/examples/blink_POWER_STATUS_PL10.py, so I thought it was possible through A10. Also, if you look at /sys/class/gpio you see gpiochip352 which is the power LED. I'm not saying you are wrong, but maybe I'll need to dig into the source I just mentioned. In any event I'm going to try a simple OPi.GPIO hack real quick.

Link to comment
Share on other sites

  • 0

OK, this is the same result that trying to access A10 from /sys/class/gpio which OPi.GPIO uses:

 

UserWarning: Channel 99 is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.

 

I mapped 99 to 10. Let me look at the working source. The main thing I need is gpio_DC="CSID1", gpio_RST="CSID0" for luma.oled (this is from my CHIP config) and I believe that will work fine. I just wanted to test without wiring and configuring (being lazy here).

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...