Skip to content

Commit 02c0467

Browse files
Bug fix in the iopi library
Fixed a bug in the IO Pi library where the library failed when working with several IO Pi boards at the same time.
1 parent dd4de43 commit 02c0467

File tree

2 files changed

+166
-86
lines changed

2 files changed

+166
-86
lines changed

examples/iopi/iopiread2boards.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//================================================
2+
// ABElectronics IO Pi Pin Read demo 2
3+
// Version 1.0 Created 20/01/2016
4+
//
5+
// Requires rpio to be installed, install with: npm install rpio
6+
// run with: sudo node iopiread2boards.js
7+
// ================================================
8+
9+
// This example reads the first 8 pins from both busses on two IO Pi boards. The
10+
// internal pull- up resistors are enabled so each pin will read as 1 unless
11+
// the pin is connected to ground.
12+
13+
// Initialise the IOPi devices using the default addresses for board 1 and addresses 0x22 and 0x23 for board 2.
14+
// You will need to change the addresses if you have changed the jumpers on the IO Pi
15+
16+
var iopi = require('../../lib/iopi/iopi');
17+
18+
var bus1 = new IoPi(0x20);
19+
var bus2 = new IoPi(0x21);
20+
var bus3 = new IoPi(0x22);
21+
var bus4 = new IoPi(0x23);
22+
23+
// We will read the inputs 1 to 8 from each bus so set port 0 to be inputs and
24+
// enable the internal pull-up resistors
25+
26+
bus1.setPortDirection(0, 0xFF);
27+
bus1.setPortPullups(0, 0xFF);
28+
29+
bus2.setPortDirection(0, 0xFF);
30+
bus2.setPortPullups(0, 0xFF);
31+
32+
bus3.setPortDirection(0, 0xFF);
33+
bus3.setPortPullups(0, 0xFF);
34+
35+
bus4.setPortDirection(0, 0xFF);
36+
bus4.setPortPullups(0, 0xFF);
37+
38+
// create a timer object and read from pins 1 to 8 on the IO Pi busses every 100ms
39+
var myVar = setInterval(myTimer, 500);
40+
41+
42+
function myTimer() {
43+
console.log('\033[2J'); // clear the window
44+
45+
console.log('IO Pi 1 Bus 1 Pin 1: %d', bus1.readPin(1));
46+
console.log('IO Pi 1 Bus 1 Pin 2: %d', bus1.readPin(2));
47+
console.log('IO Pi 1 Bus 1 Pin 3: %d', bus1.readPin(3));
48+
console.log('IO Pi 1 Bus 1 Pin 4: %d', bus1.readPin(4));
49+
console.log('IO Pi 1 Bus 1 Pin 5: %d', bus1.readPin(5));
50+
console.log('IO Pi 1 Bus 1 Pin 6: %d', bus1.readPin(6));
51+
console.log('IO Pi 1 Bus 1 Pin 7: %d', bus1.readPin(7));
52+
console.log('IO Pi 1 Bus 1 Pin 8: %d', bus1.readPin(8));
53+
54+
console.log('IO Pi 1 Bus 2 Pin 1: %d', bus2.readPin(1));
55+
console.log('IO Pi 1 Bus 2 Pin 2: %d', bus2.readPin(2));
56+
console.log('IO Pi 1 Bus 2 Pin 3: %d', bus2.readPin(3));
57+
console.log('IO Pi 1 Bus 2 Pin 4: %d', bus2.readPin(4));
58+
console.log('IO Pi 1 Bus 2 Pin 5: %d', bus2.readPin(5));
59+
console.log('IO Pi 1 Bus 2 Pin 6: %d', bus2.readPin(6));
60+
console.log('IO Pi 1 Bus 2 Pin 7: %d', bus2.readPin(7));
61+
console.log('IO Pi 1 Bus 2 Pin 8: %d', bus2.readPin(8));
62+
63+
console.log('IO Pi 2 Bus 1 Pin 1: %d', bus3.readPin(1));
64+
console.log('IO Pi 2 Bus 1 Pin 2: %d', bus3.readPin(2));
65+
console.log('IO Pi 2 Bus 1 Pin 3: %d', bus3.readPin(3));
66+
console.log('IO Pi 2 Bus 1 Pin 4: %d', bus3.readPin(4));
67+
console.log('IO Pi 2 Bus 1 Pin 5: %d', bus3.readPin(5));
68+
console.log('IO Pi 2 Bus 1 Pin 6: %d', bus3.readPin(6));
69+
console.log('IO Pi 2 Bus 1 Pin 7: %d', bus3.readPin(7));
70+
console.log('IO Pi 2 Bus 1 Pin 8: %d', bus3.readPin(8));
71+
72+
console.log('IO Pi 2 Bus 2 Pin 1: %d', bus4.readPin(1));
73+
console.log('IO Pi 2 Bus 2 Pin 2: %d', bus4.readPin(2));
74+
console.log('IO Pi 2 Bus 2 Pin 3: %d', bus4.readPin(3));
75+
console.log('IO Pi 2 Bus 2 Pin 4: %d', bus4.readPin(4));
76+
console.log('IO Pi 2 Bus 2 Pin 5: %d', bus4.readPin(5));
77+
console.log('IO Pi 2 Bus 2 Pin 6: %d', bus4.readPin(6));
78+
console.log('IO Pi 2 Bus 2 Pin 7: %d', bus4.readPin(7));
79+
console.log('IO Pi 2 Bus 2 Pin 8: %d', bus4.readPin(8));
80+
}

0 commit comments

Comments
 (0)