Coder Social home page Coder Social logo

gpio's Introduction

Summary

This project is a GPIO controller for the Odroid-N2. It also features an implementation of the Dallas 1-Wire bus.

It can be used as a native library for Android. There's a sample project which displays the temperatures measured by digital thermometers to demonstrate how to use the controller.

The goal of this project was to build an easy-to-use interface for Odroid-N2 GPIO in an Android app (Java/Kotlin).

Usage

GPIO

Initialize the GPIO by calling onResume:

// In Activity.onResume

GPIO.getInstance().onResume();

Configure one pin (use its WiringPi number):

GPIO gpio = GPIO.getInstance();
gpio.export(0);

// or gpio.setMode(0, GPIO.MODE_OUTPUT);
gpio.setMode(0, GPIO.MODE_INPUT);

Read its value:

gpio.getValue(0);

Write a new value (if configured as output):

// or gpio.setValue(0, GPIO.VALUE_HIGH);
gpio.setValue(0, GPIO.VALUE_LOW);

Terminate the GPIO by calling onPause:

// In Activity.onPause

GPIO gpio = GPIO.getInstance();
gpio.unexportAll();
gpio.onPause();

1-Wire

Initialize a 1-Wire bus on any pin:

OneWire oneWire = new OneWire();
oneWire.configure(GPIO.getInstance(), 0);

Once done with the bus, terminate:

oneWire.destroy();

DS18S20/DS18B20 thermometers

Search for thermometers over a 1-Wire bus:

// OneWire oneWire
List<Thermometer> thermometers = Thermometer.listAll(oneWire);

Read temperatures measured by the connected thermometers:

Thermometer.convert(oneWire, thermometers);

for (Thermometer thermometer : thermometers)
  Log.d(TAG, "Temperature of #" + thermometer.getRom() + " is " + thermometer.getTemperature());

Once done with the thermometers, terminate:

Thermometer.destroyAll(thermometers);

Serial

Initialize the Serial bus by calling configure:

// In Activity.onResume

Serial serial = new Serial(Serial.DEVICE_PORT1_PATH);
serial.configure(9600, Serial.DataBits.Height, Serial.Parity.None, Serial.StopBits.One);

Send a message via the configured bus:

serial.getOutputStream().write("Hello world".getBytes());

Receive a message from the configured bus:

byte[] buffer = new byte[256];
int size = serial.getInputStream().read(buffer);
String message = new String(buffer, 0, size);

Terminate the Serial bus:

// In Activity.onPause
serial.destroy();

Roadmap

  • GPIO: handle signals on falling/rising edge of a GPIO pin.
  • UART: add an implementation of serial communication using bit banging on any GPIO rx/tx pins.

Wiki

Get more info on Hardkernel Odroid-N2 wiki.

gpio's People

Contributors

cdoapps avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.