Power & Source of Big Ideas

NanoPi2 GPIO Complete Programming Guide.

Moderators: chensy, FATechsupport

Hey everyone! :D

(I don't really know if this is the correct place to put this post so I'd be nice from you to tell me if I'm wrong...)

I got a NanoPi2 recently and I've got the purpose to learn how to use it at all.
The problem is that I'm terribly naive about this kind of boards. This is the very first time I use one of this. I only have experience with microcontrollers and when I knew about this kind of boards and what they can do, I wanted to try an experiment with them, to learn something new.

So, I was wondering if there is a "for dummies" guide for this board, for me to begin to use it. Everything I've seen here in the forum and in the wiki requires kind of a hard previous knowledge, and I only have some experience in C programming and even basic experience in Linux.

My purpose is to use this board with IoT protects and applications using the GPIO, being specific.

I hope anyone can help me and others like me who want to learn about this boards.


Abel Rodriguez.

One of the first projects beginners do on a microcontroller is blink an LED. Why not try the tutorial http://wiki.friendlyarm.com/wiki/index.php/Matrix_-_LED? It is quite a comprehensive guide and the amount of information on other peripheral devices seems quite extensive.

If you haven't got their LED module make up your own. I don't see a schematic, but from the pictures it looks like a transistor driving an LED in it's collector lead. A couple of resistors in the base circuit. My guess .... 1K to 10K in series with the base and 10K to 100K from base to ground. Emitter to ground and apply your GPIO output to the series base resistor. Presto!

Driving a GPIO port is a lot more difficult on these platforms than on a microcontroller. Just be thankful that you don't have to write a kernel driver to blink your LED!

Next, learning to drive SPI devices will help you to interface to many external modules. Then I2C devices and you should be well on the way.

First of all, thanks for your reply davef :D

I agree with you about blinking the LED. Actually, that's where I started a few days ago.
Fortunately, I also got the matrix kit, so I have some things to try the board.

I've been reading a lot the NanoPi2 in the wiki but I don't think I'm getting everything. I was planning to make all the programs in Windows 7 with Eclipse in C, use a Cross Compiler and then copy the program to a microSD card to insert it on the board.
I used a sample program they have in the repository to try the blinking LED but here is where I got lost.
I read I need to install a toolchain in Eclipse to do the Cross Compile, but I'm not sure which one to use or even how to use it.
Also, I don't know what kind of file (extension) I'll get when I do the Cross Compile, or where to copy it, in the microSD card, when I already have it.

That's the part where I got totally lost. I know that in the wiki it says that you should use a 64bit Linux environment, such as Ubuntu, to program, but it doesn't also give pretty much info about what program or how to do so.

I wish if I'm not asking for much :S

Finally, you're rigth, I'll have to manage with serial communication, I2C an so, but before that I'd like to understand very well the very basics of the board.

Thanks for your explanation, you're a pretty good teacher I think! :D

The toolchain is available on GoogleDrive.

Once you get Eclipse to point to your toolchain and get a successful cross-compilation you want to check your generated file with <readelf -a> and look at the last 5-10 lines. You may have to download elfutils or ?

File extensions: I answered this question on the other forum.

After you have the generated file copy it to your SD card in the appropriate place as suggested in my posting on the other forum.

Now, I don't think I have ever made or run one of my own application. Qt apps I have and for that you have to follow the program name with <-qws> but for your own app just try <my_app> or <./my_app> and see what happens.

I've downloaded the toolchain from Google Drive, but I'm not quite sure how to install it to Eclipse. I read that if I put the PATH in the environment variables of the toolchain folder it'll work, but I don't know how to check if it's already installed.

Here I have another question, I think there are kind of some toolchains in Google Drive, how do I know which one to use?

I'm using one of the example programs that FriendlyARM have, just to be sure it's not a code error.

As you can see, my main problem here is cross-compilation. I need some basic guide with this part first.

The toolchain is installed where ever the tutorial asks you to put it (/opt/FriendlyARM/toolchain/) and then in Eclipse you will tell it where the toolchain is located.

The NanoPi2 Wiki tutorial tells you which toolchain you want. (arm-cortexa9-linux-gnueabihf-4.9.3.tar.xz)

You are aware that you have to use a 64 bit host for the NanoPi2? Also, you need to apt-get install some tools on your host. Check the latest NanoPi2 threads on the old forum for the list.

I would suggest that you start from "Setup Development Environment" and just do it on the command line. Then setup Eclipse to do it.

Okay, I've been working on Ubuntu14.04 64bits, setting up the Developing Environment, as you suggested, from the wiki.

Everything went fine until I wanted to test the "u-boot.bin" that was generated from the compilation of U-Boot. I installed "android-tools-fastboot", then I connected the NanoPi2 to the host via serial cable (I used the USB cable to power it), but then the tutorial says: "Press the enter key within two seconds right after you power on your NanoPi 2 and you will enter uboot's command line mode".

Do I have to see something appearing in the host terminal when I connect the NanoPi2 via serial cable? Or do I have to do this directly on the NanoPi2, with the LCD connected to it? I think this isn't clear enough. And I also need help in steps 3 and 4.

Thanks a lot for your help again,

I haven't tried fastboot yet. But what normally happens is .... when you are connected to the target via the UART debug cable (PSU-ONECOM) and running a terminal program on the host , ie mincom ... as soon as you put power on the NanoPi2 you will see a few lines of script then it pauses for a few seconds, which gives you the opportunity to stop the boot process and be able to do things like:
- printenv
- setenv
- saveenv

ie, change boot parameters.

I noticed some of the recent images show the boot process on the LCD.

I'll go away and read step 3 and 4
Do you mean 6.3 and 6.4?
Does the nanoPi2 & NanoPC-T2 have pull[up/down]s already like the raspberrypi? They don't require resistors for this.

It would be swell if we could have a library like wiringpi as well.

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 102 on Mon Oct 08, 2018 12:42 pm

Users browsing this forum: No registered users and 1 guest