Power & Source of Big Ideas

WiringPI for NanoPI M1

Moderators: chensy, FATechsupport

Hi, please check my attempt to port WiringPI to NanoPI M1
https://github.com/wertyzp/WiringNP
I need someone to test GPIO IN/OUT functions and PWM
Please report any errors to github
Nice work!

I did checked all 16 wiringPi pins on the 2 row connector.
These are the 2x12 pins of NanoPi Neo (part of WiringNP-master/pins/pins.pdf):
Image

14 WiringPi pins worked fine, but WiringPi pins 2 and 3 did not work for me.
Since I had just soldered the male headers to my Nanopi Neo in the morning, I resoldered both pins.
Still no luck -- does WiringNP-master/examples/blink.c work for you when you change LED from 0 to 2 and 3?

Hermann.
Thanks for you contribution, I will check reported bug.
https://github.com/wertyzp/WiringNP
Check latest commit, fixed warnings and pins 2, 3
I did a fresh "git clone git://github.com/wertyzp/WiringNP".
As you can see below there are still some warnings left.
I tested pin 2 and 3, and both work fine now.

You can update Readme.md as well:
"Currently only NanoPi M1 board supported"

I tested on Nanopi Neo and all I tested works there.
(nanopi-neo-linux-rootfs-core-qte-sd4g-20160804.img.zip)

You seem to have edited wiringPi.c on a Windows computer, unlike the other files it has CRLF line endings:

Code: Select all

root@FriendlyARM:~/WiringNP/wiringPi# file * | grep CRLF 
wiringPi.c:     C source, ASCII text, with CRLF line terminators
root@FriendlyARM:~/WiringNP/wiringPi#


Hermann.

Code: Select all

root@FriendlyARM:~/WiringNP# sh ./build
./build: 4: ./build: [[: not found
wiringPi Build script
=====================


WiringPi Library
[UnInstall]
[Compile] wiringPi.c
wiringPi.c: In function 'digitalRead':
wiringPi.c:1475:13: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]
             read(sysFds [pin], &c, 1);
             ^
wiringPi.c: In function 'digitalWrite':
wiringPi.c:1533:21: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
                     write(sysFds [pin], "0\n", 2);
                     ^
wiringPi.c:1535:21: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
                     write(sysFds [pin], "1\n", 2);
                     ^
wiringPi.c: In function 'waitForInterrupt':
wiringPi.c:1756:5: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]
     (void) read(fd, &c, 1);
     ^
[Compile] wiringSerial.c
wiringSerial.c: In function 'serialPutchar':
wiringSerial.c:146:3: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
   write (fd, &c, 1) ;
   ^
wiringSerial.c: In function 'serialPuts':
wiringSerial.c:158:3: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
   write (fd, s, strlen (s)) ;
   ^
[Compile] wiringShift.c
[Compile] piHiPri.c
[Compile] piThread.c
[Compile] wiringPiSPI.c
[Compile] wiringPiI2C.c
[Compile] softPwm.c
[Compile] softTone.c
[Compile] softServo.c
[Compile] mcp23008.c
[Compile] mcp23016.c
[Compile] mcp23017.c
[Compile] mcp23s08.c
[Compile] mcp23s17.c
[Compile] sr595.c
[Compile] pcf8574.c
[Compile] pcf8591.c
pcf8591.c: In function 'myAnalogWrite':
pcf8591.c:44:3: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
   write (node->fd, b, 2) ;
   ^
[Compile] mcp3002.c
[Compile] mcp3004.c
[Compile] mcp4802.c
[Compile] mcp3422.c
mcp3422.c: In function 'myAnalogRead':
mcp3422.c:62:7: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]
       read (node->fd, buffer, 4) ;
       ^
mcp3422.c:68:7: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]
       read (node->fd, buffer, 3) ;
       ^
mcp3422.c:74:7: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]
       read (node->fd, buffer, 3) ;
       ^
mcp3422.c:80:7: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]
       read (node->fd, buffer, 3) ;
       ^
[Compile] max31855.c
[Compile] max5322.c
[Compile] sn3218.c
[Compile] drcSerial.c
[Link (Dynamic)]
[Install Headers]
[Install Dynamic Lib]

