NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Programming in JAVA

April 10, 2011
by abd445
abd445's Avatar

Hello,

I was just wondering if its possible to program the micro controller in JAVA? The reason I ask this is because I have to use some values measured by the micro controller in my program which I have written in JAVA. But I have no clue as to how to get those values (variables) in my program. I was thinking if I could program the micro controller in JAVA itself, I could include that code in my main code and would be able to use the variables then. Can you please offer some insight?

Thanks!

April 10, 2011
by bretm
bretm's Avatar

You'd need something like this, but you'll never fit all of java on an atmega168.

April 10, 2011
by Ralphxyz
Ralphxyz's Avatar

Wow, that "The NanoVM - Java for the AVR" is really interesting.

abd445, what exactly are you trying to do?

I think you need to understood serial communications using JAVA more so than programming in JAVA on the micro. There have been other threads here on the Nerdkits forums about using JAVA for serial communications so search the forums and ask on one of those threads. Possible someone has already gotten this to work.

All you are apparently wanting to do is to read values off of the Nerdkit mcu, is that correct.

Ok, assuming so, take the tempsensor project. that program is taking temperature readings and displaying the temperature on the LCD.

It is also sending the temperature to the serial port:

     // write message to serial port
         printf_P(PSTR("%.2f degrees F\r\n"), temp_avg);

You only have to read those values from the serial port, using JAVA or any other programming language.

I cannot see the advantage of gathering those temperature readings using JAVA on the mcu.

They are just values, rather they are gathered with C or with Java "71.2" is 71.2.

Now that would be cool to do using JAVA on the micro, but, if what you really want to do is to get some work done, your efforts at learning serial communications using JAVA are probable better spent just learning JAVA on your PC.

Google, JAVA serial communications, one of the first hits will be this which will get you started,or change your mind about doing it this way, maybe prompting you to learn python.

So what exactly are you trying/wanting to do?

Ralph

April 11, 2011
by abd445
abd445's Avatar

It is correct that I am trying to get the value from the mcu into my program as I need to store it in a database. I am not yet familiar with JAVA serial communication but I will definitely check that out.

I have created a database using hash tables in JAVA and I need to store the value obtained from the height sensor into that database automatically. So for that I need that value in my program. Right now I am obtaining the value in a C program, I'd like to do the same thing with JAVA or if there's another way to obtain the value, I am open for suggestions.

Thanks!

April 17, 2011
by abd445
abd445's Avatar

Hey,

Does anybody has the knowledge of how does serial communication works in JAVA? That is to say, how to read the sensor values from the MCU into my JAVA program? I would appreciate any help.

April 17, 2011
by Ralphxyz
Ralphxyz's Avatar

Going by my JAVA Serial Programming link I would not be surprised that you end up using a scripting language like Python to read the serial values from the mcu and have Python write a text file to your pc and then have your JAVA program read that text file. This could all be done near real time so the end user would not notice all that was involved.

Possible you could do a JAVA/USB thing and then stretch it into connecting with the mcu but I really think you have better things to be doing with your time.

Ralph

April 19, 2011
by abd445
abd445's Avatar

Thank you very much for the reply. Well I am familiar with how to read a text file in Java, but I am not familiar with Python at all. Could you point me in the direction where I can find a code that reads the values from the mcu and stores it in a text file?

Also does this mean that we will have two programs (java and python) running at the same time?

April 21, 2011
by Ralphxyz
Ralphxyz's Avatar

Sorry, I do not know Python enough to have a library yet, but what you need is out there.

Yes you would have two distinct programs running, if you are using windows they might be called services, but they will be running in the background simultaneously. Or they coud run off a chron and run separately on a schedule.

Since you are familiar with reading a text file with JAVA think the Python part will be easy.

Google, Google, Google.

Ralph

Post a Reply

Please log in to post a reply.

Did you know that one NerdKits customer discovered that his hamster ran several miles in a night using his kit and a Hall-effect sensor? Learn more...