FAQ | Contact Us  |  Register  |  Login


UC Davis Center for Integrated Computing and STEM Education (C-STEM) --- Research and Outreach
Home > C-STEMbian > Ch WiringPi Package

Ch WiringPi Package

Ch WiringPi Package is Ch binding to WiringPi, a pin based GPIO access library written in C for the BCM2835 used in  Raspberry Pi. All C/C++ programs using WiringPi related C functions can readily run in Ch interpretively without compilation. Furthermore, the WiringPi utility program gpio can be conveniently used for scripting inside  Ch programs to control GPIO.

The traditional software development method in Raspberry Pi using WiringPi through gcc, Makefile, a text editor without debugging capability through a lengthy compile/link/execute/debug cycle is cumbersome, especially for beginners. Ch WiringPi makes learning electronics using Raspberry Pi simple, easy, and fun with its user-friendly ChIDE,  scripting, debugging, and plotting capabilities. It breaks the barrier and allows anyone to join the Maker Revolution  with coding in Raspberry Pi, Pi Zero, and Pi Zero W.

 

Open Source Package
Ch WiringPi Package is included in C-STEM Studio for Raspberry Pi. However, you can download the open source code for Ch WiringPi Package below:

 

Application Examples
The following three programs demonstrate the simplicity of Ch WiringPi. Each program accomplishes the same thing — set pin 0 as an output, then repeatedly set the pin high, delay for 500 ms, set the pin low, delay 500 ms using a while-loop. The first program blink.c is a C program, which can be compiled using gcc or run in Ch directly. The second program blink2.ch is a Ch program.

Ch is a very high-level language (VHLL) for script computing. The third program blink3.ch uses the utility program gpio in a Ch script program, which can be invoked like bash or csh scripts.

These sample programs can be found in the folder /usr/local/ch/package/chwiringPi/demos/ in C-STEMbian.

This introductory video shows how these three programs using Ch WiringPi can be used to control GPIO.


/* File: blink.c */
#include <wiringPi.h>

int main() {
   wiringPiSetupGpio();
   pinMode(4, OUTPUT);
   while(1) {
      digitalWrite(4, HIGH); 
      delay(500);
      digitalWrite(4, LOW); 
      delay(500);
   }
   return 0 ;
}

 

/* File: blink2.ch */
#include <wiringPi.h>

wiringPiSetupGpio();
pinMode(4, OUTPUT);
while(1) {
    digitalWrite(4, HIGH);
    delay(500);
    digitalWrite(4, LOW); 
    delay(500);
}

 

#!/bin/ch
/* File: blink3.ch*/

gpio -g mode 4 out
while(1) {
  gpio -g write 4 1
  delay(500);
  gpio -g write 4 0
  delay(500);
}