I'm having a problem using it within my PID program so I decided to create a very simple Chart Logging program to assist with my troubleshooting. Having gotten the simple program to work I thought I would share it in case other novice programmers are temporarily baffled by some of the configuration and setup steps.
When you run the program it displays a message telling you to launch the NXJChartLogging program on the PC and click the Connect button. Details in the comments. After connected, you press the ENTER button on the NXT to start the logging. This example uses real time logging. Enjoy.
- Code: Select all
import java.io.IOException;
import lejos.nxt.*;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;
import lejos.util.Delay;
import lejos.util.LogColumn;
import lejos.util.NXTDataLogger;
public class Demo {
static NXTDataLogger logger = new NXTDataLogger();
static LogColumn someNumber = new LogColumn("Some Number", LogColumn.DT_INTEGER);
static LogColumn[] columnDefs = new LogColumn[] { someNumber };
public static void main(String[] args) throws InterruptedException, IOException {
LCD.drawString("Waiting for ", 0, 2);
LCD.drawString("bluetooth con to", 0, 3);
LCD.drawString("PC to log data.", 0, 4);
LCD.drawString("Launch NXT Chart", 0, 5);
LCD.drawString("Logger & click", 0, 6);
LCD.drawString("the Connect btn.", 0, 7);
// From a command line:
// [leJOS Install Location]\bin\nxjchartinglogger.bat
// Enter the NXT's name or address. Be sure you have write permission
// to the folder chosen by the utility. If not, change the folder.
// Click the Connect button
NXTConnection connection = Bluetooth.waitForConnection();
logger.startRealtimeLog(connection);
logger.setColumns(columnDefs); // must be after startRealtimeLog()
LCD.clear();
Sound.beep();
LCD.drawString("Press orange btn", 0, 4);
LCD.drawString("to start.", 0, 5);
Button.ENTER.waitForPressAndRelease();
LCD.clear();
LCD.drawString("Press and hold", 0, 5);
LCD.drawString("dark gray ESCAPE", 0, 6);
LCD.drawString("button to stop.", 0, 7);
int startCount = 42;
while (!Button.ESCAPE.isDown()) {
logger.writeLog(startCount);
logger.finishLine();
startCount++;
Delay.msDelay(500);
}
logger.stopLogging();
}
}
The display on the PC updates in real time:

Thanks, again, to Kirk!
Walt
