Orange Pi Zero – LED blinking, temperature measurement (I2C) and sending data through SPI, in Pythonu

In today article about Orange Pi Zero I want to show you how to blink of LED, measure the temperature by AD7415 sensor, which communicates through I2C and at the end we send some data to NRF24L01 through SPI. I have to write you, at the beginning, that NRF24L01 doesn’t work, but Orange Pi Zero works fine by analyzer. The codes are written in pythonu.

Another articles about Orange Pi Zero:
Orange Pi Zero – about it and first boot
Orange Pi Zero – power consumption, thermal imaging camera, benchmark
Orange Pi Zero – speedtest of WiFi, ethernet and USB (armbian)
Orange Pi Zero – other informations and expansion board
Orange Pi Zero – LED blinking, temperature measurement (I2C) and sending data through SPI, in Pythonu

The armbian is installed in Orange Pi Zero. In armbian is enabled I2C bus. So, you can only use it, but at the start we write code for blinking of LED.

So, we download project from git, that’s python library for controling of peripherals. It is used for Allwinner H3, nevertheless it looks like that these peripherals are the same for Allwinner H2+.

The project is used for Olimex single-board computer.

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

cd ./orangepi_PC_gpio_pyH3

sudo python setup.py install

If you see this error: command ‘arm-linux-gnueabihf-gcc’ failed with exit status 1 install python3-dev
sudo apt-get install python3-dev

So, everything should be prepared.
Here is python script for blinking od LED (PA10)

Run the script
sudo python .Link_To_LED_PA10.py

So, it’s done. By easy change you can read some GPIO and then run some other script for everything.

We measure the temperature by AD7415.

The temperature sensor is connected on I2C-1, so
I2C1_SCK PA18

I2C1_SDA PA19

Of course you can use i2c-tools, or download github python library for Orange Pi with Allwinner H3 (Alwinner H2+) procesor.

Also we use https://github.com/duxingkei33/orangepi_PC_gpio_pyH3

(git clone https://github.com/duxingkei33/orangepi_PC_gpio_pyH3
cd ./orangepi_PC_gpio_pyH3
python setup.py install )

The demonstration will be usually with AD7415 temperature sensor.
Python script naleznete zde.

The sensor is connecter to I2C-1, on schematics is labled like TWI1.
VDD – 3.3V

GND – GND

TWI1-SCK (PA18) – CLK (or SCK)

TWI1 – SDA (PA19) – SDA

The address of AD7415 is 0x4A and the first 8 bits is read from 0x00 address.

Sending data to NRF24L01 (SPI)

At the start I wrote that NRF24L01 doesn’t work.

The proccess of communication looks well by the analyzator.

I don’t know yet why. If the problem is in peripheral or controling of CE and CSN pin.

I used SPI-1.
SPI1_CLK PA14

SPI1_MISO PA16

SPI1_MOSI PA15

If you use armbian, you have to edit script.bin in /boot/.

The BIN file is not easy to change. At first we have to download sunxi-tools.

So, install libusb
sudo apt-get install libusb-1.0-0-dev pkg_config

The step-by-step tutorial is on homepage of sunxi-tools
http://linux-sunxi.org/Sunxi-tools

After successful installing we can edit script.bin. I recommend, back up the original script.
cp /boot/script.bin /boot/script_BackUp.bin

The edited fex with enabled SPI we get from
https://github.com/igorpecovnik/lib/blob/master/config/fex/orangepizero.fex

Orangepizero.fex we change to script.bin.
cd /boot/

sudo /LinkToSunxi-tools/fex2bin orangepizero.fex script.bin

And now, SPI should work.

Available are two python libraries.

The first python library is the same like for controling of GPIO and I2C.
https://github.com/duxingkei33/orangepi_PC_gpio_pyH3

My python script find here. The script sets NRF24L01 like transmitter with default settings of channel and address. Data is “abcdefgh”.

The second python library is SPI-Py.

Do this:
git clone https://github.com/lthiery/SPI-Py

cd ./SPI-Py

If you want to use SPI1 instead of SPI0, edit this file spi.c, line 37 from static const char *device = “/dev/spidev0.0”; to static const char *device = “/dev/spidev1.0”;

Run the script:
sudo python setup.py install

Downloaded package contains test-nRF.py file, which reads all registers from NRF24L01.

Here is my script. It does the same like the first script. It sets NRF24L01 as transmitter and sends “abcdefgh” data with default channel and default address.

If you find any mistakes in script or NRF24L01 with Orange Pi Zero will be work, let me know. Thanks.

Share the article:
Show your
Maker soul!
Buy a T-Shirt
Coffee for Chiptron
Give a boost to the next article

Related Articles

Well, here is another article about Orange Pi Zero. I would like to write these articles similar like for CHIP computer. So, in this article I write something about power consumption by Orange Pi Zero, what is temperature of Orange…

Maybe you heard about Orange Pi. The cheaper clone of Raspberry Pi, but do you know Orange Pi Zero? This version is no such “cut down” like Raspberry Pi Zero. Another articles about Orange Pi Zero: Orange Pi Zero -…

This Orange Pi Zero article will be about how to run WiFi (after boot) for OS armbian. What speed of WiFi and ethernet we can expect. I used speedtest for WiFi and ethernet. USB speed was measured for one big…

This article is short and brief. It is a few weeks after release Orange Pi Zero and so we can find other important informations about it. I show you one expansion board (shield). Another articles about Orange Pi Zero: Orange…

Shenzhen Xunlong is comming with a new version of ZERO board. Instead of Orange Pi Zero, OrangePi Zero Plus 2 a Orange Pi Zero Plus 2 H5 now we have another choice – Orange Pi Zero Plus. Shenzhen Xunlong continues…