WiringPi Devices Library
[UnInstall]
[Compile] ds1302.c
[Compile] maxdetect.c
[Compile] piNes.c
[Compile] gertboard.c
[Compile] piFace.c
[Compile] lcd128x64.c
[Compile] lcd.c
[Compile] piGlow.c
[Link (Dynamic)]
[Install Headers]
[Install Dynamic Lib]

GPIO Utility
[Compile] gpio.c
gpio.c: In function 'doLoad':
gpio.c:228:6: warning: ignoring return value of 'system', declared with attribute warn_unused_result [-Wunused-result]
      system (cmd) ;
      ^
gpio.c:235:6: warning: ignoring return value of 'system', declared with attribute warn_unused_result [-Wunused-result]
      system (cmd) ;
      ^
gpio.c:274:7: warning: ignoring return value of 'system', declared with attribute warn_unused_result [-Wunused-result]
       system (cmd) ;
       ^
gpio.c:280:7: warning: ignoring return value of 'system', declared with attribute warn_unused_result [-Wunused-result]
       system (cmd) ;
       ^
[Compile] extensions.c
[Compile] readall.c
[Compile] pins.c
[Link]
[Install]

All Done.

NOTE: To compile programs with wiringNP, you need to add:
    -lwiringPi
  to your compile line(s).

root@FriendlyARM:~/WiringNP#
Looks like your compiler very strict, mine doesn't display those warnings
Also I want to notify everyone that pwm1 is not present in allwinner h3 chip, so pwm1 on pin 1 wouldn't work
Friendlyarm, please, update nanopi m1 and neo wiki to reflect that GPIOA6 pin cannot do pwm1. Check datasheet v1.1+:
http://linux-sunxi.org/images/4/4b/Allw ... t_V1.2.pdf
I plan to use debug port pwm0 pin (A5) as pwm pin in future
Hi,

so currently no PWM in your Nanopi WiringPI lib?

> Looks like your compiler very strict, mine doesn't display those warnings
>
Do you run debian?
I do run nanopi-neo-linux-rootfs-core-qte-sd4g-20160804.img.zip on Neo.
Once I did insert that Neo SD card and booted M1 from that without problems.
That way you can get the Neo compiler on M1 without having to buy a Neo.

Hermann.
HermannSW wrote:
Hi,

so currently no PWM in your Nanopi WiringPI lib?

> Looks like your compiler very strict, mine doesn't display those warnings
>
Do you run debian?
I do run nanopi-neo-linux-rootfs-core-qte-sd4g-20160804.img.zip on Neo.
Once I did insert that Neo SD card and booted M1 from that without problems.
That way you can get the Neo compiler on M1 without having to buy a Neo.

Hermann.

I run armbian
There's PWM support on UART_RX0 port (GPIOA5, debug port). I'm not sure why, but this pin gives 2.5v output in input state so please use it only for PWM. Also, currently it is not possible to return it back to UART mode once it was switched to pwm1
Debug port also present on nanopi neo.
I also plan to rename pins to show proper names and modes

If you have any suggestions on library improvement let me know
Hi,

Firstly let me say I am quite new to linux and usually work my way through things by following other examples both on the web and through forums.

I have previously used a rapsberry pi with python and RPi.GPIO to read from 4 switches connected to GPIO on the pi. I would like to connect 4 switches to the NanoPi - if possible using pin 39 as a common ground and using pins 31,33,35 and 37 to connect the other side of the switch.

I have managed to download and install your version of WiringPI, but now I am not sure of how to make it read those switches. I do not want to connect any resistors, just straight switches and I want each switch to call a shell script when pressed.

Can you help me?

Thanks in advance
you can do it using gpio command and bash script. To do it without resistor it will require pull-up feature to be enabled on gpio port. Unfortunately, currently enabled pull-up on gpio pin feature is not implemented. I will try to implement it soon and will be able to provide example how you can do it
Hi weryzp.

Any news on the pull up for gpio?

Thanks in advance for your work
@wertyzp
Some more work for you WiringPi Neo port.
These are pins and pin names from Neo product page:
Image

WiringPi lib contains "gpio" command.

For the "readall" option you would need to display 24/40 pns for Neo/M1 in first table.
For Neo a 2nd table should display the single row pins,
Advanced: depending on Neo version 3rd table with 5 separate audio pins should be displayed.
And the pin names are different to Raspberry Pi and should be corrected.

