Skip to main content

Learning to program with peripherals

13 replies [Last post]
jasonbe
Offline
Joined: 2008-10-24

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mthornton
Offline
Joined: 2003-06-10

If you just want to be able to control something 'real' with Java one possibility is a model railway. Have a look at the JMRI project http://jmri.sourceforge.net/ and for a cheap hardware interface http://www.sprog-dcc.co.uk/
The sprog interface is only one way (no feedback from the devices), but other systems can provide two way information.

The motors, lights and other features in each train a managed by a microcontroller (as little as £10 each). Although intended for model railway control, these devices could be fitted in other systems.

Later: Actually the SPROG can read back information from the microcontroller in programming mode. This allows the registers on the device to be read and modified (there can be dozens of such registers). With JMRI this is all done in Java.

Message was edited by: mthornton

jasonbe
Offline
Joined: 2008-10-24

mthornton, that’s a really good idea. (I’ve seen some really good ideas looking through the posts, and I’m still looking through all of the links provided for code that reads a peripheral!) Do you know if the code for the microcontroller that you mentioned would work with any microchip? It is mostly the code that I’m interested in - because I already have a microchip with potentiometers and switches. Once I find and modify a code - to make this code able to read information from this microchip, then I can modify all of my Java homework assignments to read these potentiometers and switches. I should probably have specified that this microchip is connected via a USB port.

mthornton
Offline
Joined: 2003-06-10

Current versions of the SPROG are connected via USB. I think the USB connection hardware takes the form of a USB to serial to converter followed by a basic PIC controller. It may be that your device is similar. If so an inspection of the JMRI code might yield some ideas.

jc
Offline
Joined: 2003-06-11

You might want to look at Phidgets http://www.phidgets.com/ which provides switches, knobs, RFID readers etc and provides a Java API. Or if you don't mind getting your hands dirty doing a bit of electronics, try Arduino Diecimilia http://www.arduino.cc/ which is a micro-controller board which is programmable in the Processing environment http://www.processing.org/ which is based on Java.

jasonbe
Offline
Joined: 2008-10-24

Note: as of now, there are no more than 13 new replies to this post.

psynixis
Offline
Joined: 2005-04-26

Jason - I suspect that learning to program a computer by using things like switches and pots attached to a computer via some microelectronics isn't going to work well for you. There are a bunch of technical reasons for this that I won't go in to. Suffice to say - going this route is going to make life difficult for you because it doesn't work like you think it works.

If you want to learn Java in a "hands on" way, I'd suggest you take a look at BlueJ. It's designed to let people learn Java programming in an interactive way by experimenting and exploring the BlueJ environment.

http://www.bluej.org/

jasonbe
Offline
Joined: 2008-10-24

psynixis, Thanks. I looked through the Chapter sequence of “Objects First with Java A Practical Introduction using BlueJ.” Though I couldn’t understand everything that was written, I didn’t find anything about peripheral programs – or peripheral example code – which is what I am looking for. For school class – and I am a first year student, we are using “java Software Solutions” by Lewis & Loftus. I may not have communicated clearly. For anyone who may be reading this, my goal is not to focus on peripherals, but to learn how to read a couple of analog output pins on a USB development board. Actually, I don’t even need to learn how to develop a program to read a peripheral now. I am just looking for a code that I can dissect that has a couple variables that can read my peripheral. That way, I can use these variables in programs that are on my level of developing – which is my goal.

jeeky
Offline
Joined: 2003-06-15

Unfortunately, I have to agree with p3aul. I am a hard core Java programmer and have been for several years. However, Sun's support for common USB devices such as digital cameras, scanners, and so on is very disappointing, to put it mildly. The USB API implementations out there are pathetic. If you really want to interface with and control hardware that doesn't come with a vendor provided API, I'd have to recommend C#, despite the fact that you are stuck on Windoze. The reality is that it's better to have an API that works on one platform than one that doesn't work at all.

jasonbe
Offline
Joined: 2008-10-24

jeeky, maybe you’ve come across a Java program that can read a USB peripheral with switches or knobs? Most of the sources that I’ve read confirm what you are saying – that, at the present level of development, Java does not have a lot of support for peripherals. However, I am just looking for one Java program that I can modify to give me access to different outputs on my USB development board. That way, I can use the variables - in a premade program that I am hoping someone will refer me, while creating many different programs for my peripheral. For example, is there a program that replaces the cursor - that Windows shows to identify the location of a mouse, with a picture that is specific to this program? If so, does this program enumerate microchip pins in the mouse? Or, what about a Java program for a game that reads joystick data? Is there anything specific about these types of code that would prevent me from modifying these codes to read my peripheral? I am familiar with some of the USB protocol, so I might be able to interpret any peripheral code that you can refer me to with the page at http://jusb.sourceforge.net/apidoc/usb/core/package-summary.html - which contains information that you are likely already familiar with. If you know of too many codes to list, the simpler ones would be easier for me to use!

back_ache
Offline
Joined: 2008-11-03

As Java's USB implementation sucks(and maybe always will), why not use an ethernet development board instead.

ethernet seems to be the future of connecting random things together and something java can do right now.

p3aul
Offline
Joined: 2008-10-23

Hi !
Welcome to the Forum. I'm going to be kind and answer your post, because no one here probably will.(See my last post, "Java") This is probably not going to be the answer you expect, but it's all I have. If you are a beginning programmer, don't start off with java. It's very convoluted and it's statements and syntax don't make a whole lot of sense. Try Delphi or C# instead. If you are going to be programming just for the web, PHP or javascript is a good one. Javascript is not like Java. It makes more sense. you can use PHP to access the server also. Perl is good also but harder to learn.
Good luck
Paul

jasonbe
Offline
Joined: 2008-10-24

Thank you, P3aul. Java is what they are teaching in school at my level - and what I have to learn. So, if by a chance that is odd or favorable, anyone knows of any example public domain program code - for peripherals with potentiometers and/or buttons, that I can search through to try and find variables that were declared and defined by the peripheral, this would still be helpful. The simpler the code, the better. Based on your response, I don't expect anyone to point these variables out to me. However, this would be helpful. And someone at school might be able to point these variables out if the code was provided. I was thinking that this post might belong under Global Education and Learning because it address the needs of students with different learning styles.

Message was edited by: jasonbe

kschneid
Offline
Joined: 2003-06-10

I don't really do much device/peripheral stuff myself, but a couple things jumped to mind:

LeJOS: http://lejos.sourceforge.net/
Sun SPOT: http://www.sunspotworld.com/

I wouldn't expect to see "variables that were declared and defined by the peripheral", but rather something more like event listeners. In other words, you register some code with the peripheral and that code gets called back when an event happens (e.g. button press).