MEAM.Design - MaEvArM - Graphical Data Logging


Goal

The goal of the graphical data logging section is to provide an easy way to visualize data on the M1. It is possible to see data using the USB communications framework, but viewing in the terminal does not always give a very intuitive idea of what is happening.

In this guide, we will set up a method for viewing ADC values on a graph. You can throw any data at the graph, such as filtered ADC values.

Configure M1

The first step is to get your M1 to spit out Hex values over the USB port to your computer. Follow the USB guide, but use the following code instead:

#include "maevarm-usb.h"
int main(void)
{
unsigned int value = 512;
usb_init();
while(!usb_configured()); // wait for a connection
while(1)
{
usb_tx_hex(value);
usb_tx_string("\n");
}
}


Now, your M1 will be spitting out an endless stream of 0x8000's to your computer. Check that it is working by running one of the various terminal options described in the USB section.

Configure Python

Mac

You need to install matplotlib from: http://sourceforge.net/projects/matplotlib/files/ Get this file if on Snow Leopard: matplotlib-0.99.3-Apple-py2.6-macosx10.6.dmg

You also need to install PySerial from http://pypi.python.org/pypi/pyserial - get the source version. Unzip it, and open a Terminal. Change directories into the unzipped folder, and run "python setup.py" - this will install the pyserial library.

Windows

You're going to want to download the Portable Python distribution: http://www.portablepython.com/. Make sure to download the 2.5.4 distribution. Now, grab pyserial from: http://pypi.python.org/pypi/pyserial. Don't get the Windows installer - get the tar.gz source file. Unzip that with 7-zip - you may have to then unzip the resulting tar file, too.

In the resulting pyserial-2.5 folder, copy the serial folder. Paste it into the "\App\Lib" directory of the Portable Python distribution.

Linux

If you are running Linux, BSD, or your own operating system that you wrote in your free time, chances are that you know how to get Python running as described.

Running the Script

Updated some Python code

link: PyLogger (right-click, select download as log_m1.py)
If having trouble, try this Logger, which eliminates a redundant new line check - thanks Miki. link: PyLogger2 (right-click, select download as log_m1.py)
link: PyViewer (right-click, select download as view_m1.py)
When in Windows, the Logger file should be modified to read from COM7 instead of /dev/cu.usbmodem411

Place these files anywhere if on Mac, or in the "~\App" directory of your Windows Portable Python install.

If on Windows, change into the Directory of your Portable Python installation. Go to the "\App" directory. Run "python.exe log_m1.py" - you should see a graph pop up with a straight line on it.

If on Mac OS X, open a Terminal and go to the directory where you downloaded the Python script. Run "python log_m1.py" - you should see a graph pop up with a straight line on it. For mac: http://www.jaharmi.com/2009/08/29/python_32_bit_execution_on_snow_leopard

Running the Logger Wirelessly

If you want to log data wirelessly,