Shop OBEX P1 Docs P2 Docs Learn Events
Help needed for a sensor and 433 rf transmitter — Parallax Forums

Help needed for a sensor and 433 rf transmitter

skybotskybot Posts: 14
edited 2008-12-09 14:17 in BASIC Stamp
Hi
I want to capture data from a sensor and to send the data to my pc via 433 rf transmitter.
I want to send·the data something like below.
X·······Y······ Degree
222.1· 222.1 23

Here is my code that has some errors.
1. the first error is out of variable space. How can I fix it?
2. the second problem is how can I capture the data from compass sensor and put that in the message variable for the transmit packet?

'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
'
' =========================================================================

'
[noparse][[/noparse] I/O Definitions ]

Tx············· PIN···· 10············· ' Transmitter (27981)DATA pin
'
[noparse][[/noparse] Pins/Constants/Variables ]
DinDout······· PIN····· 6··················· ' P6 transceives to/from Din/Dout
Clk··········· PIN····· 5··················· ' P5 sends pulses to HM55B's Clk
En············ PIN····· 4··················· ' P4 controls HM55B's /EN(ABLE)
Reset········· CON····· %0000··············· ' Reset command for HM55B
Measure······· CON····· %1000··············· ' Start measurement command
Report········ CON····· %1100··············· ' Get status/axis values command
Ready········· CON····· %1100··············· ' 11 -> Done, 00 -> no errors
NegMask······· CON····· %1111100000000000··· ' For 11-bit negative to 16-bits

x············· VAR····· Word················ ' x-axis data
y············· VAR····· Word················ ' y-axis data
status········ VAR····· Nib················· ' Status flags
angle········· VAR····· Word················ ' Store angle measurement

'
[noparse][[/noparse] Constants ]

EOM············ CON···· 255············ ' Value to signal end-of-message
#SELECT $STAMP························· ' Select Baud constants
· #CASE BS2, BS2E, BS2PE
··· T1200······ CON···· 813
··· T2400······ CON···· 396
··· T4800······ CON···· 188
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
#ENDSELECT
Inverted······· CON···· $4000·········· 'Value for inverted serial format
Baud··········· CON···· T9600+Inverted· '9600 baud, 8,N,1 inverted

'
[noparse][[/noparse] Variables ]

string········· VAR···· Byte(16)······· 'Array to hold received data
idx············ VAR···· Word··········· 'Index into message data
StrLen········· VAR···· Byte············ 'Byte··········· 'Length of string received
char··········· VAR···· Byte··········· 'Current character from message

cValue········· VAR···· Byte··········· 'Holder for CRC calculation
crc············ VAR···· Word··········· 'Calculate Crc value

'
[noparse][[/noparse] EEPROM Data ]

Message DATA "x-axis· y-axis· Angle", CR
······· DATA " -20···· 37···· 240", CR···· 'I wnat to put real data from compass sensor.
··················································· 'How can I put the SDEC x, SDEC y and·angle values?
······· DATA EOM

'
[noparse][[/noparse] Initialization ]


'
[noparse][[/noparse] Program Code ]

LOW Tx································· 'Initialize transceiver interface
DO
· idx = Message························ 'Point idx to start of message data
· DO
··· strLen = 0························· 'Set string length to zero
··· crc = 0···························· 'Start Crc at zero
··· DO
····· strLen = strLen + 1
····· READ idx, char··················· 'Read a character from message data
····· idx = idx + 1···················· 'Point to next character in message
····· string(strLen-1) = char·········· 'Put character into string array
····· cValue = char···················· 'Prepare to add char to Crc value
····· GOSUB CalcCRC···················· 'Add cValue to Crc value
····· IF (strLen = 15) OR (char = EOM) THEN EXIT 'Exit loop when ready
··· LOOP······························· 'Keep reading message characters
··· ' Send packet
··· PULSOUT Tx,1200···················· 'Send sync pulse to radio
··· ' Send preample "UUUU!", string length, string data, crc
··· SEROUT Tx, Baud, [noparse][[/noparse]"UUUU!", strLen, STR string\strLen,
····················· crc.LOWBYTE, crc.HIGHBYTE]
··· PAUSE 100·························· 'Give receiver time to process
· LOOP WHILE char <> EOM··············· 'Keep sending until EOM character
· DO·········································· ' Main loop

··· GOSUB Compass_Get_Axes···················· ' Get x, and y values
··· angle = x ATN -y·························· ' Convert x and y to brads
··· angle = angle */ 360······················ ' Convert brads to degrees

··· DEBUG HOME, "x-axis N(-S) = ",SDEC x,····· ' Display axes and degrees
········· CLREOL, CR, "y-axis W(-E) = ",
········· SDEC y, CLREOL, CR, CR, "angle = ",
········· DEC angle, " degrees", CLREOL

··· PAUSE 150································· ' Debug delay for slower PCs
· LOOP········································ ' Repeat main loop
LOOP··································· 'Start all over at the beginning


'
[noparse][[/noparse] Tx Subroutines ]

' CRC Checksum Calculation Routine
CalcCRC:
· CValue= crc.HIGHBYTE ^ cValue >> 4 ^ (crc.HIGHBYTE ^ cValue)
· crc = cValue ^ (cValue << 5) ^ (cValue << 12) ^ (crc << 8)
RETURN
'

[noparse][[/noparse] Copass Subroutines ]

Compass_Get_Axes:··························· ' Compass module subroutine
· HIGH En: LOW En··························· ' Send reset command to HM55B
· SHIFTOUT DinDout,clk,MSBFIRST,[noparse][[/noparse]Reset\4]

· HIGH En: LOW En··························· ' HM55B start measurement command
· SHIFTOUT DinDout,clk,MSBFIRST,[noparse][[/noparse]Measure\4]
· status = 0································ ' Clear previous status flags

· DO········································ ' Status flag checking loop
··· HIGH En: LOW En························· ' Measurement status command
··· SHIFTOUT DinDout,clk,MSBFIRST,[noparse][[/noparse]Report\4]
··· SHIFTIN· DinDout,clk,MSBPOST,[noparse][[/noparse]Status\4]· ' Get Status
· LOOP UNTIL status = Ready················· ' Exit loop when status is ready

· SHIFTIN· DinDout,clk,MSBPOST,[noparse][[/noparse]x\11,y\11]·· ' Get x & y axis values
· HIGH En··································· ' Disable module

· IF (y.BIT10 = 1) THEN y = y | NegMask····· ' Store 11-bits as signed word
· IF (x.BIT10 = 1) THEN x = x | NegMask····· ' Repeat for other axis

RETURN

Pleae help me
Thank you.

Comments

  • Carl HayesCarl Hayes Posts: 841
    edited 2008-12-09 14:17
    For starters, you've got 30 bytes of variables to fit in the 26 available on a Stamp. You can cure that by putting some of them in the scratchpad RAM instead of in the variable RAM, or by getting rid of some of them, or both.

    When (and only when) you've done that, it will become possible to attack other problems in the code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
Sign In or Register to comment.