-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLenzi_wall_xbee_processing
67 lines (49 loc) · 1.46 KB
/
Lenzi_wall_xbee_processing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//MIT Mobile Experience Lab
//ReActive Innovation for Artisans project - Vibration sensor wall prototype
//June 2015
//This code pushes the serial data to Processing for visualization
#include <XBee.h>
#include <SoftwareSerial.h>
XBee xbee = XBee();
ZBRxIoSampleResponse ZBSample = ZBRxIoSampleResponse();
// Define NewSoftSerial TX/RX pins
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX = 8;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 9;
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
SoftwareSerial nss(ssRX, ssTX);
void setup() {
// start soft serial
nss.begin(9600);
xbee.begin(nss);
Serial.begin(9600);
delay(3000);
establishContact(); // send a byte to establish contact until receiver
// responds
Serial.println("It has Begun");
}
int data[4];
void loop() {
xbee.readPacket();
if (xbee.getResponse().isAvailable()) {
if (xbee.getResponse().getApiId() == ZB_IO_SAMPLE_RESPONSE) {
xbee.getResponse().getZBRxIoSampleResponse(ZBSample);
if (ZBSample.isAnalogEnabled(0)) {
for (int i =0; i < 4 ; i++){
data[i]= ZBSample.getAnalog(i);
}
for (int i = 0; i < 4; i++){
Serial.write(data[i] % 256);
}
delay(1000);
}
}
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A'); // send a capital A
delay(300);
}
}