Giter Club home page Giter Club logo

chip_io_c's Introduction

CHIP_IO Arduino Style for C

A CHIP IO library for C: IO+PWM

Arduino Style GPIO control for C.H.I.P and C.H.I.P Pro

Installation and first build

Attach an LED to XIO-P2 with a resistor to run the blink example::

sudo apt-get install git build-essential -y
git clone https://github.com/Groguard/CHIP_IO.git
cd CHIP_IO/examples/
arm-linux-gnueabihf-gcc -pthread blink.c ../chip_io_c.c ../source/event_gpio.c ../source/common.c -o blink -static
sudo ./blink

Examples

GPIO Setup

#include "chip_io_c.h"
pinMode("CSID0", OUTPUT);

You can also refer to the pin number:

pinMode("U14_31", OUTPUT);

You can also refer to the bin based upon its alternate name:

pinMode("GPIO1", INPUT);

Debug can be enabled/disabled by the following command:

// Enable Debug
toggle_debug();

GPIO Output

Setup the pin for output, and write HIGH or LOW. Or you can use 1 or 0:

#include "chip_io_c.h"
pinMode("CSID0", OUTPUT);
digitalWrite("CSID0", HIGH);

GPIO Input

Inputs work similarly to outputs.:

#include "chip_io_c.h"
pinMode("CSID0", INPUT);

Other options when setting up pins:

// Specify pull up/pull down settings on a pin
pinMode("CSID0", INPUT_PULLUP);
pinMode("CSID0", INPUT_PULLDOWN);

Pull Up/Down values are only for pins that are provided by the R8, the XIO are not capable of this. The allowable values are: INPUT_PULLOFF, INPUT_PULLUP, and INPUT_PULLDOWN.

Polling inputs:

int state = digitalRead("CSID0");
if(state)
    printf("HIGH\n");
else
    printf("LOW\n");

GPIO Cleanup

To clean up the GPIO when done, do the following:

// Clean up a single pin (keeping everything else intact)
cleanup("XIO-P0");

// Clean up all 
cleanup("ALL");

PWM

Hardware PWM requires a DTB Overlay loaded on the CHIP to allow the kernel to know there is a PWM device available to use. Works by defualt on CHIPPro

//startPwm(channel, duty, polarity);

#inlcude "chip_io_c_pwm.h"
startPwm("PWM0", 50, 0);
//duty values are valid 0 (off) to 100 (on)
setPwmDutyCycle("PWM0", 20.5);
setPwmFrequency("PWM0", 50);

// to Stop PWM
stopPwm("PWM0");
cleanupPwm("PWM0");

chip_io_c's People

Contributors

groguard 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.