Data acquisition is a very important part of test engineering. By plotting the data acquired in real time, we can analyze how the design behave and to determine whether it meet specs or not. Some examples of application are logging aircraft altitude and LiPo battery cells temperature. In my previous project of designing an aircraft altitude controller, the real time data logger is a key part of the project in determining how the system perform. In that project, I used Java to program a real time data plotter and it was such a pain. The code became so messy that I do not want to look at it ever again. It took such a long time too.
So this time, I turned to MATLAB. As a 4th generation programming language, this is so much easier since it got a Serial interface and plotting function built in. In the end of this post, we should get sometime like this:
MATLAB is a matrix based software that is widely used in engineering. Since the software is matrix based, it is actually a lot faster to do matrix operations rather than looping.
The following is an example of how to create a filter to eliminate all non-positive numbers from an array using the dot operation instead of a for loop.
function y = negative_filter( x )
% function y = negative_filter( x )
% plugging in a matrix will return only the positive numbers in a vector
%Create a zero matrix same size as the incoming matrix for comparison
z = zeros( size(x));
%Create a "filter" matrix that return 1 if the condition is true
%It will return 0 if the condition is false
filter = (x > z);
%This function multply the "filter matrix" with the incoming matrix
%elements by elements, note the '.' in front of '*'. This line will set all
%number less than 0, or false to the earlier stated condition to 0.
y = filter .* x;
%This remove all zero terms from the matrix
y(y==0) = ;
This is a simple project that I did with the LCD Shield to learn how to use it. Basically, you can use the buttons to scroll through the different pins and control the lcd display back light. Basically, this is a mini voltmeter. Good for testing out raw sensor readings.
In your program, you might want to acquire files from the internet for purposes such as update, additional resources, web image gallery… so here’s a modified version of the codes I found on stackoverflow.com that you can just copy and paste into your Java program. Just supply the URL for path and the file name in filename.
Time to open up the new toys I got from China, DFRobot LCD Keypad Shield (DFR0009)! As I said, I ordered this from China’s ebay equivalent, Taobao.com, got this for 30 RMB ($5 USD), pretty cheap for a LCD display panel, let alone this is a shield with keypad! In the US, it is being sold for $15!!! Anyway, the link is follow if anyone is interested. Maybe I will do a post about ordering stuffs directly from China. I spent like $50 total and stocked up my electronic inventory with all kinda of new shields, joysticks…
In the engineering world, we often gather lots of data that we need to store and display in a spreadsheet format. Microsoft’s Excel is probably the most popular spreadsheet format there are out there. In order to read and write to an excel file from Java, we need the Apache POI library. The POI library actually handle all kinds of Microsoft document format, however, we will only deal with Excel files today.
In this post, I will talk about using Java as a client and Arduino as a server. To keep it simple, we will only use the Arduino’s built-in LED 13. Before proceeding, please read my other post about Arduino to Java Communication through Serial Port if you haven’t already.
In summary, the only differences in the Java’s side is that we will use jSSC’s serial write method instead of serial read as follows: