Using Modules with Orange Pi

08/20/18

Categories: ComputersTags: Orange Pi

~/contents

Shenzhen Xunlong sells Orange Pi-branded modules, however, you can use a variety of generic arduino modules with these SBCs. This is a collection of code and wiring for basic sensors. Those new to modules may find it useful.

DHT22: Temperature and Humidity

This is an inexpensive sensor that is apparently more accurate than its counterpart, the DHT11. My sensor has 3 headers labelled + (power), - (ground), and OUT (data) respectively, output is naturally Celsius. I had no issues connecting this sensor to 3.3V, GND, and PA06.

There is a Python library for the DHT22/DHT11, that utilizes our old friend, the pyA20 library. An example script is included in the repo, see my code below as well as at Sensor de temperatura y humedad con Python.

from pyA20.gpio import gpio
from pyA20.gpio import port
import dht
import time

DHT22_PIN = port.PA6
gpio.init()
DHT22_instance = dht.DHT22(DHT22_PIN)

def convert_temp(celsius):
    return((celsius*1.8)+32)

def DHT22_print(result):
    if result.is_valid():
        fahrenheit_temp = convert_temp(result.temperature)
        print('Temperature: {}, Humidity: {}'.format(fahrenheit_temp, result.humidity))
    else:
        DHT22_read()

def DHT22_read():
    result = DHT22_instance.read()
    DHT22_print(result)

while True:
    DHT22_read()
    time.sleep (1)

HCSR501: Passive Infared Motion Sensor

This is an inexpensive little motion detector module. My sensor has 3 headers labelled VCC (power), GND, and OUT. The VCC will need to be connected to 5V. This module returns a 0 or 1 if it detects something.

from pyA20.gpio import gpio
from pyA20.gpio import port
import time
import datetime

PIN = port.PA6
gpio.init()
gpio.setcfg(PIN, gpio.INPUT)

while True:
    if gpio.input(PIN):
       print ("Detected something at {}.".format(datetime.datetime.now()))
    time.sleep (1)

I/O Expander

These expander modules are for expanding the I2C bus. The OP branded module uses PCF8574AT, which is an 8-bit I/O expander, and provides 9 additional pins plus 3 sets of GND/A0/VCC. I became interested in this after reading about it on Scargill’s blog. I was most interested in figuring out how the device could be used. Datasheet.

GND - GND VCC - 3.3V SDA - SDL 5 SCL - SCA 3

See my I2C/SPI post for more info on setting up I2C. If it’s working i2cdetect will return:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- 38 -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Until I explore this further, here are additional references:

LM393: Light Level Sensor (3-pin)

This module has a photosensitive cell on the end and two LEDS for power and data respectively. The data LED is active when light is detected. It has a blue potentiometer which can be be turned clockwise to increase sensitivity and range.

The 4-pin version is capable of analog output, and appears to be able to provide direction and intensity of light. The 3-pin version that I have functions more as a switch, and returns a 0 when light is detected with the below code.

VCC - 3.3V GND - GND VO - PA6

from pyA20.gpio import gpio
from pyA20.gpio import port
import time

PIN = port.PA6
gpio.init()
gpio.setcfg(PIN, gpio.INPUT)

while True:
    if gpio.input(PIN):
        print(gpio.input(PIN))
        time.sleep (1)

Orange-Pi Branded 0.96 OLED 12864

Here’s the datasheet in English. Have fun. The 0.96" Orange Pi branded OLED is a 7-pin module. The manufacturer indicates this is a I2C device. Prior to getting their datasheet the only information I could find on the 12864 in English suggested there are two versions, I2C and a 7-pin SPI, so I found this 7-pin I2C a bit confusing. There is no resistor information on the back. The manufacturer provides a SSD1306 library, which does have a demo. I could not get either of my boards to detect it and I tried both I2C and SPI and multiple pin variations. Others may have luck with this particular OLED but I either fried my module (likely!) or it was dead to begin with. Personally, I would recommend passing on this one for a SSD1306 (clearly marked as such on the pbc) with 4 pins and I2C/SPI info on the back. The branded board is more expensive than most other OLED modules and offers no apparent advantage. Certainly it was not easier to use.