New to Megunolink

Share your projects using MegunoLink Pro here!
Post Reply
JSYoung
Posts: 1
Joined: Thu Jun 19, 2014 1:24 pm

Thu Jun 19, 2014 1:32 pm

I am using Megunolink to communicate with a laboratory scale to send a print command then receive the information. I have made a button that will send the command and I have also used the timer to easily send the command on a loop every 10s. I am now in need of help to get the time plot to plot the weights from the monitor to the time plot. From what I have read the information coming to the time plot needs to be surrounded by { } but I am unsure of how to send information received from the monitor to the time plot. I have little to no code experience. Any help anyone can give would be great and save me hundreds of dollars from having to buy the lab software that does the same thing.
Thank you
lorrin
Posts: 1
Joined: Sat Jun 21, 2014 3:54 pm

Sat Jun 21, 2014 4:15 pm

Hello JSYoung,

I am new to Megunolink also, but I can post my first program that sets up a basic 3 channel plot and outputs from my Arduino to those three channels in Meguno Link.
Maybe it will help you get started too.

Here is how the program below is set up:

The "MyPlot" commands in the program are available because I have included the "MegunoLink.h" library at the top of the program.
The program below sets up the plot, names the X and Y labels, and names the plot.
It then names the 3 "Series" names for the 3 channels that will be sent to the Megunolink software software.
In the program I read each temp sensor 30 times while storing the values into an array then averaging the values in each array.
This is to "calm down" the noisy readings from the Arduino so that they look smoother on the graph.
I then convert the readings from the Arduino 0-1023 values to Fahrenheit and add a calibration number for each sensor as each sensor is connected via a differnt length cable to the Arduino.
The value for "medianOrAverage1" Is set to only have 1 of 2 values (50 or 70) so that it looks like a bar graph on the graph plot showing only when the AC in my home is "on".
The comment in the program "Send Values to graph" is the section that actually sends the information to Megunolink for plotting.
The "totalAContime" message is just sent to Megunolink so that I can see in the serial monitor window how long my home AC has been "on" in minutes total during the plot as I have not figured out a way to put a message actually on the plot graph.

The actual program is below this line:
/*

This program reads an analog input and gives the average of 30 readings,
sorts the list of readings and delivers the average for Analog pins 0-2

*/
#include "MegunoLink.h"
TimePlot MyPlot;
// variables for subroutines:
int analogValues[30];
int analogValues1[30];
int analogValues2[30];
float totalAContime=0;
float totalForAverage=0;
float medianOrAverage=0;
float totalForAverage1=0;
float medianOrAverage1=0;
float totalForAverage2=0;
float medianOrAverage2=0;
int numReadings = 29; // number of samples to take
int readingNumber; // counter for the sample array
//
void setup()
{
Serial.begin(9600);
//=======================\
delay(1000); // So that serial port will have set back to the plotting software by the time next command is sent
Serial.println("{TIMEPLOT|CLEAR}");
MyPlot.SetTitle("My Apartment Temp");
MyPlot.SetXlabel("Time");
MyPlot.SetYlabel("Temp");
MyPlot.SetSeriesProperties("Outside Temp", Plot::Magenta, Plot::Solid, 2, Plot::NoMarker);
MyPlot.SetSeriesProperties("Apartment Temp", Plot::Green, Plot::Solid, 2, Plot::NoMarker);
MyPlot.SetSeriesProperties("A/C on ", Plot::Blue, Plot::Solid, 2, Plot::NoMarker);
//
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
// set the rest as outputs and LOW pullup to help with noise
digitalWrite (A3, LOW);
pinMode(A3, OUTPUT);
digitalWrite (A4, LOW);
pinMode(A4, OUTPUT);
digitalWrite (A5, LOW);
pinMode(A5, OUTPUT);
//========================/
}
void loop()
//==========================\
// Start of loop for A0 pin
{
for (readingNumber = 0; readingNumber < numReadings; readingNumber++)
{
//get the reading:
analogRead(0);
delay(5);
analogValues[readingNumber] = analogRead(0);
// keep the total of values for average method
totalForAverage=(totalForAverage+analogValues[readingNumber]);
}

// End of loop for A0 pin
//========================/
//
//========================\
// Start of loop for A1 pin
for (readingNumber = 0; readingNumber < numReadings; readingNumber++)
{
//get the reading:
analogRead(1);
delay(5);
analogValues1[readingNumber] = analogRead(1);
// keep the total of values for average method
totalForAverage1=(totalForAverage1+analogValues1[readingNumber]);
//Serial.print(" totalForAverage: ");
//Serial.println(totalForAverage);
}
// End of loop for A1 pin
//========================/
//
//========================\
// Start of loop for A2 pin
for (readingNumber = 0; readingNumber < numReadings; readingNumber++)
{
//get the reading:
analogRead(2);
delay(5);
analogValues2[readingNumber] = analogRead(2);
// keep the total of values for average method
totalForAverage2=(totalForAverage2+analogValues2[readingNumber]);
//Serial.print(" totalForAverage: ");
//Serial.println(totalForAverage);
}
// End of loop for A2 pin
//=======================/
//
//=======================\
// figure out the average from the total we been keeping (average method)
medianOrAverage = totalForAverage/numReadings;
medianOrAverage1 = totalForAverage1/numReadings;
medianOrAverage2 = totalForAverage2/numReadings;
//=======================/
//=======================\
// Convert all to fahrenheit
medianOrAverage =(((((medianOrAverage)*.004882814)-.5)*100)*1.8)+36.1; // on breadboard
medianOrAverage1=(((((medianOrAverage1)*.004882814)-.5)*100)*1.8)+36.4; // AC sense
medianOrAverage2=(((((medianOrAverage2)*.004882814)-.5)*100)*1.8)+36.4; // Outside
//=======================/
//
//=======================\
// Try to show AC on as a bar graph of "on time" by using "bar" graph type values
if (medianOrAverage1 < 66) // If AC is blowing on sensor then it will be below 66 degrees
{
medianOrAverage1=70; // This will show a Bar up to 65 degrees if AC ia on
totalAContime=totalAContime+10; // Keep track of total of AC on time during this plot (10 more seconds of on time)
}
else
{
medianOrAverage1=50; // Hide bar below plot if AC is off
}
// =====================/
//
//======================\
// Send values to graph
MyPlot.SendData("Outside Temp", medianOrAverage2);
MyPlot.SendData("Apartment Temp", medianOrAverage);
MyPlot.SendData("A/C on ", medianOrAverage1);
Serial.print("Total time AC has been on during this plot so far is: ");
Serial.println(totalAContime/60);
Serial.println();
//======================/
medianOrAverage=0;
totalForAverage=0;
medianOrAverage1=0;
totalForAverage1=0;
medianOrAverage2=0;
totalForAverage2=0;
//=======================/
delay(9400); // Delay until next sensor (for total of 10 seconds)
// =========================
}
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Thu Jul 03, 2014 3:38 am

Thanks for providing your example Lorrin.

Hi JSYoung, yep you need to send the data in a format that MegunoLink understands. At that point it will automatically detect it and send it to the plotting visualiser. Unfortunately lab scales don't usually let you define your own message format. One option could be to use MegunoLink to log the data and then read the text file using MATLAB. Alternatively you could put an Arduino in the middle to receive the data, change the format to suit MegunoLink then forward it on. This would involve a bit of work but if you are making lots of measurements it could be worth it.

Cheers
Phil
Post Reply