[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

[pi8] GPIO inputs with rpi-gpio.js

It is highly recommended that you have done blinking a LED with rpi-gpio sample before continue.
Please take a look at GPIO(General Purpose Input/Output ports).
See also GPIO pinout to explore different pin interfaces.

This sample uses a simple push button to simulate an input. In addition to your Raspberry Pi running Raspbian & S8 and rpi-gpio.js loaded, what you will need is:

BreadBoardUploaded Image: breadboard.png
A push button switch x1Uploaded Image: switchbutton-01.png
1KOhms resistor x1Uploaded Image: 1KOhms.jpg
10KOhms resistor x1Uploaded Image: 10KOhms.jpg
Male-Female jumper wiresUploaded Image: jWires.jpg

J8 Expansion Header

Check the GPIO pins layout on your pi device.

Install rpi-gpio.js

Check for rpi-gpio.js documentation and follow install instructions
$ sudo npm install rpi-gpio


Making connections

In order to try a minimal sample we need to do the connections as follow:

Uploaded Image: gpio input.png

Pin 1 sends 3.3v and the push button closes the circuit routing to pin 16. The resistors are needed for protecting GPIO from a potencial sending charge from pin 16 (acidentally you can set up your code for output through pin 16).

Listening for a pin change with S8

  1. Start your S8 system server executing
    $ sudo node n8.snapshot.js
    take note of the server address e.g. SystemServer running at http://192.168.1.???:8088
  2. connect from U8 tools image to S8 system running in your Raspberry Pi.
  3. Load rpi-gpio framework to your system (using the remote/connected workspace) doing a #fileIn.
  4. Finally copy this few lines to your remote workspace. Just select/paint all this code and click on #doIt button
    | gpio |
    gpio := RPI gpio.
    gpio setMode: gpio modeRPI.
    gpio on: #change do: [:channel :value|
    	self print:'Channel ', channel , ' value is now ' , value
    ].
    gpio 
    	setup: 16
    	direction: gpio dirIn
    	edge: gpio edgeBoth
    	with: [].
    What you'll see on standard output (console) is the text: 'Channel 16 value is now (?)' whenever you push the button. Congratulations!!


References