header img
     
 


Networked Lamp (PIC):

This entry describes how to connect a Lantronix Cobox-Micro to a Java server over a local area network. In this example we use a PIC 18F452 microcontroller, some blue superbright LEDs (http://www.superbrightleds.com Part# RL5-B2430) frosted plexiglass, three RadioShack project boards, and a Sharp GP2D120 proximity sensor to build a lamp that responds when viewers walk up to it.

Figure 1 below shows how the lamp works. When the viewer stands approximately four feet in front of the lamp, the first plexiglass "panel" is illuminated. As the viewer moves closer to the lamp the the second and third panels will eventually become illuminated based on proximity. At close inspection (a few inches) all panels are illuminated. In addition to responding to distance through these physical cues, the lamp is also connected (through the Cobox) to a Java server running on another machine. User proximity causes the lamp to send different messages to the Java server. In the context of this project other "networked-furniture" is also sending and receiving messages to the Java server in the same manner. The idea was to make the lamp respond and interact with the user, but also respond and interact to messages coming from other networked furniture objects. It is particularly interesting to think about the parallel "behavior" that can result from messages related the interaction to furniture that is being used in a remote location.

Pic and Cobox Configuration:

The PIC breadboard and Cobox configuration were similar to a previous project. However, for this project we used only one cobox that automatically logged into the Java server running on ITP's internal network. A summary of the configuration we used for both coboxes is as follows:

A summary of the configuration we used for both coboxes is as follows

IP address: as given to us by the network administrator
Gateway address: as given to us by the network administrator
Netmask (number of bits for host port): 8 (equates to 255.255.255.0)
Channel 1 settings (main menu item1) This configures how serial port 1 will work, and how you'll connect to it from the net:
Baudrate: 9600
I/F Mode: 4C (sets the various baud mode bits; see manual for details)
Flow: 00
Port No: 10001 (or whatever other port number you choose)
Connect Mode: D4 (auto-connect, and send chars C or N indicating the Cobox's connection status)
Remote Address: in this case we used the IP address of ITP's network followed by the specified port number (i.e. 128.121.151.21 10002). Programs were called "FurnitureServer.java" and "ClientThread.java".
Remote Port no.: 10002 i.e. the port number to connect to on that remote machine
Disconnect mode: 00
Flush Mode: 77
Disconnect Time: 00:00
SendChar1: 00
SendChar2: 00

Connecting the PIC to the Cobox

Figure 3 shows how the PIC is connected to the Cobox. In this example a hex inverter is used to amplify the signals coming from the PIC. Eleven LED's are wired in parallel for each panel. We used superbirght blue LEDs which have an intensity of about 2400 mcd (at 20 mA) and a viewing angle of ~ 30 degrees. Each of the three LED boards was connected to the PIC on portc.1,portc.2, and portc.3. Figure 2 shows an example of the lamp with the lights turned off.


networked lamp

Figure 1 - Lamp is activated using a infrared proximity sensor


lamp in dark

Figure 2 - View of the lamp with the room lights off.


cobox breadboard 3

Figure 3 - Breadboard, LED prototype boards, and Lamp base.

''****************************************************************
'* Name : lampclientfinal.BAS *
'* Author : Inshan Khairullah, Jason Babcock, Steven Oh, Limor Garcia*
'* Notice : Copyright (c) 2004 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 10/14/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
' Initial Code supplied by
' By Tom Igoe, 2004

' Serial out is on pin RC6
' serial in is on pin RC7
' an analog sensor is on pin RA0

DEFINE OSC 4

' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE CCP2_REG PORTC 'Hpwm 2 pin port
DEFINE CCP2_BIT 1 'Hpwm 2 pin bit

' variables and constants for the serial port: 
tx var portc.6 ' transmit pin
rx var portc.7 ' receive pin
exitpin var portb.7

ledset1 var portc.1
ledset2 var portc.2
ledset3 var portc.3

debugr var portc.5
debugt var portc.4

input debugr
INPUT exitpin

output ledset1
output ledset2
output ledset3

exitpin = 0

non9600 con 16468 ' baudmode for serin2 and serout2: 9600 8-N-1 non-inverted

inputMaxLength con 96 ' max. input string
nameMaxLength con 20 ' max name string
cmdMaxLength con 10 ' max command string
asciiSpace con 32 ' constant for ascii SPACE character
lf con 10 ' constant for ascii linefeed character
cr con 13 ' constant for ascii carriage return character

i var byte ' counter
flag1 var bit
flag2 var bit
flag3 var bit
inputArray var byte(inputMaxLength) ' input strung from cobox
nameArray var byte(nameMaxLength) ' name of person who sent to us
cmdArray var byte(cmdMaxLength) ' command string they sent us
nameLength var byte ' length of their name
cmdLength var byte ' length of the command
chunkCursorPos var byte ' array pointer
currentChar var byte ' array pointer
dataByte var byte ' used when we just want one byte
distance var word
speed var word

dutyCycle var byte ' Duty cycle for PWM

clear ' clear all variables

'variables for ADC:
ADCvar var word ' Create variable to store result
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result

Pause 1000 ' Wait a second at startup


login:
serout2 debugt, non9600, ["doing login", lf]
' wait for an ascii C, signifying a connection.
' this assumes you're in autoconnect mode (ConnectMode D5)
while dataByte <> 67
serin2 rx, non9600, [dataByte]
serout2 debugt, non9600, ["waiting for connect", lf,cr]
wend
pause 100
' wait until the intro text is past. It ends with a > and a linefeed:
serin2 rx, non9600,[WAIT(">"), dataByte]
pause 100
' send your login
serout2 tx, non9600, ["login lampy", lf]
serout2 debugt, non9600, ["Logged in", lf,cr]

main:
gosub check


goto main

check:
GOSUB exit_server
gosub ir_mode
'serout2 debugt, non9600, ["doing check", lf]
'serin2 rx, non9600,300,check, [STR inputArray\96\lf]

return
' ir_mode:
' adcin 0, adcvar
' dutycycle = adcvar/4
' serout2 debugt, non9600, ["ir_mode: ",dec4 adcvar, lf]
' 'pulseout ledset1,dutycycle
' hpwm 1, 255, 32767
' return

'ir_mode:
' adcin 0, ADCvar
' if adcvar < 5 then
   ' serout2 debugt, non9600, ["ir_mode: ",dec4 adcvar, lf]
   ' serout2 tx, non9600, ["send all ir_mode: ",dec4 adcvar, lf]
' endif

return

ir_mode:
adcin 0, adcvar

if adcvar > 24 then
  serout2 debugt, non9600, ["In range",dec4 ADCvar, lf,cr]
if flag1 = 0 then
  serout2 tx, non9600, ["send all someone approaching me",lf,cr]
  flag1 = 1
endif 

high ledset1
adcin 0, adcvar 'get it again 
if Adcvar > 125 then
  high ledset2
if flag2 = 0 then
  serout2 tx, non9600, ["send all someone draws closer",lf,cr]
  flag2 = 1
endif
 
if adcvar > 400 then
  if flag3 = 0 then
    serout2 tx, non9600, ["send all someone is real close",lf,cr]
    flag3 = 1
  endif 
  high ledset3 
else 
 low ledset3
endif 'end set 3 conditional
else
 low ledset2
endif

else
 low ledset1
 flag1=0
 low ledset2
 flag2=0
 low ledset2
 flag3=0
 serout2 debugt, non9600, ["Out of range", lf,cr]
endif 'end range condtitional

return

'lights:

'return

exit_server:
if exitpin = 1 THEN
  serout2 debugt, non9600, ["send all exit ", lf]
  serout2 tx, non9600, ["send all exit ", lf]
  serout2 tx, non9600, ["exit ", lf]
endif
exitpin = 0

return
 
     
  Copyright © 2006 Jason Babcock. All rights reserved. Valid CSS   Valid XHTML 1.0