uJ – a Java VM for microcontrollers


Dmitry Grinberg wanted to design a way to program MCUs that would be easy for beginners who don’t necessarily understand details of C such as pointers and memory management, yet don’t want to rely on common alternatives such as Arduino or PICAXE. He developed uJ: a Java VM for microcontrollers. “It implements the entirety of the Java bytecode and is written entirely in C, so that it may run on any processor. It has been tested and found functional on 8-bit AVR devices (ATmega64, Atmega128), some Microchip 16-bit PIC devices (dsPIC33FJ128GP802, dsPIC33FJ64GP802, PIC24FJ32GA002), and a few other architectures. It is quite efficient, fast, and usable for actual real-life situations. Minimum requirements? A few dozen K of code space and a few hundred bytes of RAM is all you need to get started.”

For more documentation, another demo video and to download the code visit Dmitry’s website.

Via the contact form.

Join the Conversation

15 Comments

  1. Neat project. And the “binary-tree” keyboard-mode he is using seems to be a quite fast fay of entering alphanumeric data with only a 2/3 buttons. I’ll see if I can find any more information of how it’s done…

    1. I found this keyboard very handy too.

      Here is my quick and dirty implementation in Python (probably unix-only) :

      #!/usr/bin/python

      # dirty unbuffered getch()
      import sys, tty, termios
      def raw_getch():
      setbak = termios.tcgetattr(sys.stdin.fileno())
      try:
      tty.setraw(sys.stdin.fileno())
      ch = sys.stdin.read(1)
      finally:
      termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, setbak)
      return ch

      # binary keyboard, use u and d keys to select the line
      def bin_select(chars):
      while len(chars) > 1:
      upper = chars[0:len(chars)/2]
      lower = chars[len(chars)/2:len(chars)]
      print ''.join(upper)
      print ''.join(lower)

      inp = raw_getch()
      if inp == 'u':
      chars = upper
      elif inp == 'd':
      chars = lower

      return chars[0]

      if __name__ == '__main__':
      chars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
      'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1',
      '2', '3', '4', '5', '6', '7', '8', '9', '.', ',', '-', '_']
      print bin_select(chars)

      1. Thanks… I didn’t see how it actually worked, just that the some letters disappeared at a high rate when he was clicking on the buttons.

        But now when you showed me the algorithm it will be a piece of cake to implement when needed…

      1. Han you seen this somewhere else? A quick google doesn’t give me any results – and my google-fu is usually quite strong…

      2. I thought about two cool improvements that could be made to this input method.

        With two keys, you basically enter the number of the character in binary, so it takes 6 bits or 6 keypresses to choose among 40 characters.
        There is also an improvement that can be made by using 4 keys (up-left, up-right, down-left and down-right). It would be equivalent to entering 2 bits by each keypress, so each letter would need only 3 keypresses which seems to be a nice tradeoff between the number of keys and the speed of typing.

        If the LCD has only 2 lines of text, it’s annoying, because you can’t see what you’re typing. You can use the upper line for printing the string being typed and the lower line for the characters and instead of asking the user “is the character on the upper or the lower line” ask “is the character you want visible on the bottom line” which is really the same.

  2. Nice project.
    BTW. Where can I purchase WEH001602D or any other OLED 2×16 HD44780 compatible display with pins on the side?

  3. An 80KB Java VM??? :-O
    Wow.

    If it had lightweight semi-realtime threading and FAT/SD card support, it’d make a cool RTOS…

    1. Threads execute as close to concurrently as possible (as close as one instruction from each interleaved) You can adjust the time quantum in the code.
      FAT in java is easy
      80KB is large, it can get down to 30KB depending on the architecture and options

  4. For as long as I have been using PICs and that goes back to the first 16C5x parts, and by some strange coincidence, the name “Dmitry” has always been a byword for “genuis.”

    What would be fantastic would be to see this ported to the PIC32. The growing amount of support for this family is really quite amazing and Java would really round out all the options that are now available for it.

Leave a comment

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.