After finishing the multimeter project and seeing some

other creations from
Xander S. and
Andy M., I thought we had used the
Mindsensors’ PowerMeter to its limits : reading voltage/current, logging it or displaying it graphically. However, during a walk on the beach, it dawned on me: this is not ‘just’ a power meter, it is
the sensor of all sensors, the must-have for all Robotics and Electronics fanatics. With the PowerMeter extending the NXT with a special sensor becomes a no-brainer. Most electronic sensors work by varying voltage or current. The PowerMeter is actually a generic
A/D converter for the NXT which allows you to quickly and safely interface your home-made sensor to the NXT. It is even a bit more than that, since it has a built-in timer you can use as well and in this example we will. Measuring distance, temperature, humidity, … all becomes easy with the PowerMeter.

Once I realized this, I was up for a new challenge. To keep the electronics simple, I made a light sensor for the PowerMeter with a photodiode and a resistor. As transmitter I use a simple flashlight. The circuit shown here is not very critical. In fact I left out C2 and R4. I first used the multimeter program from the previous project and learned that -depending on the surrounding light- the ‘dark’ value was 1350 mV, the ‘light’ value was 20 mV. I decided to use 20% of the dark value as threshold between light and dark.
Instead of using the RobotC drivers, which I created for my previous PowerMeter project, I wanted to use
LeJOS for this one. LeJOS is a Java Virtual Machine for the NXT. Java promises cross-platform portability ("Write Once, Run Anywhere") and this is partially true. LeJOS allows to create programs in Java that run entirely on the NXT, partly on the NXT and partly on the PC or completely on the PC. This means that instead of needing different programming environments if you want to communicate between NXT and PC, all can be done from the same environment. However, there is a catch. Some parts of LeJOS are very sophisticated, while other parts are very basic. Most notably, LeJOS has no IDE. It is all command line based and even the firmware for the NXT has this same basic look-and-feel. Most of this is not a real issue and you can use your preferred development environment. For me that is
Eclipse.
First I created a new Java class ‘PowerMeter’ that contains all

the code to interface with the sensor. This class is the basis for all other programs. I must admit that interfacing with I²C turned out to be very simple in LeJOS. Then I rewrote the multimeter program in Java as proof-of-concept. Now was the time for the real work. Several hours, crashes and lots of coffee later, the Morse decoder was born. The usage is simple. First you learn the NXT what a ‘short flash’ and a ‘long flash’ is. Then the NXT starts waiting and every time a short pulse is received it takes is as a DOT, a long pulse as a DASH. Once a full character is received –
the end of a character is denoted a dark period equal to 3 short pulses in time - the character is decoded using a simple lookup table.
The code is available
here.
0 comments:
Post a Comment