Grapher Library

1. Intro

Grapher is a small utility included with Ansteron IDE which allows data samples from Ansteron Board to be plotted onto computer screen for monitoring or reviewing. A software library for Ansteron Board is also included. It handles low level protocol and provides simple functions for working with Grapher running on computer. Communication is based on Serial Interface.

Grapher can run by itself or with Ansteron IDE. When Grapher is called from Ansteron IDE, a link is established which allows two software to share control of one Ansteron Board. Users then won't have to manually switch the board back and forth between them.

2. How it works

Grapher can plot up to 8 graph lines at the same time. Each line is also called a channel and each have a different color by default. They are numbered from 1 to 8 and each of them needs to be activated to start showing except channel 1(activated by default). All channels have the same number of sample, which is the size in horizontal direction of the graph.

Each time a sample is added to a channel, the graph shift to the right one sample. The oldest sample will be discarded and the new value will be plotted on the right side. If there is more than 1 channel activated and samples are added to only one channel, other channels will be written with zeros.

A basic program running on Ansteron Board will follow these steps:

  • Initialize the connection with Grapher software.
  • Activate channels other than channel 1.
  • Start adding samples.

The program can skip initialization if only channel 1 and default settings is used (1000 samples, max sample value is 1024). Setting up Serial Interface is still needed and the program can then send data at any time. Grapher will also skip initialization and start plotting as soon as samples are received.

3. Example

In this example, output of a potentiometer is connected to pin C0 (analog pin). Ansteron Board will read voltage value then add a sample to the graph every 25 millisecond. When the knob moving, the change of voltage level can be view on the graph.

Below is Grapher streaming samples from Ansteron Board. One 0.1uF capacitor was added between output of the potentiometer and GND to filter noise, giving a smooth curve.

5. Functions

grapher_init(number_of_sample,max_sample_value);

The function will setup Serial Interface with default setting, and wait for Grapher software. Number of sample per channel and maximum sample value is also set. Function returns when the connection has been established and Grapher software is ready to receive samples. Note that the function will also send restart connection request every 500ms until a message is received from Grapher software.

grapher_add_sample(channel,value);

Add a sample into channel. If there are more samples in the buffer than its size, the oldest sample will be removed, the entire graph shift right 1 sample and the new value will be added. There are 8 possible channels, number from 1 to 8. Value of sample is 16bit integer.

grapher_activate_channel(channel);

Activate a channel. Input channel is a value 1 to 8. Channel 1 is activated by default. Other channels needed to be activated before use.

grapher_deactiveate_channel(channel);

Turn of a channel when it's not in use. It's graph won't be plotted on the display.

grapher_set_number_of_sample(size);

Set the size of buffer per channel. The default size is 1000 samples for each channel. Maximum buffer size is 65535(0xFFFF) samples (per channel).

grapher_set_max_sample_value(max_value);

Set the maximum possible value of all samples. This number will be used when plotting the graphs.

grapher_set_channel_color(channel,RGB_color);

Set color for each channel. Each channel has a different default color and they can be changed with this function. RGB_color is a 32bit long value with the 3 low bytes are RGB values(0x00RRGGBB).

grapher_set_background_color(RGB_color);

Change background color to RGB_color. Input value is 32bit with 3 low bytes are RGB values(0x00RRGGBB);

grapher_show_grid(on_off);

Show or hide grid. Giving zero will hide the grid. Any other value will make the grid show.

5. Notes

The rate of samples being added should be limited to no more than 50 times per second when using Mac OS X or Linux. On Windows, the rate has no limit but it depends on the speed of Serial Interface.