PDA

View Full Version : Sensors Project questions



fresh
03-24-2010, 02:48 AM
Hello all. Pleased to be here. I have a few questions regarding the BASIC Stamp.

A) How do constants (CON) contribute, in terms of their size, to memory use?
B) I want to export data to a spreadsheet and to my personal website. Perhaps one could point me in the direction of some documentation?

I have code regarding the 1st question if anyone wants to see it. It's demo code though, and I know it fits in memory.

Franklin
03-24-2010, 04:07 AM
To dynamically retrieve data from the stamp you need a program that reads the serial port and stores the data to a file. Some terminal emulators do this or you could write something in VB Vc# or python that would do this for you.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

bill190
03-24-2010, 04:15 AM
Try...

Run

Memory Map

(For memory usage - experiment.)

As to exporting to Microsoft Excel (if you are using that), I found a bunch of stuff by searching google.com for the words...

microsoft excel input serial port

http://www.google.com/#hl=en&q=microsoft+excel+input+serial+port&aq=f&aqi=&aql=&oq=microsoft+excel+input+serial+port&gs_rfai=&fp=3582fcc58a84fb8f

rixter
03-24-2010, 04:23 AM
fresh,

Using CON shouldn't increase memory use at all. The PBASIC editor replaces the constant throughout your code with the value you specify in the CON statement. An experiment as bill suggests may reveal this.

Are you aware of PLX DAQ? : http://www.parallax.com/ProductInfo/Microcontrollers/PLXDAQDataAcquisitiontool/tabid/393/Default.aspx

Rick

allanlane5
03-24-2010, 06:40 AM
+1 that you can have any number of "CON" -- they are replaced by the compiler before the code is downloaded into the BS2.

Note that "code check" and the memory map only shows you what the IDE will download -- it doesn't actually read the memory of the BS2.

And yes, typically you'd run a program on the BS2 that uses SERIN/SEROUT like "SEROUT 16, 16468, ["Hi", CR]" to send data to the PC.
Then, on the PC you'll need to run a program to read the serial port.

fresh
04-07-2010, 12:44 AM
To all those who replied: Thank you very much! I got the PLX-DAQ working fairly well; with a little more troubleshooting for the timing I think it will work flawlessly.

What I want to work on now is sending multiple SERINs and SEROUTs. Is there a trick to getting the receiver correctly pick out which message is which? Thanks!

EDIT: I forgot to mention that I'm working with the RF transmitter, which limits message size to 2 words.

Mike: Should I use an if...elseif statement with the different WAITs?

Post Edited (fresh) : 4/6/2010 6:15:54 PM GMT

Mike Green
04-07-2010, 01:10 AM
Regarding multiple SERINs and SEROUTs, commonly you use punctuation and/or prefix information to distinguish between messages. Some I/O devices that use serial communications always expect a message to begin with "!" and this is usually followed by a couple of characters unique to the type of device and the specific message. One example might be "!X01Hello". The "!" marks the beginning of a message. The "X" tells what type of device is being used. The "01" marks the specific type of message and the rest of the data up to and including a CR is the actual message. If a SERIN is being used to receive this, its operands would start with WAIT("!") and the SERIN would ignore everything up to the first "!" received.

fresh
04-07-2010, 01:14 AM
Mike: Would it be a good idea to use an if...elseif statement with the different WAITs?

Mike Green
04-07-2010, 01:36 AM
First, what are you trying to accomplish? What would you be trying to do with IF ... ELSEIF statements?

fresh
04-07-2010, 01:38 AM
I would be putting them in the Receiver's code so that it would determine which message it was receiving and what to do with it. I have the variables for temperature, humidity and compass direction and a checksum that I'm sending over.

Post Edited (fresh) : 4/6/2010 6:43:10 PM GMT

fresh
04-14-2010, 04:27 AM
Okay, I figured out what I was doing wrong. And I used your suggestion to put in different preambles.

Now I need to send data to PLXDAQ and accept incoming data from an RF antenna. The problem is, I can't get PLXDAQ to work with the code for the RF SERIN in the program; I know this because when I remove it, plxdaq works fine. When I leave it in, even if the RF receiver is not receiving data, plxdaq will not work. I would greatly appreciate any and all help with this problem.

Post Edited (fresh) : 4/13/2010 9:50:34 PM GMT

Franklin
04-14-2010, 08:33 AM
Could we see your code as it is now?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

fresh
04-15-2010, 12:47 AM
'--------------------------------------------------------------------------
' {$STAMP BS2}
' {$PBASIC 2.5}

' -----[ I/O Definitions ]-------------------------------------------------

Rx PIN 15 ' Receiver(27981)DATA pin

' -----[ Constants ]-------------------------------------------------------

sPin CON 16 'Serial Pin - P16, Programming port
Baud1 CON 84 'Baud mode for PLX-DAQ with a rate of 9600, 8-N-1
'BS2P, BS2SX use 240 for 9600, 8-N-1


#SELECT $STAMP ' Select Baud constants
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
#CASE BS2PX
T1200 CON 3313
T2400 CON 1646
T4800 CON 813
T9600 CON 396
T19K2 CON 188
#ENDSELECT
Inverted CON $4000 'Value for inverted serial format
Baud CON T9600+Inverted '9600 baud, 8,N,1 inverted

