My apologies if this has been answered before, but I could not find my solution anywhere.
Now, moving on to my problem. I have two IR distance sensor measuring distance, the sensor are connected to FEZ Mini. When I debug the the program, it runs fine, and the reading obtained through the sensors are displayed on the output debug window.
I was thinking of copying all the output reading to a excel and create a graph, but that will be an enormous pain. So I was wondering if there is a way of getting output in any kind of graph.
You can enable the USB CDC interface with debugging interface. This way the PC will discover 2 USB devices: the debugging netmf interface and a virtual COM.
You can forward the results through that virtual COM port.
… then, once you hav CDC working, you can use a terminal program to collect the output and put it into Excel. Or you can write a PC program to take that output and graph it.
Thanks a lot Brett and Joe, but by stupid brain has no idea what all those words means. :-[
In the mean time I found a code that will create an excel application and export the values there. But whenever I run it it comes up with an error message, and stops the program from running.
I have attached am image that shows the error message. Here is my code
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.Threading;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using Microsoft.Office.Interop.Excel;
namespace GHIElectronics.NETMF.FEZ
{
public class Program
{
public static void Main()
{
FEZ_Components.DistanceDetector myRanger_l = new // Get Range From Left Sensor
FEZ_Components.DistanceDetector(FEZ_Pin.AnalogIn.An7, // Analogue PIN Input from the Left sensor
FEZ_Components.DistanceDetector.SharpSensorType.GP2Y0A21YK); // Sensor Model Declare
FEZ_Components.DistanceDetector myRanger_r = new // Get Range From Right Sensor
FEZ_Components.DistanceDetector(FEZ_Pin.AnalogIn.An6, // Analogue PIN Input from the Right sensor
FEZ_Components.DistanceDetector.SharpSensorType.GP2Y0A21YK); // Sensor Model Declare
PWM servo = new PWM((PWM.Pin)FEZ_Pin.PWM.Di3); // Servo motor conection PIN
double range_l = 0; // Variable Declare to store IR Range in CM, double for fraction
double range_r = 0; // Variable Declare to store IR Range in CM, double for fraction
double pulse = 0; // Variable Declare to calculate and store pulse width instruction
while (true)
{
range_l = myRanger_l.GetDistance_cm();
range_r = myRanger_r.GetDistance_cm();
if (range_l > 10 && range_l < 34)
{
pulse = 2760 - (36 * range_l);
Debug.Print("Left: " + range_l.ToString());
Debug.Print("PWM: " + pulse.ToString());
Debug.Print("Right: " + range_r.ToString());
Debug.Print("----------------");
servo.SetPulse(20 * 1000 * 1000, (uint)pulse * 1000);
Thread.Sleep(100);
}
else if (range_l > 36 && range_r > 36)
{
pulse = 1500;
Debug.Print("STABLE");
Debug.Print("Left: " + range_l.ToString());
Debug.Print("PWM: " + pulse.ToString());
Debug.Print("Right: " + range_r.ToString());
Debug.Print("----------------");
servo.SetPulse(20 * 1000 * 1000, (uint)pulse * 1000);
Thread.Sleep(100);
}
else if (range_r > 10 && range_r < 34)
{
pulse = 240 + (36 * range_r);
Debug.Print("Left: " + range_l.ToString());
Debug.Print("PWM: " + pulse.ToString());
Debug.Print("Right: " + range_r.ToString());
Debug.Print("----------------");
servo.SetPulse(20 * 1000 * 1000, (uint)pulse * 1000);
Thread.Sleep(100);
}
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
xla.Visible = true;
ws.Cells[1,1] = "IR left";
ws.Cells[1,2] = "IR Right";
ws.Cells[1,2] = "PWM";
ws.Cells[2,1] = range_l.ToString();
ws.Cells[2,2] = range_r.ToString();
ws.Cells[2,3] = pulse.ToString();
}
}
}
}
the code you found is for the full .Net framework on a PC, that has Excel installed. It will never work on a .Net Micro Framework device, so don’t bother
There are multiple ways to get the data into your PC. How “real time” that is will depend on what you’re trying to achieve, which you haven’t really told us that, so tell us more about what you are trying to achieve as the overall goal.
One option we haven’t discussed yet, you can log the data to an SD card and at some point later take that SD card and open the data in Excel, and draw a graph.
If you want more like “real time” then CDC is best. I’ll find a CDC tutorial for you shortly.
SD card logging example: http://code.tinyclr.com/project/169/sd-card-program-logging/
UART communication to PC: http://wiki.tinyclr.com/index.php?title=UART_-_PC_Communication (to give you the concept of serial data being sent between Fez and a PC)
CDC http://wiki.tinyclr.com/index.php?title=USB_Client (go straight tot he CDC section, ignore everything else at this point). That code will show you how to output the data to the serial line, all you have to do is replace the “hello world” with your own data, and on the PC side run Tera Term and collect the data, copy/paste into Excel and you’re done. Or as I said, write a PC program that collects the data from the serial port and displays the graph (but this is a more advanced requirement, not necessarily easy)
I am writing a report and on the testing section I want to include a graph for distance vs time and PWM signal vs time graph. It doesn’t matter if its the same graph or not.
To do the graph I’ll need data from the IR sensor and PWM. It doesn’t have to be real time. I just need a graph that shows the PWM signal responds for change in distance.
So far, the output of the sensor shows on the debug window and I get a loads of data, which is not easy to copy to excel. So I was wondering if there is something I could do that will put those values directly to cell in excel or any other graph making software.
My apologies if I have been confusing, I hope I could make sense. :-[
Do you have a soldering iron? You can solder direct onto an SD card.
Even if you do have a soldering iron, CDC is the simplest way forward here. You have Tera Term, right? Then all you need to do is incorporate the CDC portion of the code into your application and instead of doing debug.print to output the data, spit it out the CDC port. Then, you can set TeraTerm to log the data that it gets to a file, then just open the file in Excel and draw your graph/s.
Hi Brett, thank you very for your help. You made my brain open to new information. I was on a deadline, hence couldn’t implement the solution you provided. So, I just copied the result I got from the debug window and created a graph in excel.
Now that I am free now, I want to properly put my effort into it. If I wanted to get a real time graph (based on the information I get from the debug output window).