Using sensors together with the Arduino or JeeNode is cool. Using the serial monitor of the Arduino IDE lets you see the values. The data is sent from the Arduino over (in my case) a USB cable to my PC. With the serial monitor of the IDE I can receive and also send data.
To make a domotica solution I need something more than the serial monitor of the IDE. I want to be able to send and receive data from my own application and website.
I’m want to use Java to develop the application that’s going to send and receive data. Although I might also try C/C++ in a while, but for now I’ll focus on Java. The reason I want to use Java is that I’m using a Windows computer to develop, but I might want to use a Linux based device to let my application run and do its job. Hopefully it will be easier to switch between the two operating systems with an application written in Java.
(The platform I’m thinking of is the Raspberry Pi; hopefully soon to be ordered)
Searching for a good way to start writing code to communicate with an Arduino I found this page on the Arduino website and also another interesting website. (I did find this site about C and Arduino which might be useful in the future; and this one is I think about Processing and Arduino)
It turns out that by using the RXTX Java library it is possible to use serial communication to send and receive data between a PC and an Arduino. The page shows a code example of a Java app which is able to receive data from a serial port (COM port; in PC terms).
I chose Eclipse as my Java IDE (the SpringSource version to be exact). I had to download the 2.2pre version of the RXTX Library, because my Windows is a 65-bit version. In the 2.2pre package a 64-bit version of the rxtxSerial.dll is included. The 32-bit version will not work on a 64-bit OS, as I found out by trial-and-error. (I didn’t read through the entire page on Arduino.cc otherwise I would have seen the instruction) Beware that when you use the 2.2pre .dll file you also need to use the 2.2pre RXTXcomm.jar file in your classpath. If you don’t a version mismatch error will be shown.
The steps I took for my basic serial communication test application were:
- copy the rxtxSerial.dll to c:\windows\sysWOW64
- add the c:\windows\sysWOW64 to your path
- added the location of the RXTXcomm.jar file to the classpath in Eclipse
- created a new Java project;
- added a new file to the \src of the project
- named it SerialTest.java
- copied the code snippet from the Arduino page (file is attached to this post)
- change the COM port to COM5
- changed the bit-rate in the Java code (I needed 57600 for my JeeLink with RF12Demo)
- build en run
I saw the expected text from the RF12Demo in the console window of Eclipse.
The first step is done, data is transferred from JeeLink (Arduino) to a ‘self made’ application. The next step is, of course, to send data to an Arduino. I’ll let you know whta my findings are.
The first of many steps to my own Java Domotica-bridge application.