Basic Stamp tokenizing and flashing from the Linux CLI
For those of you who aren't familiar with the Basic Stamp, its a small microcontroller available from Parallax. It runs at a whopping 20Mhz and has a full 2K of storage on board for instructions. Although it may not sound like much, its more than enough to program the stamp to do some interesting things. The Basic Stamp is programmed in PBASIC, parallax's version of BASIC the stamp interprets.
Rather than waste your time explaining the coolness of the Basic Stamp, (if you've found this page you're probably already interested) I want to focus on how it can be utilized under linux. Currently, Parallax has a very nice PBASIC IDE but its available for windows only. It can however be run under Wine, and with the proper font settings it doesn't look too horrible and is quite functional. But what is the fun in that?
If you're more of a 'vim' guy like me, there's a better alternative. A quick visit over to sourceforge and you'll find a set of command line tools available for download that make it easy to tokenize code and send it to the stamp without needing to reboot into windows.
After downloading the tarball, unpack it and move into the directory. All you need to do now is build it, and it shouldn't require much more than a simple 'make'.
unpack...
tdavis@tdavis-64:~$ tar xvzf bstamp-2006.05.31.tar.gz
bstamp/
bstamp/bstamp_run.cpp
bstamp/tokenizer.h
bstamp/PBASIC_Tokenizer_Software_Distribution_License.txt
bstamp/pbasic_examples/
bstamp/pbasic_examples/hello.bs2
bstamp/pbasic_examples/Makefile
bstamp/pbasic_examples/touch.bs2
bstamp/Makefile
bstamp/PBASIC_Tokenizer_Software_Distribution_License.pdf
bstamp/TODO.txt
bstamp/GPL.txt
bstamp/README.txt
bstamp/CHANGES.txt
bstamp/COPYING.txt
bstamp/bstamp_tokenize.cpp
bstamp/tokenizer.so
bstamp/error_handling.cpp
tdavis@tdavis-64:~$
move into the directory where you unpacked the tarball...
tdavis@tdavis-64:~$ cd bstamp/
tdavis@tdavis-64:~/bstamp$
and build it...
tdavis@tdavis-64:~/bstamp$ make
tdavis@tdavis-64:~/bstamp$ make install
The last step is to make a symbolic link to whatever serial port your stamp is hooked up to. In my case it was /dev/ttyUSB0 because I'm using a serial to usb converter, but for a regular serial connection its likely to be /dev/ttyS0 or /dev/ttyS1. The symlink needs to point the serial device to a new location, /dev/bstamp. If at any point you encounter any problems, don't forget to check out the README.txt that comes with the program.
tdavis@tdavis-64:~/bstamp$ sudo ln -s /dev/ttyUSB0 /dev/bstamp
Now you just need some code to tokenize, as an example here's a simple program I wrote that does nothing more than monitor the light levels off a photo resistor and produce output accordingly. (It beeps and blinks!) Its certainly not the most beautiful code, but it does the trick.
'for Basic Stamp 2
'basic light meter that shows on 7 segment display
'and controls LEDs related to the amount
'of light detected; can also produce
'audio output through a piezo electric
'speaker based on the amount of light detected
'@ Tyler Davis 2007
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "program running!"
index VAR Nib
time VAR Word
dark CON 25
OUTH = %00000000
DIRH = %11111111
'FREQOUT 2, 2000, 4500 'test spk on p2
DO
GOSUB Get_RC 'grab light level info
GOSUB Delay 'delay between refreshes
GOSUB Update_Display
GOSUB sound 'play sound that changes as light
'measurments do
LOOP
Get_RC:
HIGH 0 '0 pin
PAUSE 3
RCTIME 0, 1, time
DEBUG HOME, "time = ", DEC5 time
IF (time > 200) THEN HIGH 6 'for green and
IF (time < 200) THEN LOW 6 'red lights
IF (time < 200) THEN HIGH 4
IF (time > 200) THEN LOW 4
IF (time < 35) THEN HIGH 5
IF (time > 35) THEN LOW 5
IF (time > 400) THEN HIGH 3
IF (time < 400) THEN LOW 3
RETURN
Delay:
PAUSE time
RETURN
Update_Display: 'to adjust 7 segment display
IF index = 6 THEN index = 0
LOOKUP index, [ %01000000,
%10000000,
%00000100,
%00000010,
%00000001,
%00100000 ], OUT
index = index + 1
RETURN
sound: 'to create audible sounds related to
'detected illumination levels
FREQOUT 1, 50, time + 4000
RETURN
Now I'm gonna assume you're using your own code since my code is kind of worthless without a corresponding schematic, but I guess it could be figured out. Since I don't feel like drawing up one I'll just post a picture and if someone wants to try and figure it out they're welcome to. (Sorry but they're terrible pictures, I'll try and get better ones up as soon as I get a chance).


Otherwise the process of tokenizing the code and writing it to the stamp is quite straightforward.
tdavis@tdavis-64:~/bstamp$ ./bstamp_tokenize lightmeter.bs2 lightmeter.tokenized
: Success
PBASIC Tokenizer Library version 1.23tdavis@tdavis-64:~/bstamp$
tdavis@tdavis-64:~/bstamp$ cat lightmeter.tokenized | bstamp_run
If you run into any problems, be sure to verify you're working with the correct serial device. Try a 'dmesg | grep ttyS' and see what it brings up. Or replace 'ttyS' with 'ttyU' if you have a USB connection.



