Issue
149 December 2002
Wireless
Temperature Sensor Stew
AMULET’S
EASY GUI
Thank
you, Tom Cantrell. I remembered a piece that Tom did
covering the Amulet Easy GUI ("Liquid Crystal Delight,"
Circuit Cellar 132). If I could use the Amulet device,
I may be able to pull off this whole conversion thing.
A
couple of hours after receiving a 5.7 version
of the Easy GUI touch display, I was using Macromedia’s
Dreamweaver to design my new rfPICDEM1 user interface.
The Amulet device used in conjunction with a web-authoring
program like Dreamweaver becomes a web site you can
literally hold in your hand. Generating the GUI code
was as simple as copying from the Amulet widget library
and pasting to my Dreamweaver design page.
After
I generated my first GUI on the Easy GUI device, things
started to come together. The Easy GUI interfaces to
a server via a standard serial port configured as data
communications equipment (DCE). In your case, that server
will be a PIC16F877.
Using
the PIC16F877 and a simple Sipex232 IC, I can interface
to the Easy GUI using the PIC16F877’s internal UART.
Also, I just happen to have a Microchip MPLAB-ICD in-circuit
debugger (ICD) and an MPLAB-ICD demo board that can
host a PIC16F877. Using the ICD, I can port the rfPIC
transmitter code to the PIC16F877 and develop the Amulet-to-PIC
GUI interface without having to touch the rfPIC12C509AG
or cut traces on the rfPICDEM1 transmitter PCB.
The
Easy GUI’s DCE serial interface expects to see a DTE
interface at the other end. The same is true for the
MPLAB-ICD demo board’s serial interface. So, the first
order of business is to convert the MPLAB-ICD demo board’s
serial interface from DCE to data terminal equipment
(DTE). By performing that action, I can eliminate the
need for special crossover cables or null modems between
the ICD demo board and the Easy GUI.
Just
in case I need to switch the ICD demo board’s serial
interface back to DCE, I installed a mechanical multiplexor
(i.e., a DPDT slide switch). The multiplexor simply
swaps pins 2 and 3 of the demo board’s RS-232 interface
in relation to the PIC16F877’s UART RX and TX pins,
depending on which set of DPDT switch poles are made.
A graphical representation of the mechanical multiplexor
is shown in Figure 3.
|
|
|
Figure
3—There seems to be a bunch of "X’s"
in this month’s column. Anyway, this simple scheme
swaps the transmit and receive lines at the connector.
Because the Amulet Easy GUI and MPLAB-ICD serial
ports don’t care about the other modem signals,
this arrangement works fine.
|
After
I was able to connect the PIC16F877’s serial interface
to the Easy GUI’s serial port, I inserted my Frontline
Test Equipment Serialtest Async datascope in the line
to make it easier to see what the PIC16F877 and Easy
GUI were saying to each other. My switchable DTE/DCE
MPLAB-ICD demo board is populated in Photo 3.
|

(Click
here to enlarge)
|
Photo
3—Adding parts to this MPLAB-ICD demo board wasn’t
the only thing I had to do to get my ICD up to par
for this project. I also had to upgrade the firmware
on the MPLAB-ICD module. If you have a down-level
ICD, just search ETNs on the Microchip web site.
ETN #21 tells you how to perform the upgrade. |
For
the touch display conversion, I used the Amulet function
button and numeric-field and string-field widgets. The
widgets and associated HTML all combined to produce
the touch-sensitive display rendering what you see in
Photo 4. The Test Tone button is an Amulet function
button widget set for Toggle mode and inverted display.
When you touch the Test Tone button, it will invert
and remain in that state until you touch it again.
|

