Burning LED with OrangePi C and Python

Weburn LEDs with GPIO, one of the first steps with OrangePi, one of the preferred development cards, as single card computers are very widespread and highly efficient in terms of use. If you have direct access to the card, you can go directly to the coding and library section, but if you cannot access the card from a physical screen, I recommend reading "Connecting to OrangePi" carefully. In addition, we make installations and adjustments for python and C language to work. But at the beginning, we will take a look at the connection to our card. Towards the bottom of the page, a description of the terms and some functions was added.

OrangePi Prep

Assuming we just got our card, I'll start our guide. To use our card, we first need one power cable, one SD-card with an operating system installed and one cable to provide an internet or data connection, for example; ethernet cable, wi-fi adapter, USB-TO-TTL cable. Due to my distance from the modem, I provided my connections with a Wi-Fi adapter, you can act according to your situation and your choice. Apart from these methods, you can connect your card directly to a screen, keyboard, and mouse. I used "Armbian" as the operating system on my card, and I recommend it to you in terms of compatibility and usage. Alternatively, you can use Raspian OSfor OrangePi.

Physical Status of the Card I Use


Connecting to OrangePi

As I mentioned above, I provided connections to my card via wi-fi adapter. For connection, we need to determine which IP address the card received by the modem or virtual modem, for this;

Don't be surprised by the different IP Addresses received by the Card I Used in Some Programs, it differed because I did it at different times.

By Checking Directly from the Card

To check through our card, we need access to the terminal. You can use the combination "CTRL+ALT+T" to open the terminal, or you can open it directly. When the terminal screen comes up, if we have a connection over wi-fi "iwconfig" if we have established a wired connection over ethernet, we write the command "ifconfig" and find out our IP address assigned by the modem on the incoming screen.


Through the Modem Interface

Many modems have an interface address of "", but this input address may vary depending on the model of your modem. To find the right address, you can read the label on the back of your modem, or you can also find it in the "Default Gateway" section in the connection settings of the device you are connecting to. In addition, the interface username and password will be required to log in, these two information usually come in as "admin" "admin", but it is also worth checking this. To solve the problem of some modems not being able to enter the interface, you can restart the modem or return directly to the factory months, but remember that as a result you will need to enter the information provided to you by the service provider.


By Scanning IP Distance from a Different Device

If you do not have the chance to get images from the modem interface or directly from our card, you can use this method. Any network scanning program will do the trick. In the meantime, I used software called net-scan to find the IP address my card received.


With PuTTY

PuTTYis an open source, simple interface software used to connect to your sunc/machine remotely or on the same network using the SSH/Telnet structure. Once we have identified the IP address of our card, we will provide our first connection via PuTTY. Make sure you typed the IP address correctly and used port 22 by default, otherwise you won't be able to connect.


If your connections and login information are correct, the screen that will meet you after the "Open" button is such an error message. You can continue this message as a security measure by saying "Yes" without problems. In order not to receive this error message in our later articles, we will cache "fingerprint", as well as establish direct links with "puttygen".


We will need to enter the login details of our card in the terminal that we come across through PuTTY. I log in as "root" because I use the root account and enter it with the password I set because I have already set the password.Although your password appears as a space when you type, don't worry! Be sure to type correctly when entering your password, which is containing Turkish keyboard and Turkish letters. You can log in with the user account you have specified, if you have not created any users, you can use the "root" account. Although it varies from version to version, in general the first root passwords; It comes in "root" , "toor" and "1234". However, if you are not aware of what you are doing, if you have logged into the root account, then it will be useful to create a new user. With the high access capacity of the Root account, you can cause problems and problems on your card that you do not know about.


After entering the password;

We have successfully established our connection with PuTTY.

We have successfully established our connection with PuTTY.

With Windows CMD (Command Prompt)

You can establish a direct SSH connection with the built-in SSH feature that comes with Windows. Parameters and information that we can use with the "SSH" command will appear. The code you need to use for the connection is; "ssh [email protected]_ip_adresi" appeared when I filled in the necessary places according to my own card, "ssh [email protected]".


As a result of our code sent with Enter, we will be greeted by the login screen. Since we have already specified the username, we have successfully made our attempt with the password that we have already set, which will only ask us to enter a password. In some card and operating systems, it may not directly create a user account and password, but it gives you the chance to create it on the first SSH connection.


Library Downloads and Updates

Libraries that appear almost everywhere, i.e. code groups, are necessary for GPIO operations in this project. I would like to point out that there are separate libraries for Python and C, whichever you want you can use. My suggestion is that you have and master both libraries. Note that you'll cover where Python isn't with Python, where C and C aren't.

