-
Notifications
You must be signed in to change notification settings - Fork 3
Devices
The Hub takes little to no changes in order to use for your project. As is it will take any data sent to it, then process the new data out the Serial bus.
All data can be access using the built in GetLastType()
functions. Due to the fact that the library does not know your data type, you will have to call the correct one or be typecasted. There are two default serial output functions: SerialPrintAllNew()
and SerialPrintAllLast()
. The only difference between them is that SerialPrintAllNew()
will only print new data.
The current comma-separated value(csv) format is as follows:
Millis, Node Address, Data as Float, Unit, Status
note: Millis, millis()
, is milliseconds since boot. This number will overflow in 50 days
Should you wish to add to or change the output of the Hub device, all your changes should only need go into the:
// User Section: Output
which contains the void output()
function.
Communication between the devices is handled in the library
Sensor nodes will need to be tweak and created for each unique sensor or setup. The example code will get you most of the way to running your first sensor. There are two sections that you must change to fully get the Sensor node working.
In the first section, you must simply change the defines that will setup your packet and data type to transmit. Note: the referenced table can be found in Library under the communication protocol.
// User Section: Defines ---------- ---------- ---------- ----------
#define PACKET_TYPE 2 // Use the above table as reference
#define DATA_TYPE int
#define DATA_UNIT "m/s^2" // 5 char max
#define ADDRESS_TYPE true // True = Preset, False = pin based
#define ADDRESS 2 // Preset Value
#define ADDRESS_PINS 8,9,10 // Digital Pins to Address off of
// ---------- ---------- ---------- ---------- ---------- ----------
In the second section, this is where all your code for the sensor reading should go. This will happen on the loop call of input()
. As an example the packet of 12345 m/s^2
is being sent with the status of true. Should you need slow down the rate of data capturing simply add a Delay( milliseconds );
to the input function.
// User Section: Sensor Setup ---------- ---------- ----------
void input()
{
g_packet.SetReading(12345);
g_packet.SetStatus(true);
}
// ---------- ---------- ---------- ---------- ---------- ----------
Communication is based on a ask and response system. There are 2 stages to this, with 3 responses:
It is key went working with the 'stage 3' response to not interrupt a data transaction in motion.
NEVER set stage 1 to stage 3.
// Tell hub the datatype
if (g_stage == 0)
Wire.send( PACKET_TYPE );
// Tell hub data
else if (g_stage == 1)
{
Wire.send((uint8_t *)&g_packet, sizeof(g_packet));
g_stage = 0;
}
// Tell Hub no data
else if (g_stage == 3)
Wire.send( TYPENULL );
Communication between the devices is handled in the library