Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Need help with GPIO on NanoPi M4V2

Featured Replies

Hello,

 

I bought myself a NanoPi M4V2 and 4x SATA HAT for NanoPi M4, hoping to make a small home made server with some docker containers. I installed Armbian buster 5.10.21, downloaded from your site and managed to boot the OS from an attached SATA drive.

I have some experience with linux (mostly Ubuntu/Debian), I own and I’ve played with Raspberry boards and I wrote small python scripts to work with GPIO on raspberry pi (how to blink a led or how to connect and display some text on an I2C 16x2 LCD).

I thought that might be a nice project if I could connect an I2C LCD to nanopi and display some text text from python script, but here where I hit a brick wall. I found and read on this forum some discussion about user space GPIO, installing WiringPi, sysfs, tried them all, but none worked. Regarding user space GPIO, I have no idea where to start; sysfs seems to be deprecated (I don’t care), however I have no /sys/class/gpio/gpio50 (or any other pin); wiringpi has no Hardware line in /proc/cpuinfo and gpio readall responds with wiringPiSetup: Unknown model.

I’ve managed to work with GPIO pins (from Python script) on FriendlyElec official OS and using WiringPi library, but I prefer Armbian because I can make it boot from SATA drive (which I don’t know if is possible with FriendlyElec OS).

Let me know if you need more hardware infos and how I can get them for you. Thank you.

 

Radu

it is WiringNP  for GPIO .

and gpio just works only you hve to calculate the pin

 

 but you are talking connecting a i2c device 

 

for lcd some you can add to dts and compile a kernel module .

 

 or through a script wich calls the i2c bus only just watch the bus number and device id .

ow and watch the voltage of the i2c bus

 

 

  • Author

Thank you for your message thc13. You are talking about WiringNP from here?

 

https://github.com/friendlyarm/WiringNP

 

Unfortunately I’ve tried this, too, but without too much success.

When executing gpio readall, I still get 

 Unable to determine board revision from /proc/cpuinfo
 -> Is not NanoPi based board. 
 ->  You may want to check:
 ->  http://www.lemaker.org/

 

I don’t understand why every library that I've tried, needs something from cpuinfo and why that info is not present there on Armbian OS? It seems that the WiringPi installed on FriendlyElec OS has no problem finding what it needs in cpuinfo. I wonder:  is there any way to write into /proc/cpuinfo? From previous attempts, it seems that I need to add a Hardware line, or something like that.

18 hours ago, radu said:

I don’t understand why every library that I've tried, needs something from cpuinfo and why that info is not present there on Armbian OS? It seems that the WiringPi installed on FriendlyElec OS has no problem finding what it needs in cpuinfo. I wonder:  is there any way to write into /proc/cpuinfo? From previous attempts, it seems that I need to add a Hardware line, or something like that.

 

Because GPIO pin mappings are different on every single SBC that exists, and often times they are not called out by hand? The software needs to know which board you're on, and vendor kernels can often times put in nonstandard hacks that don't exist elsewhere.

 

Also, WiringPi isn't exactly a standard product, and I'm unsure if it's supported outside the FriendlyElec build. Perhaps you'd want to try something actually built for this project? https://forum.armbian.com/topic/5655-armbianio-api-proposal/

 

Barring that, I'd suggest installing gpiod, and using gpioinfo, gpioget, gpioset, etc ...

I've been using the following table with the M4v2:

 

------+-----+----------+------+ Model  NanoPi-M4 +------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | Physical | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----++----+---+------+----------+-----+------+
 |      |     |     3.3V |      |   |  1 || 2  |   |      | 5V       |     |      |
 |      |     | I2C2_SDA |      |   |  3 || 4  |   |      | 5V       |     |      |
 |      |     | I2C2_SCL |      |   |  5 || 6  |   |      | GND(0V)  |     |      |
 |   32 |   7 | GPIO1_A0 |  OUT | 0 |  7 || 8  |   | ALT  | GPIO4_C1 | 15  |  145 |
 |      |     |  GND(0V) |      |   |  9 || 10 |   | ALT  | GPIO4_C0 | 16  |  144 |
 |   33 |   0 | GPIO1_A1 |   IN | 0 | 11 || 12 | 1 | IN   | GPIO1_C2 | 1   |  50  |
 |   35 |   2 | GPIO1_A3 |   IN | 0 | 13 || 14 |   |      | GND(0V)  |     |      |
 |   36 |   3 | GPIO1_A4 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO1_C6 | 4   |  54  |
 |      |     |     3.3V |      |   | 17 || 18 | 0 | IN   | GPIO1_C7 | 5   |  55  |
 |      |     | UART4_TX |      |   | 19 || 20 |   |      | GND(0V)  |     |      |
 |      |     | UART4_RX |      |   | 21 || 22 | 0 | IN   | GPIO1_D0 | 6   |  56  |
 |      |     | SPI1_CLK |      |   | 23 || 24 |   |      | SPI1_CSn |     |      |
 |      |     |  GND(0V) |      |   | 25 || 26 |   | ALT  | GPIO4_C5 | 11  |  149 |
 |      |     | I2C2_SDA |      |   | 27 || 28 |   |      | I2C2_SCL |     |      |
 |      |     | I2S0_LRX |      |   | 29 || 30 |   |      | GND(0V)  |     |      |
 |      |     | I2S0_LTX |      |   | 31 || 32 |   |      | I2S_CLK  |     |      |
 |      |     | I2S0_SCL |      |   | 33 || 34 |   |      | GND(0V)  |     |      |
 |      |     | I2S0SDI0 |      |   | 35 || 36 |   |      | I2S0SDO0 |     |      |
 |      |     | I2S0I1O3 |      |   | 37 || 38 |   |      | I2S0I2O2 |     |      |
 |      |     |  GND(0V) |      |   | 39 || 40 |   |      | I2S0I3O1 |     |      |
 +------+-----+----------+------+---+----++----+---+------+----------+-----+------+

 

Let's try GPIO1_A4:

 

echo 36 > /sys/class/gpio/export
echo "out" >/sys/class/gpio/gpio36/direction
echo "1" > /sys/class/gpio/gpio36/value

 

And then I can measure 3v with a multimeter hooked to the physical pin 15.

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.