PDA

View Full Version : Download a program into the Boe Bot without it automatically starting?



czetie
11-22-2009, 11:22 PM
OK, I'm sure this question must have been asked before... but I can't find a set of search terms that brings up anything relevant :-(

Is it possible to download a program into the Boe Bot's EEPROM but not have it start executing immediately?

I'm working my way through the beginner's textbook, and for a lot of the exercises I'd really prefer that the wheels not start spinning (etc.) until I've had a chance to detach the serial cable, switch from power adapter to batteries, and move the robot to the floor... I also expect that once I get into more custom stuff, like maze-solving, I'll want to be able to make it wait patiently until I tell it go.

I know I could do this using some kind of sensor (e.g. after program initialization, have the program wait for a touch on the whiskers or a flash of light); or leave the power switch at position 1 until I'm ready to go, push it to 2 then quickly hit reset; but is there anything slicker/less power consuming?

thanks,
Carl

Phil Pilgrim (PhiPi)
11-22-2009, 11:33 PM
No, other than having your program wait for a sensor input, removing power, or holding the reset button down, there's no way to prevent execution from commencing. Think about it this way: if you were able to load a program that didn't execute, how would tell it to start?

BTW, some boards, like the BOE, have a three-way switch so that the servo headers remain unpowered unless the switch is all the way in the third position. That way, with the switch in the middle position, even if the program is running, nothing plugged into these headers gets activated.

-Phil

czetie
11-23-2009, 12:11 AM
Phil Pilgrim (PhiPi) said...
how would tell it to start?


With the RESET button?

Ideally, what I would like is for the program to download, then on completion of the download (presumably some signal from the serial port tells the board that's happened?) for the processor to immediately go to the same state that it goes to when it executes an END command, rather than going to the run state. Pressing the RESET button would then cause the program to start running as normal.

sylvie369
11-23-2009, 12:22 AM
Well, you could just add a momentary normally open pushbutton pulled high (for example) that goes low when pressed, and read it as input to a pin. Then your program begins with a loop that just goes around in circles as long as that input pin is high, but escapes from the loop into the actual program when the pin is taken low. The code might look something like this (from the PBasic manual's page on INPUT):


The PBASIC ·fairy said...
Setup: INPUT 4Hold: IF PIN4 = 1 THEN Hold ' Stay here until P4 is 0 [Note: I changed the 1s and 0s around to reflect what I wrote above][The rest of your code goes here]

Post Edited (sylvie369) : 11/22/2009 4:31:04 PM GMT

Mike Green
11-23-2009, 12:44 AM
@czetie - That's not how the Stamp works and you can't change it. Whenever the Stamp is powered up or the reset signal is released (low->high) or a download completes, the Stamp will go through its reset process and start executing whatever program is recorded in its EEPROM. The program has no access to the reset signal or reset button. As sylvie369 suggested, you'd have to use some other pushbutton and write your program to make use of it.

There have been programs that keep track of how many times the Stamp has been reset by using a location in EEPROM to keep a counter, but these programs can't tell the difference between a reset caused by a new download vs. a reset caused by power on or by pushing the reset button.

Typically, these programs have a DATA statement that initializes an EEPROM location to zero, then the first thing the program does is to read that location. If the value is zero, it's the first reset since the program was downloaded. The program normally increments the location before continuing, so it will be non-zero for all other resets. Read the BASIC Stamp Syntax and Reference Manual chapters on the DATA and READ statements for details on how to use the EEPROM for data storage.

W9GFO
11-23-2009, 04:41 AM
You could put some code in the beginning of the program (before the main loop) that checks to see if a whisker is touched, if you then start the program (or download) with the whisker activated the program would either go into a perpetual loop or jump to the END. Then, when you push the reset button (without touching a whisker) the program executes immediately.

Rich H

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster. (http://www.gadgetgangster.com/206)

czetie
11-23-2009, 04:55 AM
Mike Green said...
There have been programs that keep track of how many times the Stamp has been reset by using a location in EEPROM to keep a counter, but these programs can't tell the difference between a reset caused by a new download vs. a reset caused by power on or by pushing the reset button.



I like that idea. And since I really don't need to count how many times the Stamp has been reset, I can just use one bit. If it's 0, set it to 1 and END. If it's 1, run the program.

And in fact I can do even better: If I toggle the bit on each run, I can use the Reset button as a "stop/go" button: The first time it runs after download, the program will set the bit to 1 and then END. Hit it again, it will see the 1, set it back to 0, and then run. Hit the Reset while it's running and it will see the 0, set it to 1, and END.

Zoot
11-23-2009, 05:11 AM
Mike Green said...
There have been programs that keep track of how many times the Stamp has been reset by using a location in EEPROM to keep a counter, but these programs can't tell the difference between a reset caused by a new download vs. a reset caused by power on or by pushing the reset button.


Ah.... but you CAN -- to wit:





ResetState DATA $FF ' all ones

Start:
READ ResetState, myVar
WRITE ResetState, myVar + 1 & %1 ' limit to 0-1
IF myVar = $FF THEN First_Run
IF myVar = 0 THEN Main ' regular run
'otherwise off

Off:
' program "off"; loop here forever
GOTO Off

First_Run:
' run some calibration code or whatever
' more code
' only runs on first runthrough after download
' now you can drop through to Main and "go"
' or loop forever and wait for a reset to "go"
' at this point the written state is 0, so if you
'wait here for a reset, the next button push will "run" the main program
' I do this with bots so they never "run" after I download the program fresh
' otherwise they take off with the cable still attached
' after the first run, alternate resets will "run" or "off" the program
' w/o running calibration code or what have you

Main:
' do some stuff

GOTO Main



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

1uffakind.com/robots/povBitMapBuilder.php (http://1uffakind.com/robots/povBitMapBuilder.php)
1uffakind.com/robots/resistorLadder.php (http://1uffakind.com/robots/resistorLadder.php)

Post Edited (Zoot) : 11/22/2009 9:17:05 PM GMT

Phil Pilgrim (PhiPi)
11-23-2009, 05:23 AM
I'd neglected to consider the RESET count technique. Here's how to do it:




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

READ 0, B0
WRITE 0, 1
PAUSE 1000
WRITE 0, 0

IF (B0 = 0) THEN END 'Powerup, or one reset: Do nothing.

B0 = 0 'Two or more reset button pushes: Reinitialize B0 and proceed.




-Phil