Shop OBEX P1 Docs P2 Docs Learn Events
Sending data to Java program? — Parallax Forums

Sending data to Java program?

RatatoskrRatatoskr Posts: 12
edited 2008-05-29 20:34 in BASIC Stamp
Hi everybody, I apologize for asking n00b questions, but what can I do?

I'm working on a school project that involves connecting a guitar to a computer with software that will read notes and such (for a Guitar Hero-esque game, except with an actual guitar as the controller). We're either going to have to use a stock Roland GK-2 synth setup and then convert MIDI files into data that we can use or we need to read pickup voltages with a Stamp (plus some damping circuitry...) and send them to a separate Java application running on the computer.

My question is how to send data from a Basic Stamp unit to said Java application as they both run. What's the hardware/software interface that I'd need? For this project, the sampling rate would have to be every 1/4 second at least (for eighth notes at 120 bpm).

I probably just fail at using the forum search function, since sending data between the Stamp and a separate program running on the computer seems like a fairly basic task (these people did it: http://www.parallax.com/tabid/498/Default.aspx), but I haven't found any pointers on how it's done. If someone could point me to some resources, that would be really appreciated.

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2008-05-09 19:34
    Typically you open a serial port in Java on the PC, then connect that to the 'programming' port on the BS2.

    The BS2 can send to its programming port with:

    Main:
    SEROUT 16, 16384, [noparse][[/noparse]"Hi there!", CR]
    PAUSE 2000
    GOTO MAIN

    The "16384" is the "Baud Mode" value you need to do 9600 baud. So, on the Java port, you'd open it at 9600 baud.

    Now you just have to add the code to read the value from the guitar -- which I have no idea how to do, sadly. Well, not NO idea -- you could use an A to D converter, or an op-amp interface. But figuring out what "note" was desired might be difficult.
  • RatatoskrRatatoskr Posts: 12
    edited 2008-05-10 14:37
    Thanks!

    I'll have to learn some more Java, but that can't be too tough... I'll let you know how it goes, I'm sure I'll run into plenty of snags. ^_^
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2008-05-10 15:15
    You will be looking for javax.comm packages or the latest alternative software to support your computer's RS-232 port.

    For some reason that I cannot really fathom, JAVA has faded in and out on supporting these serial ports of one's computer. It may have something to do with a conflict between Sun and Microsoft in which Windows wants to dominate all low-level i/o services. I say that because it appears easier to do in both Linux and Solaris.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PLEASE CONSIDER the following:

    Do you want a quickly operational black box solution or the knowledge included therein?······
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • whirlymarkwhirlymark Posts: 10
    edited 2008-05-13 02:16
    You might want to look at the open source processing.org language at www.processing.org . This software has a lot of users out there interfacing microcontrollers to this software. Many use Arduinos but it is not a major leap to use the BS2 to interface with processing. The advantages are that there is a processing forum of artists that use these interfaces to link to computers including "sound" artists.
  • voodoofishvoodoofish Posts: 67
    edited 2008-05-15 00:06
    If you are going to be learning java, I recommend this book.
    http://www.mindview.net/Books/TIJ/

    It's a free download and it explains concepts clearly and in detail.
    It's slightly dated, but the concepts are the most important details that you'll be pulling from this doc.
  • RatatoskrRatatoskr Posts: 12
    edited 2008-05-28 20:38
    I got this to work mostly, with rxtx. My current issue is that I'm not getting Java to accept multiple outputs. If I reset the stamp, it doesn't trigger the DataAvailable event again. Any ideas?

    Is resetting the Stamp making Java lose the port somehow? If so, I could deal with that.

    EDIT: my code was closing my own InputStream.

    Thanks for the previous help, folks! I'm pumped, this project might just work out sort of!

    For anyone else trying to do Java serial communication, rxtx.org (the gnu.io package) works pretty well.

    Post Edited (Ratatoskr) : 5/28/2008 8:57:54 PM GMT
  • rotary9krotary9k Posts: 26
    edited 2008-05-28 22:11
    Ratatoskr,

    I'm trying for a similar application, except it is the other way around. The java application sends information to the stamp controller, while the stamp controller just awaits data.

    Was rxtx very easy to get working? I was looking at simpleserial which seems easy as well.
  • RatatoskrRatatoskr Posts: 12
    edited 2008-05-29 20:34
    Never heard of simpleserial, so I wouldn't know.

    RXTX is working well for me. I used en.wikibooks.org/wiki/Serial_Programming:Serial_Java for most of the code.

    It took me the time to copy a few files into the proper folders, read that wikibooks page, copy+paste+mod the code. Pretty easy if you subtract the time spent getting Java and Netbeans (for some reason I computer I was using had about half of Java) and missing important lines of code like adding the listener, setting the port to notify, and not closing my stream while I was waiting for more data. That wikibooks page makes it pretty easy if you pay attention and don't do silly things.


    EDIT: oh, and I needed to use baudmode 16468 on the Stamp for 9600 in Java, IIRC. Currently I'm using 84, which is equivalent (I think). It works.

    Post Edited (Ratatoskr) : 5/29/2008 8:39:29 PM GMT
Sign In or Register to comment.