Hardware Reference
In-Depth Information
in the update function associated with the packet creation and sending. Compile and run the program, and the red
line should increment to a new position after three packets are sent. With the program running, upload the modified
software serial sketch to the Arduino Mega ADK that is set up with the connected, required hardware, and check for
data printing to the serial monitor. The data is in readable by humans in this from, but shows that the packets are
reaching the Arduino.
Listing 8-2. testApp.h
#pragma once
#include "ofMain.h"
class testApp : public ofBaseApp{
public:
// variables and objects
unsigned char graph[256], graph1[256], graph2[256];
unsigned char point;
int counts;
bool SensorsSent [3];
bool ReplyOK;
bool FirstPacketsent;
unsigned char incomingBuffer[80];
unsigned char incomeData[64];
int incomingByteLen;
unsigned char incomingPacketChecksum;
unsigned char destADR[10];
unsigned char packetBuffer [80];
int lastPacketLength;
unsigned char dataLength;
ofSerial serial;
// openFrameworks-specific functions
void setup();
void update();
void draw();
// sensor network functions to handle packets
void CheckForIncoming();
void WaitForReply();
void ReadPacket ();
void CreatePacket (unsigned char*, int);
}; // end class testApp
The Arduino
The Arduino is the main workhorse of this chapter's example. The Arduino receives packets from other network
nodes and processes the information to be logged to an SD card to be eventually retrieved by an Android device.
The Arduino programming responds to good incoming data by generating an “OK” reply packet using the address
contained within the good incoming packets of the sending node. If a packet is malformed, a broadcast “BAD” packet
is sent to the network; the packet is a broadcast because it might not be possible to determine the address of the
sending node. Both reply packets keep the simulated sensor network that is made with openFrameworks moving
forward and sending data.
 
Search WWH ::




Custom Search