10
\$\begingroup\$

My hardware team is planning to use an Atmel AVR 8-bit microcontroller for a future project.

So far as I know, it must be programmed in C. I have found a JVM for AVR, though it is more limited than the native C libraries from Atmel.

Can you suggest me an 8-bit microcontroller which supports Java?

PS. I don't know C and I am inexperienced in microprocessor programming.

\$\endgroup\$
  • 28
    \$\begingroup\$ Say someone was selling a big floating skirt and some long poles they said you could use with your car to go fishing on a lake. After struggling for three days to put it on, you get about 15 feet into the lake before your car flips over and sinks. You're dad's going to be -really- pissed. You had passed up the local boat shop with a nice canoe. The canoe is the micro's C compiler, and the floaty car with sticks is Java on an 8-bit microcontroller. Luckily, this didn't happen... you're asking us where you can find the floats. So, as your dad, let me say "What are you thinking?! Get a canoe!" \$\endgroup\$ – darron Dec 15 '10 at 20:44
  • 6
    \$\begingroup\$ I'm having trouble visualizing the floaty skirt car with sticks. Do you have any pictures? \$\endgroup\$ – endolith Dec 15 '10 at 22:11
  • 8
    \$\begingroup\$ @darron - Shouldn't that be a big_floating_skirt object which implements the boat interface in the org.buoyant package, and pole objects, which have some sort of weird inheritance pattern with java.net that I can't remember now (but is clearly described in the UML)? \$\endgroup\$ – Kevin Vermeer Dec 15 '10 at 22:27
  • 2
    \$\begingroup\$ @sterz: I think with no microprocessor background it's perfectly understandable that you might have not realized how out of place Java on an 8-bit micro really is. Sorry if my first comment sounded harsh... A simple "Don't do that" seemed way too weak. \$\endgroup\$ – darron Dec 16 '10 at 2:10
  • 1
    \$\begingroup\$ @darron: thanks for the "shooting birds with a cannon" analogy \$\endgroup\$ – sterz Dec 17 '10 at 10:59

10 Answers 10

32
\$\begingroup\$

If you're inexperienced in the microprocessor/microcontroller programming field, you should probably learn C first, so that you can understand when and why Java is a poor choice for most microcontroller projects.

