Plotting with XBee

Support forum for MegunoLink
Post Reply
User avatar
RoboBill
Posts: 31
Joined: Mon May 23, 2016 4:13 pm

Fri Jun 23, 2017 7:25 pm

I can make the sinewave example work thru the standard serial port. But when I modify the sketch for an XBee series 1 on pins 8 & 11, I'm unable to see any plot data. What must I do to the arduino sketch to have the XYPlot data sent via my XBee.

Thanks

RoboBill

Here is your example sketch with my SoftwareSerial & Xbee modifications

/* **********************************************************************************************
* Example program to plot sine wave data on MegunoLink's Time Plot visualiser
* Visit http://www.megunolink.com/documentation/plotting/
* for more information.
* ********************************************************************************************** */
#include "MegunoLink.h"
#include <SoftwareSerial.h>

// XBee Serial configuration
const int XBeeRxPin = 11;
const int XBeeTxPin = 8;
SoftwareSerial XBeeSerial(XBeeRxPin, XBeeTxPin);



// For more information on installing the MegunoLink Arduino library check out our documentation
// http://www.megunolink.com/documentation ... tegration/

// You can download the MegunoLink Interface (.mlx) that goes with this example here
// http://www.megunolink.com/examples/ardu ... newave.mlx


// Uncomment if you would like to use plotting channels
// TimePlot MyPlot("Waveforms"); //"Waveforms" = the taget plotting channel (remember to select this in megunolink)

TimePlot MyPlot; //no channel selected

void setup()
{
XBeeSerial.begin(19200);
//Serial.begin(19200);

MyPlot.SetTitle("Sine and Cosine Function Waveforms");
MyPlot.SetXlabel("Time");
MyPlot.SetYlabel("Amplitude");

// Set the plotting parameters. "Sinewave" = series name, Plot::Blue = line colour
// 2 = line width, Plot::Square = marker style
MyPlot.SetSeriesProperties("Sinewave", Plot::Blue, Plot::Solid, 2, Plot::Square);
MyPlot.SetSeriesProperties("Cosinewave", Plot::Red, Plot::Solid, 2, Plot::Square);

// Colours include
// Red, Green, Blue, Yellow, Black, Magenta, Cyan, White

// Markers include
// Square, Diamond, Triangle, Circle, Cross, Plus, Star, DownwardTriangle, NoMarker

// Line style
// Solid, Dashed, Dotted, DashDot, DashDotDot

}


void loop()
{
double dY, dY2;
float seconds;
float frequency = 0.5; //Hz
float phase = 3.141 / 2;

seconds = (float)millis() / 1000;

dY = sin(2 * 3.141 * frequency * seconds);
dY2 = cos(2 * 3.141 * frequency * seconds + phase);

//Send Data To MegunoLink Pro
MyPlot.SendData(F("Sinewave"), dY); // Sinewave = series name, dY = data to plot
MyPlot.SendData(F("Cosinewave"), dY2); // By wrapping strings in F("") we can save ram by storing strings in program memory


delay(10);
}
User avatar
RoboBill
Posts: 31
Joined: Mon May 23, 2016 4:13 pm

Fri Jun 23, 2017 8:34 pm

Found it!

added


TimePlot MyPlot("",XBeeSerial);

It works great! :mrgreen:
Post Reply