(Click
here to enlarge)
|
Photo
4—The Amulet Easy GUI is a touch-driven, hand-held
web site that you can get up and running with little
or no HTML experience. The Test Tone button is shown
in toggled mode. |
The
first touch of the Test Tone button initiates an event
that sends 3 bytes of data (0x14, 0x30, and 0x31) to
the PIC16F877 server via the serial connection between
the two. The 0x14 is the Amulet client-invoke remote
procedure call (RPC) command with 0x30 and 0x31 representing
01 or routine 01.
All
of the communications between the Amulet client and
server are in ASCII format with the exception of the
Amulet commands. The server—the PIC16F877 in this instance—has
200 ms to reply with three bytes: 0x24, 0x30, and 0x31.
If the PIC16F877 server misses the response window,
the Easy GUI times out and continues. The server should
always reply to a command or unexplained things may
happen. If a code or command is not understood or supported
by the server, it should respond to the Amulet client
with a 0x10. The Amulet client does not resend commands
under any circumstance.
The
RPC routine number can be from zero to 255. The server
uses these routine numbers to select and run a particular
set of code. For instance, Listing
1 responds to the RPC call initiated by the Test
Tone function button’s initial touch. The 01 (0x30 and
0x31) sequence is parsed by the PIC16F877 operating
code and ultimately runs code that turns on the rfPIC’s
transmitter and sets the transmit data pin high. A second
touch of the Test Tone button sends a command that invokes
routine 02, which turns off the rfPIC’s transmitter
and sets the transmit data pin low.
Touching
the Set Station ID function button invokes routine 03,
which increments the station ID variable and transmits
three station ID messages, while the Send Temp function
button tells the PIC16F877 server to take a temperature
reading and transmit it as a normal message three times.
Listing
2 is the Amulet HTML and PIC16F877 server code that
creates the Fahrenheit and Celsius temperature Easy
GUI display fields. The Fahrenheit temperature reading
is updated every 65 s, while the Celsius temperature
is read and updated every 60 s. Temperature data from
the Microchip TC74 is supplied as 8 bits of Celsius
temperature data in 2’s complement format. Thus, a temperature
reading of 0xFF is interpreted as –1°C.
The
Get_The_Temp() function reads the TC74 and performs
the necessary calculations to produce both a Celsius
and Fahrenheit ASCII temperature value that’s passed
to the Amulet Easy GUI display. The unprocessed 8-bit
temperature reading from the TC74 is saved so it can
be transmitted as the receiver does its own display
conversions on the received data from the remote transmitters.
I
initially tested the temperature code and applet HTML
using a punched-in number. When it came time to put
the actual hardware to the test, I realized that because
the rfPIC transmitter temperature sensor was running
at 3.3 VDC and my MPLAB-ICD system was running at 5
VDC, I ran the risk of letting the smoke out of my rfPIC
transmitter’s 3.3-VDC TC74 temperature sensor if I drove
the TC74 from the PIC16F877.
Because
I didn’t have any spare TC74s and I wanted to limit
my soldering activity, I opted not to test the 5-VDC
tolerance of the 3.3-VDC TC74’s I2C pins. The alternative
was to build up an alternate 3.3-VDC PIC16F877 board
with a 3.3-VDC RS-232 converter or find another board
with a 5-VDC TC74 on it. I didn’t want to build up anything
for this project and, as luck would have it, I didn’t
have a PIC16LF876 to retrofit my MPLAB-ICD for use with
PIC microcontroller targets running a VCC below 4.5
VDC.
Fortunately,
I recently received a PICDEM2 PLUS board, and what do
you know, that funny-looking five-pin device on the
new PICDEM2 PLUS board just happens to be a 5-VDC TC74.
To gain access to the MPLAB-ICD’s PIC16F877 pins, I
added some header pins to the MPLAB-ICD. In addition,
I ran a couple of wires from the TC74’s sda and sclk
pins to the correct set of the newly installed PIC16F877
header pins. It was a kludge with a common ground, but
it worked; it only took a few solder joints, and I didn’t
have to design a thing. My PICDEM2 PLUS, complete with
the TC74 tap, is depicted in Photo 5.
|

(Click
here to enlarge)
|
Photo
5—In addition to borrowing the services of the on-board
5-VDC TC74 temperature sensor, I also "bogarted"
the PICDEM2’s 4-MHz oscillator for use on the MPLAB-ICD
demo board. The PICDEM2 is really designed to work
with the legacy MPLAB-ICD (PIC16Fxxx parts) and
the new MPLAB-ICD2 (PIC18Fxxx parts). |
The
station ID value indicator at the bottom of the display
is an Amulet numeric field widget that requests the
station ID value from the PIC16F877 server every 2 s.
Note the numeric field applet’s min, max, minFld, and
maxFld fields in Listing 3. Station
IDs are mapped one-to-one—min to minFld and max to maxFld—because
the minimum value for a station ID is zero, and the
maximum station ID value is seven.
The
min value corresponds to the minFld value (i.e., if
the minimum value returned from the invocation of the
station ID RPC is zero, then it’s mapped to the minFld
value of zero). The same is true for the max and maxFld
fields, because a maximum returned value of seven maps
to the maxFld value of seven.