Hermann.

Code: Select all

root@FriendlyARM:~# WiringNP/gpio/gpio readall
 +-----+-----+----------+------+---+--NanoPI M1---+---+------+---------+-----+--+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 |     |     |     3.3v |      |   |  1 || 2  |   |      | 5v       |     |     |
 |   2 |   8 |    SDA.0 | ALT5 | 0 |  3 || 4  |   |      | 5V       |     |     |
 |   3 |   9 |    SCL.0 | ALT5 | 0 |  5 || 6  |   |      | 0v       |     |     |
 |   4 |   7 |   GPIO.7 |  OUT | 1 |  7 || 8  | 0 | ALT5 | TxD3     | 15  | 14  |
 |     |     |       0v |      |   |  9 || 10 | 0 | ALT5 | RxD3     | 16  | 15  |
 |  17 |   0 |     RxD2 | ALT5 | 0 | 11 || 12 | 0 | ALT3 | GPIO.1   | 1   | 18  |
 |  27 |   2 |     TxD2 | ALT3 | 0 | 13 || 14 |   |      | 0v       |     |     |
 |  22 |   3 |     CTS2 | ALT3 | 0 | 15 || 16 | 0 | ALT3 | GPIO.4   | 4   | 23  |
 |     |     |     3.3v |      |   | 17 || 18 | 0 | ALT3 | GPIO.5   | 5   | 24  |
 |  10 |  12 |     MOSI | ALT4 | 0 | 19 || 20 |   |      | 0v       |     |     |
 |   9 |  13 |     MISO | ALT4 | 0 | 21 || 22 | 0 | ALT5 | RTS2     | 6   | 25  |
 |  11 |  14 |     SCLK | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE0      | 10  | 8   |
 |     |     |       0v |      |   | 25 || 26 | 0 | ALT3 | GPIO.11  | 11  | 7   |
 |   0 |  30 |    SDA.1 | ALT4 | 0 | 27 || 28 | 0 | ALT4 | SCL.1    | 31  | 1   |
 |   5 |  21 |  GPIO.21 | ALT3 | 0 | 29 || 30 |   |      | 0v       |     |     |
 |   6 |  22 |  GPIO.22 | ALT3 | 0 | 31 || 32 | 0 | ALT3 | RTS1     | 26  | 12  |
 |  13 |  23 |  GPIO.23 | ALT3 | 0 | 33 || 34 |   |      | 0v       |     |     |
 |  19 |  24 |  GPIO.24 | ALT4 | 0 | 35 || 36 | 0 | ALT3 | CTS1     | 27  | 16  |
 |  26 |  25 |  GPIO.25 | ALT3 | 0 | 37 || 38 | 0 | ALT3 | TxD1     | 28  | 20  |
 |     |     |       0v |      |   | 39 || 40 | 0 | ALT4 | RxD1     | 29  | 21  |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+--NanoPI M1---+------+----------+-----+-----+
root@FriendlyARM:~#
AntB wrote:
Hi weryzp.

Any news on the pull up for gpio?

Thanks in advance for your work


Have not worked on this yet, sorry

@HermannSW
Thanks for the info. If you can find a way to distinguish nanopi m1 vs nano neo I will add autodetection
Hi, wertyzp!
How can I change the frequency of the hardware PWM? Now PWM operates at a frequency of 195 Hertz. I need 100KHz.
Hi,

wertyzp wrote:
AntB wrote:
Thanks for the info. If you can find a way to distinguish nanopi m1 vs nano neo I will add autodetection


I do not run Armbian like you, but "uname -n" allows distinction for me, this is for Nanopi Neo:

Code: Select all

root@FriendlyARM:~# uname -n
FriendlyARM
root@FriendlyARM:~#


And this is for Nanopi M1:

Code: Select all

root@NanoPi-M1:~# uname -n
NanoPi-M1
root@NanoPi-M1:~#


uname() function can be used:
/usr/include/arm-linux-gnueabihf/sys/utsname.h:81:extern int uname (struct utsname *__name) __THROW;

Hermann.

Who is online

In total there are 8 users online :: 0 registered, 0 hidden and 8 guests (based on users active over the past 5 minutes)
Most users ever online was 2865 on Sun Nov 10, 2019 5:27 am

Users browsing this forum: No registered users and 8 guests