sudo apt-get update && sudo apt-get

We update our card with this line.

sudo apt-get install git git-core

In this line, we get the "go" script that we will use frequently, which comes installed in most systems. In short, we will use it to pull data from GitHub.

C Library

For the OrangePi Mini Model:

go clone https://github.com/orangepi-xunlong/WiringOP -b orangepimini

For other OrangePi Models:

go clone https://github.com/orangepi-xunlong/WiringOP -b orangepi

After downloading library C, we move on to installation processes. We clear the path to the file that comes into the descending directory:

cd WiringOP

We authorize the Setup script:

chmod +x ./build

We are running the setup script:

sudo ./build

If we haven't made any mistakes so far, we're checking the pins. If you encounter any errors, please contact us in the comments section or by contact;

gpio readall


Our C Code

We can write our code in any writing module or we can use it ready- made, and I used nano for it.

nano blink.c

With this script, we created a file called "nano.c". We write our code on the command screen that comes up.

int main (void)
wiringPiSetup () ;
pinMode (0, OUTPUT) ;
for (;;)
digitalWrite (0, HIGH); delay (500);
digitalWrite (9, LOW) ; delay (500);
digitalWrite (0, HIGH); delay (500);
digitalWrite (9, LOW) ; delay (500);
return 0 ;

We save the window we typed with "CTRL+X" followed by "y". To compile our code;

gcc -Wall -o blink blinkk.c -lwiringPi -lpthread

To test;

sudo ./blink


We successfully compiled and executed our first code.

Python Library

Python; is a general purpose, object-oriented, easy-to-read and understand programming language. With OrangePi, the usage area is very wide. Using Python, create tasks, control Orange pi pins, create algorithms, and take actions. No matter how much you master the C language, you can't bypass Ptyhon when using OrangePi.

For Zero models;

sudo git clone https://github.com/nvl1109/orangepi_zero_gpio.git

For other models;

sudo git clone https://github.com/duxingkei33/orangepi_PC_gpio_pyH3.git

We're opening our way to the file;

cd orangepi_PC_gpio_pyH3

We are installing;

install sudo python setup.py

If this script does not work, try allowing it with CHMOD, the problem will most likely be solved. Python3 was also used in this code.

Python Code

from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port
Assign #gpio.
led = port. PA6
gpio.setcfg(led, gpio. OUTPUT)
while True:
gpio.output(led, gpio. HIGH)
gpio.output(led,gpio. LOW)

Circuit Diagram and GPIO Pins

GPIO Pins may vary depending on the card model you use, so be sure to check the documentation of your card, I shared the diagram and pin distribution for OrangePi PC below.

orangepi orangepi

Potential Errors

[email protected]:~/WiringOP/examples$ gcc -o blink blink.c -lwiringPi
usr/local/lib/libwiringPi.so: undefined reference to 'pthread_join'
usr/local/lib/libwiringPi.so: undefined reference to 'pthread_create'
usr/local/lib/libwiringPi.so: undefined reference to 'pthread_cancel'
collect2: error: ld returned 1 exit status

If you receive an error such as "gcc", try adding the "-lpthread" script to your compile code, or make sure you type it correctly.

Problems with Python are usually caused by installing the wrong version, and having the same and two different versions will cause confusion and conflicts. So it's best to stay in one version.

Terms and Page Dictionary

GCC: An open source, free compile script produced by Gnu C Compiler, based on many programs written in C and C++.

GPIO: General purpose input and output pins.

Virtual Modem: If you do not have a physical modem, you can connect your card directly to the computer via ethernet cable. Or you can connect by setting up a virtual wi-fi network, you can handle transactions smoothly under both conditions. If there is no Internet connection, you can't just download updates and required libraries.

Net-Scan: You can use any network scanning program. Be sure to download it from a free and reliable source.

Telnet: One of the TCP/IP protocols. We can translate it into Turkish as a communication network. It is generally not preferred for long distances because it communicates on a text-by-text basis without encryption. Today, it is used only on server farms on the same network. Uses 23 as the default port.

Root: The word "root", which we come across in many places, actually means that you have access to the root directory. That is, a user account with all the permissions.

SSH Connection: It is the protocol used for encrypted binding prepared like SSH Telnet. Uses port 22 by default. It is highly preferred due to the cryptic progression of communication and has become one of the most used communication prococos today. At first, it came out as an alternative to Telnet. It is a communication prototys that is used quite a lot now.