Sending Bytes?
worthyamherst
Posts: 46
So I am trying to 'code my code' and add values to certain numbers before they send so that the various sensors willhave different values and then I can know what values I have. I am wondering if anybody can tell me if I am asking too much from the basic stamp or the propeller. PS- I am using Xbee transceivers
BASIC STAMP
n the propeller
Also, the propeller board is a spinneret. Any help is greatly appreciated!
BASIC STAMP
' {$STAMP BS2} ' {$PBASIC 2.5} BDistance VAR Word LDistance VAR Word RDistance VAR Word CDistance VAR Word Compass VAR Word signal VAR Word BDistanceA VAR Word RDistanceA VAR Word CDistanceA VAR Word CompassA VAR Word HIGH 6 DO SERIN 6,84, [signal] IF signal = "L" THEN SERIN 6,84, [DEC LDistance] DEBUG HOME, DEC LDistance, " inches left" SEROUT 13,84, [DEC LDistance] PAUSE 250 ELSEIF signal = "R" THEN SERIN 6,84, [DEC RDistance] DEBUG HOME, CR, DEC RDistance, " inches rt" RdistanceA = Rdistance + 148 SEROUT 13,84, [DEC RDistanceA] PAUSE 250 ELSEIF signal = "C" THEN SERIN 6,84, [DEC CDistance] DEBUG HOME, CR,CR, DEC CDistance, " inches front" CDistanceA = CDistance + 296 SEROUT 13,84, [DEC CDistanceA] PAUSE 250 ELSEIF signal = "B" THEN SERIN 6,84, [DEC BDistance] DEBUG HOME, CR,CR,CR, DEC BDistance, " inches rear" BDistanceA = BDistance + 444 SEROUT 13,84, [DEC BDistanceA] PAUSE 250 ELSEIF signal = "s" THEN SERIN 6,84, [DEC Compass] DEBUG HOME,CR,CR,CR,CR, DEC Compass CompassA = Compass + 1000 SEROUT 13, 84, [DEC CompassA] PAUSE 250 ENDIF LOOP
n the propeller
CON _clkmode = xtal1 + pll16x 'Use the PLL to multiple the external clock by 16 _xinfreq = 5_000_000 Baud = 9600 OBJ bs : "BS2_Functions" 'BS2 Libraries STR : "STREngine.spin" 'A string processing utility Var long number long distanceL long distanceR long distanceB long distanceC long compass Pub main bs.start(25,30) repeat number := bs.SERIN_char(25,9600,0,8) if number => 0 and number =< 147 'Left bs.serout_dec(31, number, Baud, 1, 8) 'debug bs.Debug_Char(13) distanceL := number 'STR.numberToDecimal(distanceL, 3) elseif number => 148 and number =< 295'Right distanceR := number - 148 bs.serout_dec(30, distanceR, Baud, 1, 8) bs.Debug_Char(13) distanceR := number 'STR.numberToDecimal(distanceR, 3) elseif number => 296 and number =< 443'Front distanceC := number - 296 bs.serout_dec(30, distanceC, Baud, 1, 8) bs.Debug_Char(13) distanceC := number 'STR.DecimalTonumber(distanceC) elseif number => 444 and number =< 591' Back distanceB := number - 444 bs.serout_dec(30, distanceB, Baud, 1, 8) bs.Debug_Char(13) distanceB := number 'STR.DecimalTonumber(distanceB) elseif number => 1000 and number =< 1360 'Compass compass := number - 1000 bs.serout_dec(30, compass, Baud, 1, 8) bs.Debug_Char(13) compass := number 'STR.DecimalTonumber(compass
Also, the propeller board is a spinneret. Any help is greatly appreciated!
Comments
Any IO-pin of the propeller can be used for serial datatransmission
In your code above you are using the propeller-basic-stamp-functions. They are a quick entrance but they are quite limited (like the basic stamp itself compared to the propeller-chip).
Simply use the IO-pins 31,30 for the serial connection together with the FullDuplexSerialPlus-object (shortna,e FDX+) which can be found in the propeller-tool library
You don't need the str-engine to tie everything together before sending with FDX+ because FDX+ has methods for sending
- single characters
- decimal values
- strings
keep the questions coming
best regards
Stefan