'Sensirion CONs
MoveTo CON 2 ' for DEBUG control
DegSym CON 186 ' degrees symbol for DEBUG
ClrRt CON 11 ' clear DEBUG line to right

' -----[ Variables ]-------------------------------------------------------

angle VAR Word 'Array to hold received data
strLen VAR Byte 'Length of string received
ctemp VAR Word ' temp counts from SHT1x
tC VAR Word ' temp - celcius
tempF VAR Word ' temp - fahrenheit

chumid VAR Word ' humidity counts from SHT1x
humiLin VAR Word ' humidity; linearized
humiTrue VAR Word ' humidity; temp compensated


' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization ]--------------------------------------------------
GOSUB Start_plxdaq


' -----[ Program Code ]----------------------------------------------------

DO
' Wait for preamble, then receive data and crc value
SERIN Rx,Baud,[WAIT ("U!"), angle]

SERIN Rx,Baud,[WAIT ("O!"), DEC ctemp]

SERIN Rx,Baud,[WAIT ("I!"), DEC chumid]

angle = angle */ 360


tC = ctemp / 10 - 400 ' convert to tenths C
tempF = ctemp ** 11796 - 400 ' convert to tenths F
humiLin = (chumid ** 26542)
humiLin = humiLin - ((chumid ** 3468) * (chumid ** 3468) + 50 / 100)
humiLin = humiLin - 40
humiTrue = ((tC / 10 - 25) * (chumid ** 524 + 1) + (humiLin * 10)) + 5 / 10
'test run with plxdaq ; only wants to work when the Rx is not allowed

tempF = 89
angle = 15
humiTrue = 99

'GOSUB DEBUG_MENU
GOSUB PLXDAQ
PAUSE 1000
LOOP


' -----[ Subroutines ]-----------------------------------------------------
DEBUG_MENU:
DEBUG HOME, CR, "angle = ",
DEC angle, DegSym, CR
DEBUG MoveTo, 0, 3
DEBUG "tempF...... "
DEBUG DEC (tempF / 10), ".", DEC1 tempF, DegSym, ClrRt, CR
DEBUG "humiTrue... "
DEBUG DEC (humiTrue / 10), ".", DEC1 humiTrue, "%", ClrRt, CR, CLREOL
RETURN

PLXDAQ:
' Send String with data for Excel
SEROUT sPin,Baud1,["DATA,TIME,TIMER,",DEC angle,DegSym,",", DEC (tempF / 10),DegSym, ",",DEC (humiTrue / 10),".", DEC1 humiTrue, "%",CR]
RETURN

Start_plxdaq:
PAUSE 1000 'Allow data communications to stabilize
SEROUT sPin,Baud1,[CR] 'Send a lone CR to ensure PLX-DAQ buffer is ready

'Label columns
SEROUT sPin,Baud1,[CR,"LABEL,Time,Timer,Wind Direction,Temperature,Humidity",CR]
SEROUT sPin,Baud1,["CLEARDATA",CR] 'Clear all data columns (A-J) in Excel
SEROUT sPin,Baud1,["RESETTIMER",CR] 'Reset Timer to 0
RETURN

Franklin
04-15-2010, 08:31 AM
Seems I remember that "Pin 16" is the same pin as pin15 but goes through the rs232 converter and has some special features. Move your rx pin somewhere else and try it.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

fresh
04-28-2010, 11:35 PM
Thanks Franklin, your suggestion worked.

Now my problem is that I am trying to run the RF in the same room as another set of RF sensors, and it isn't working. The other guy's sensors work but they bump off mine. I've tried everything I can think of, including using different preambles, but I still can't get a signal across.

Mike Green
04-29-2010, 12:04 AM
A lot of RF sensors use very simple transmitters and receivers which don't handle interference very well. There may not be anything you can do. It may be that you can switch to different RF devices that use a different band of frequencies.

For future questions ... Please provide enough information at the beginning about your project, what devices you're using, how they're all connected, and what code you're using. This piecemeal approach is not a good use of your own or anyone else's time.

fresh
05-04-2010, 10:29 PM
Thanks for the advice Mike.

One more question: the code I'm using is partially taken from the demo code posted by Parallax with the modules. I want to enter the Parallax RF contest. I've put this bit in the beginning of my code.




' Author.... *Insert my name*
' Code excerpts for Compass module Hitachi HM55b (#29123) and Sensirion (#28018) provided courtesy of
' Parallax, Inc. Code for RF transmission adapted from Demo code for
' Parallax 433 MHz Transmitter (#27980) & Receiver (#27981) provided courtesy of Parallax, Inc. All
' other code and changes in code are mine.



I've also marked the blocks I've directly borrowed from the Hitachi and Sensirion codes as being from their respective demos. I've changed the formatting and flow of the code for the Sensirion. The code for the RF transmitter and receiver has been adapted to a transceiver and receiver but uses some of the same variables, although the preambles and message data are different. I've kept most of the variables from the sources.

Please tell me if this is OK and tell me what changes I should make to be in compliance. Thank you.

Mike Green
05-04-2010, 10:45 PM
That sounds good to me. You've acknowledged those parts that you've borrowed giving credit where it's due. Parallax isn't "lawyer happy". They're more concerned about intent and integrity and it looks like you've satisfied both. As with any project being judged, the contest is about what you've done, how well you've used existing resources and information, and how well you've done and presented the whole thing.