I’m trying to use my FEZ Domino as a wireless data acquisition sensor.
I’m reading the analog values from a 3-axis accelerometer and sending the resulting data through an Xbee to a remote computer.
I want to sample as fast as possible. Based on the millisecond time stamp of the samples, I’m getting about 128 samples per second with the current code.
Take a look and any suggestions to optimize would be appreciated.
using System;
using System.Text;
using System.Threading;
using System.IO.Ports;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
namespace FEZ_Domino_Accel
{
public class Program
{
static AnalogIn accelY = new AnalogIn(AnalogIn.Pin.Ain0);
static AnalogIn accelX = new AnalogIn(AnalogIn.Pin.Ain1);
static AnalogIn accelZ = new AnalogIn(AnalogIn.Pin.Ain2);
static SerialPort xbeePort;
static byte[] outBuffer;
public static void Main()
{
accelX.SetLinearScale(-500, 500);
accelY.SetLinearScale(-500, 500);
accelZ.SetLinearScale(-500, 500);
double accelXValue = 0;
double accelYValue = 0;
double accelZValue = 0;
xbeePort = new SerialPort("COM1", 38400, Parity.None, 8, StopBits.One);
xbeePort.Open();
Debug.Print("GO!!");
while (true)
{
accelXValue = accelX.Read();
accelYValue = accelY.Read();
accelZValue = accelZ.Read();
outBuffer = Encoding.UTF8.GetBytes(DateTime.Now.Millisecond + "," + accelXValue.ToString() + "," + accelYValue.ToString() + "," + accelZValue.ToString() + "\n"); ;
xbeePort.Write(outBuffer, 0, outBuffer.Length);
}
}
}
}