Did you read the restrictions on the JVM you linked? It includes the following problems:

  • As little as 512 bytes of program memory (not KB, and definitely not MB)
  • As little as 768 bytes of RAM (where your variables go. You're limited to 768 characters of strings by this restriction.)
  • About 20k Java opcodes per second on 8 Mhz AVR.
  • Only includes java.lang.Object, java.lang.System, java.io.PrintStream, java.lang.StringBuffer, a JVM control class, and a native IO class. You will not be able to do an import java.util.*; and get all the classes not in this list.

If you're not familiar with what these restrictions mean, make sure that you have a plan B if it turns out that you can't actually do the project with Java due to the space and speed restrictions.

If you still want to go with Java, perhaps because you expect the device to be programmed by a lot of people who only know Java, I'd strongly suggest getting bigger hardware, likely something that runs embedded Linux. See this page from Oracle for some specs to shoot for to run the embedded JVM, in the FAQ of their discussion they recommend a minimum of 32MB of RAM and 32MB of Flash. That's about 32,000 times the RAM and 1,0000 times the Flash of the AVR you're looking at. Oracle's Java Embedded Intro page goes into more detail about the restrictions of the JVM. Their tone of voice is, as you might guess, a good deal more Java-friendly than mine. Be aware that this kind of hardware is much more difficult to design than an 8-bit AVR.

I'm a computer engineering student with a computer science minor. My university's CS department has drunk the Java Kool-aid, so a lot of students in the engineering program come in knowing only Java (which is a sad state of affairs for a programmer, at least learn some Python or C++ if you don't want to learn C...), so one of my professors published a C Cheat Sheet for students with a year of Java experience. It's only 75 pages; I suggest you read or skim it before making a decision. In my opinion, C is the most efficient, durable, and professional language in which to develop an embedded project.

Another alternative to consider is the Arduino framework. It uses a stripped down version of the Wiring language, which is like C++ without objects or headers. It can run on many AVR chips, it's definitely not restricted to their hardware. It will give you an easier learning curve than just jumping straight into C.

In conclusion,
XKCD Golden Hammer
Alt text: Took me five tries to find the right one, but I managed to salvage our night out--if not the boat--in the end.

\$\endgroup\$
  • 5
    \$\begingroup\$ One of my favorite comic strips I have ever enjoyed. \$\endgroup\$ – Kortuk Dec 15 '10 at 19:09
  • 1
    \$\begingroup\$ Mmm, cool-aide. +1 \$\endgroup\$ – tyblu Dec 15 '10 at 19:19
  • \$\begingroup\$ I wonder how that JVM compares with the "Java iButtons" that were available a couple decades ago? \$\endgroup\$ – supercat Jun 7 '13 at 18:17
  • \$\begingroup\$ @kevin "C Cheat sheet" link is not working! Please update! \$\endgroup\$ – charansai Apr 30 '18 at 14:36
6
\$\begingroup\$

The most popular programming environment for the Atmel AVR is Arduino. The Arduino language is a subset of C++.

Arduino "sketches"/programs appear syntactically very similar to Java. The Wiring language which Arduino derives from has implementations in C++ (Arduino), Java (Processing) and Javascript (processing.js).

Both languages share the same declaration style, loop constructs and arithmetic operators due to their common ancestry in Algol68. Typically, all objects in Arduino are declared globally or on the stack, so like Java, member functions are called with the . operator (eg. LED.flash()).

The language will be very familiar to a Java programmer - but, importantly, Arduino sketches are compiled into native code which runs at full speed with full hardware access. This is critical for getting the most from your microcontroller.

Here is the API.

Arduino provides everything you need to get going: low cost hardware, a free integrated development environment and a bootloader (so you can load code over USB/serial).

\$\endgroup\$
  • 3
    \$\begingroup\$ To be more precise, it is (most likely) the most popular programming environment with hobbyists, but not necessarily over all AVR developers. \$\endgroup\$ – pfyon Dec 15 '10 at 20:31
  • 2
    \$\begingroup\$ I'd assert that Arduino is most popular by the number of users, but not by number of product units shipped containing Arduino firmware. There are a lot of Arduino users out there \$\endgroup\$ – Toby Jaffey Dec 15 '10 at 20:36
  • 1
    \$\begingroup\$ Although "sketches" are compiled, IO access speed can be greatly improved using C or assembly. \$\endgroup\$ – tyblu Dec 15 '10 at 21:13
  • 1
    \$\begingroup\$ C++ and Java look very different to me. ("Arduino" is just C++ with some bizarre include structure to hide some of the technical bits.) \$\endgroup\$ – Nick T Dec 15 '10 at 21:50
  • 2
    \$\begingroup\$ @Jason S "Arduino "sketches"/programs appear very similar to Java" \$\endgroup\$ – Toby Jaffey Nov 9 '11 at 23:45
4
\$\begingroup\$

I want to make it clear that I haven't used one before, but there used to be one years ago called the Javelin. It's possible that Parallax has acquired them or something, because now the only one that comes up is the "Javelin Stamp". Years ago there also used to be a company called Velocity Semiconductor, that made a (supposedly) drop-in replacement for Rabbit Semiconductor's core modules, and it had a JVM in hardware, but that company has apparently vanished. Good luck in your search!

\$\endgroup\$
4
\$\begingroup\$

Sun Microsystems used to make a platform called the Sun Spot which was an embedded java platform basically. Now obviously Sun Microsystems is not around anymore (Oracle bought them), but it seems like you can still buy Sun Spots - http://www.sunspotworld.com/products/. I'm not big on the idea of using Java in an embedded environment (wrong level of abstraction for the job imho) but this would seem to be the most natural embedded platform for Java. Note the specs on these things - they are heavy duty 180MHz / 512k RAM, and they are not cheap at $400 for a starter kit.

So I'll be a second or third to the Arduino advocacy responders to this question. There is one hell of a community out there to support you if you need help. And if you need peripheral hardware, look up "Arduino Shields" on google and be amazed - you can do anything from control servo motors to hop on an 802.11 wireless network with the right combination of shields. It's not practical to learn C (pointer says what!?) without some practice time, but you can start writing Arduino sketches in next to no time... You can also get "real" Arduino platforms around $30 and clones (e.g. RBBB or DorkBoard) for under $15.

\$\endgroup\$
  • \$\begingroup\$ ah yes, I saw that at the Maker Faire two years ago! Pretty cool device. \$\endgroup\$ – Dave Dec 15 '10 at 21:28
  • \$\begingroup\$ The killer feature for SunSpots is not Java, but the built in wireless stuff allowing them to communicate with each other. If you want awareness of each other or easy wireless communication with the home base, that is very, very nice. \$\endgroup\$ – Thorbjørn Ravn Andersen Apr 9 '11 at 16:13
3
\$\begingroup\$

Parallax make the Javelin Stamp, a CoM (Computer-on-Module) that runs a JVM.

It's $60 and executes a blazing ~8,500 Java instructions/sec.

Also, the PCB is pink (Really!)

\$\endgroup\$
2
\$\begingroup\$

Ajile systems make a variety of native embedded, real time java chips and eval boards.

They run bare metal java. It's very pleasant.

www.ajile.com make the chips and eval boards.

www.systronix.com sell a variety of embedded java hardware.

I've used AJ-100 from ajile for demanding work, they are very nice to work with. And no, they aren't as cheap as an avr but they process data like a low-end pentium.

Ajiles' chips respond to interrupts (interrupt latency) in under 1 microsecond.

\$\endgroup\$
  • \$\begingroup\$ 'never do that on an embedded C system' ??? Do what? 1 uS latency? High speed? Hardly. I think you're forgetting 1GHz+ DSPs, lots of ARMs, and quite a few others. Plenty of people write for these with just bare metal C (no OS, etc). I will grant you that this type of thing is a halfway rational way to use Java in embedded (outside a full Linux-scale OS)... although after taking a quick look at Systronix I'd say it appears you're paying a good premium for that little convenience. I'd go embedded ARM for sure. Also, a lot of the links to those projects off Systronix are dead. \$\endgroup\$ – darron Dec 16 '10 at 1:52
  • \$\begingroup\$ Oh, and TINI is insanely dumb. JVM in ROM on an 8051. I stupidly tried one way back when I wanted easy Ethernet, and even in C the thing was just swamped by the broadcast traffic of a normal corporate LAN. It'd be a fine product if they marketed it like Parallax's Basic Stamps, but they don't. It's not fit for any non-hobbyist purpose. \$\endgroup\$ – darron Dec 16 '10 at 1:59
  • 1
    \$\begingroup\$ These chips are running at several hundred megahertz. 1uS latency is possible when programmed in C on a processor running 100 times slower than these devices. You can do some pretty cool things (like iPads and Droid phones) with equivalent processors, but posting this as an alternative to the 8-bit AVR in the question is hardly an apples-to-apples comparison. \$\endgroup\$ – Kevin Vermeer Dec 16 '10 at 17:17
  • \$\begingroup\$ @reemrevnivek: Given the OP wanted Java, I'd consider the Ajile part to be appropriate in that it's one of the only reasonable ways to run embedded Java (outside a full Linux OS or something). If the last paragraph and TSTIK bits weren't there I'd even upvote it. \$\endgroup\$ – darron Dec 18 '10 at 3:26
2
\$\begingroup\$

My personal experience is that the C code to program and get started with AVR is pretty easy, I also come from many years of doing java, and after about 2 months of using arduino sketches I dropped the environment and went for avr-gcc, sites like avrfreaks make easy to find answers to common problems. (I still do all on my trusty Arduino Duemillenove)

Using eclipse to compile and "deploy" i.e. write to the chip, is also nice as I don't have to deal with another IDE

I think is actually harder to get your head around registers, 16 bit registers and read them in the appropriate order, interrupts, timers, hardware PWM, than the programming language itself.

\$\endgroup\$
1
\$\begingroup\$

While I'd generally be of the "learn C and understand what processors actually do" camp where embedded work is concerned, it's worth pointing out that a small arm chip is not that much more expensive than an AVR, and is in an almost plausible position to handle simple tasks on top of a jvm.

\$\endgroup\$
1
\$\begingroup\$

NanoVM is a Java Virtual Machine designed to run on 8-bit AVR microcontrollers.

(from the homepage)

It is not a full featured Java VM and it will never be. It will always be limited to a small subset of the java language and the standard java libraries and a few application specific methods. Furthermore, it is not meant to replace C as the standard way of programming microcontrollers. It is less flexible and has a lower performance than C or assembler programs.

The NanoVM is a way to provide a limited but controllable programming interface to a microcontroller based device. With most of the most hardware specific code being part of the NanoVM itself, the user can focus on the application itself. If a user is given a device equipped with the NanoVM he is not required to think about the hardware itself. Furthermore, he doesn't need any target specific compilers or the like. All he needs is a standard java compiler and the NanoVMTool which itself is written in java. Thus, the whole development chain works on any device that has a java compiler and can run java code. With the hardware abstraction the NanoVM provides, the user doesn't even have to care about the microcontroller type the target is based on. The same java compiler and the same NanoVMTool can be used with any NanoVM based system running on any type of microontroller.

\$\endgroup\$
1
\$\begingroup\$

It's not quite Java - or 8 bit, but there is a Javascript interpreter available for low power ARM Microcontrollers called Espruino.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.