11

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.

Toby Jaffey
  • 28,796
  • 19
  • 96
  • 150
sterz
  • 233
  • 1
  • 3
  • 7
  • 31
    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!" – darron Dec 15 '10 at 20:44
  • 8
    I'm having trouble visualizing the floaty skirt car with sticks. Do you have any pictures? – endolith Dec 15 '10 at 22:11
  • 8
    @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)? – Kevin Vermeer Dec 15 '10 at 22:27
  • 2
    @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. – darron Dec 16 '10 at 02:10
  • 1
    @darron: thanks for the "shooting birds with a cannon" analogy – sterz Dec 17 '10 at 10:59
  • In spite of my skepticism towards embedded Java, I just found out that the AVR32 has a partially hardware-based JVM and felt compelled to add it to this question - See their [Java Technical Reference](http://www.atmel.com/dyn/resources/prod_documents/doc32049.pdf) – Kevin Vermeer Jan 26 '11 at 14:34
  • 1
    What you are trying to do? MCUs are programmed in C, maybe C++. There are exceptions at least in the hobbyist community, but basically people program MCUs in C. "I don't want to learn how to program it" is not the best excuse; I wouldn't be surprised if trying to find and bootstrap a theoretically usable JVM is more time and trouble than learning C and building the product. Depending on what you need it may be quite easy to learn, with micros you don't even want to allocate so you may be able to punt on memory management - one of the greatest spectres of coming to C from a GC'd language. – Suboptimus Nov 10 '11 at 23:47
  • I wonder if there is a posibility to burn Java card(tm) to an AVR – drzymala Jul 15 '12 at 21:40

11 Answers11

35

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 (Wayback machine link) 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.

user13267
  • 599
  • 2
  • 9
  • 24
Kevin Vermeer
  • 19,989
  • 8
  • 57
  • 102
8

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).

Toby Jaffey
  • 28,796
  • 19
  • 96
  • 150
  • 4
    To be more precise, it is (most likely) the most popular programming environment with hobbyists, but not necessarily over all AVR developers. – pfyon Dec 15 '10 at 20:31
  • 2
    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 – Toby Jaffey Dec 15 '10 at 20:36
  • 1
    Although "sketches" are compiled, IO access speed can be greatly improved using C or assembly. – tyblu Dec 15 '10 at 21:13
  • 1
    C++ and Java look very different to me. ("Arduino" is *just* C++ with some bizarre include structure to hide some of the technical bits.) – Nick T Dec 15 '10 at 21:50
  • 1
    @Nick similar in the sense that it's all Algol-like http://en.wikipedia.org/wiki/Comparison_of_ALGOL_68_and_C%2B%2B#Comparison_of_the_assignment_and_equality_operators Java and C++ are much closer to each other than either are to BASIC or assembly – Toby Jaffey Dec 15 '10 at 22:05
  • but I cry over it's lack of pointers. – Nick T Dec 15 '10 at 22:16
  • -1. C++ is not almost distinguishable from Java. It's a small but important point and I'm glad to remove my downvote if you can edit to clarify in a way that sounds less misleading. – Jason S Nov 09 '11 at 22:31
  • 2
    @Jason S "Arduino "sketches"/programs appear very similar to Java" – Toby Jaffey Nov 09 '11 at 23:45
  • Here's my objection in more detail. C++ and Java and Javascript and several other languages are all very similar syntactically: `foobar.functioncall(argument)` is a common method call among all of them, and as you mention correctly, share operators, loop constructs, and `{}` for statement delimiters. But syntax and these basics are perhaps only 10% of the knowledge needed to use a language. Then you have idioms: things in C++ like #include files and memory allocation and operator overloading; or in Java like packages and interfaces and annotations. The other 90% mastery is quite different... – Jason S Nov 10 '11 at 00:41
  • ...also including library differences, tool differences, and other nuances (C's "unsigned" and C++'s multiple inheritance are absent in Java; Java's built-in String handling features are absent in C) So if you said the syntax for C++ and Java were similar, I could buy that (vs. comparing Java and Haskell or Python or Scheme), but the *languages* in practice are very different. Not hard to get started, but the language-specific experience in one language won't get you that far in the other. – Jason S Nov 10 '11 at 00:50
  • 1
    "Arduino "sketches"/programs appear syntactically very similar to Java" – Toby Jaffey Nov 10 '11 at 08:49
  • The true path to enlightenment is to encourage the guy to learn C, not seek out a slightly different type of sledgehammer for each type of nut encountered. – John U Mar 05 '13 at 14:04
4

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!

Dave
  • 3,800
  • 24
  • 41
4

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.

vicatcu
  • 22,499
  • 13
  • 79
  • 155
  • ah yes, I saw that at the Maker Faire two years ago! Pretty cool device. – Dave Dec 15 '10 at 21:28
  • 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. – Thorbjørn Ravn Andersen Apr 09 '11 at 16:13
3

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!)

Connor Wolf
  • 31,938
  • 6
  • 77
  • 137
2

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.

Tim Williscroft
  • 1,702
  • 11
  • 11
  • '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. – darron Dec 16 '10 at 01:52
  • 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. – darron Dec 16 '10 at 01:59
  • 1
    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. – Kevin Vermeer Dec 16 '10 at 17:17
  • @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. – darron Dec 18 '10 at 03:26
2

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.

webclimber
  • 131
  • 2
1

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.

Toby Jaffey
  • 28,796
  • 19
  • 96
  • 150
1

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

Gordon Williams
  • 1,023
  • 4
  • 11
  • 17
1

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.

Chris Stratton
  • 33,282
  • 3
  • 43
  • 89