Very Nice! Also dig the Math Captcha, it may need to be a bit more complex. But better than the Orange Captcha
Thx. You saved my life! It works perfectly
hi! I have an eeepc900 with xandros(i think) linux for OS. I think there is a different command for building it(ei. not "make" command. I also have wine 0.9.58. i would really like to detach Lexi(my boe-bot) from my not so mobile, not to mention dead slow, PC(Vista) and would like to introduce it to my eeepc. Im new and different field from programming. Is there a chance that I could progam bs2 on my eeepc. Hope you could help me. Thanks.
Thanks. Nice article
I dont know if winzip works in a linux platform, wasnt there an inbuilt "zip" in linux platforms?
Energy | Phone
most linux distros have a built in 'unzip' command for zip files...
In Centos/RedHat is located here: /usr/bin/unzip
s2eGR0 ornjhuxfsxvi, [url=http://pvwwnfwnyriu.com/]pvwwnfwnyriu[/url], [link=http://ctcosywjdcsi.com/]ctcosywjdcsi[/link], http://dzztlaktyrwh.com/
Z5S9sL dczpllmrcxqh, [url=http://byzxiqrqdgdw.com/]byzxiqrqdgdw[/url], [link=http://rbafgpcgpccv.com/]rbafgpcgpccv[/link], http://bjaurkxfhbof.com/
franklin life insurance efticr life insurance quotes %DDD home insurance rates iamcag affordable car insurance 615784 life insurance 8-((( discount auto insurance %(((
car insurance lucjw ing life insurance uuct home insurance rates 64774 health insurance rates 8-( new york car insurance gmavy auto insurance online =O auto insurance rates >:DD
home insurance 895 american life insurance xevbe auto insurance online %[[[ health insurance coverage wtxf individual health insurance =]]] life insurance quotes kcyage
generic internet pharmacy renova ultram zyrtec xydwt xanax >:))) propecia 6056 viagra >:)) xanax 331 buy valium in wgsu tramadol online lowest price :P
ambien 8)) acomplia %-PPP phentermine %-PP valium %]] acomplia 678 valium :-[[ accutane iqtsu
homeowners insurance quotes =-( home insurance rates 35420 health insurance 768372 buy auto insurance online bmq auto insurance 352680 auto insurance rates %[ auto insurance quotes 75400
life insurance iwsqsm auto insurance quotes 058647 life insurence 198731 health insurance for individuals llku health insurance =PPP auto insurance =) home insurance xsjkuc
cialis sales fqsuey cialis :-P buy accutane 33967 ultram 129576 buy accutane 58123
valium 072319 xanax slvphk retin-a bcxu ultram pill identifier oswr phentermine without a prescription =)) tramadol bgmbuj
home insurance in florida =-P life insurence 8))) homeowner s insurance 8D affordable health insurance :-[[[ auto insurance rates =-))) health insurance :))
in home health care insurance 2493 health insurance rates :P car insurance online 17505 individual health insurance plans exf health insurance 40298 home insurance 290 life insurance 8-O
valium :OO aciphex 270 accutane %-OOO xanax prescriptions 2830 xanax 817 online pharmacy valium 127 order accutane 9142
cialis 8-DDD valium pjyb what is aciphex :OO cialis mfxu discount cialis >:DD accutane 96031
ultram 5160 xanax 346429 valium bkwd ambien 359428 buy levitra viagra nzai
crownpills valium american express pay 346 retin-a yrll order accutane 8-PPP cheap ambien perscription >:) ambien rx ehtt viagra prices %]]]
life insurance quotes 8-OOO car insurence =-(( home insurance rates ybd health insurance rates =OOO health insurance %[ senior life insurance 926465 home insurance quotes ujd
car insurence 373 car insurance quotes eacq life insurance foz life insurance quotes :) home insurance rates fpne life insurance rates unce homeowner s insurance iggdho
Hello! adddbea interesting adddbea site!
Hello!
cialis , viagra , cheap viagra , cheap cialis , buy cialis ,
Hello!
cheap viagra , cheap cialis , viagra , order cialis , cheap viagra ,
Hello!
viagra , viagra , order cialis , cheap cialis , cheap cialis ,
Hello!
cialis , viagra , buy cialis , cheap viagra , cheap cialis ,
Hello!
viagra , cialis , cialis , buy cialis , cialis ,
Hello!
viagra , buy cialis , viagra , cialis , order cialis ,
viagra =-PPP ultram aioasr prednisone qbsi generic pill ultram wellbutrin 173099 online prescription for acomplia 783009
Hello!
viagra , viagra , cialis , buy cialis , viagra ,
Hello!
order cialis , viagra , cheap viagra , cheap viagra , buy cialis ,
Hello!
viagra , viagra , cheap cialis , cheap cialis , cialis ,
Hello!
cialis , cialis , cheap viagra , cialis , viagra ,
Hello!
cialis , viagra , cialis , cheap viagra , viagra ,
Hello!
cheap viagra , buy cialis , order cialis , viagra , cialis online ,
xanax without prescription %DD buy valium england 630 carisoprodol review valium 2750 levitra lah purchase valium 1380 acomplia miracle diet pill =-[[[
Hello!
cheap cialis ,
Hello!
cheap viagra ,
Hello!
cialis ,
Hello!
cheap cialis ,
Hello!
cialis ,
Hello!
viagra , cheap viagra , buy cialis , buy cialis , cheap viagra ,
Hello!
viagra , cialis , order cialis , order cialis , buy cialis ,
Hello!
cialis , buy cialis , viagra , cialis , viagra ,
Hello!
cialis , viagra , buy cialis , buy cialis , cheap viagra ,
Hello!
viagra , viagra , viagra , buy cialis , cheap cialis ,