I am using a BS2 chip to make a demo board for a pneumatics presentation. I’m having a little trouble getting started. The main function that the chip needs to serve is to regulate the pressure using the pressure sensors and a spike relay. I can connect this hardware-wise, but I don’t know how to program the chip. Both switches are NC until they reach their max pressure (which is adjustable). Any help would be appreciated.

No problem. Are you using the innovationFIRST controllers, or a BS2 by itself? I can help either way, but the program would be drastically different depending on which way you are doing it.

Just the Bs2 along with one of the housing boards. One of the BOE’s. The First stamps wouldn’t be a problem, but the chip is a little different and I’m not sure how to do the input and output, though I think I have the logic part down

Basically, if you want something to be an input (like the pressure switch), start with

Input X

where X is the number of the pin you want to make be an input. Likewise, use

Output X

for any pins you want to be outputs (relays, PWMs, etc).

Then, the bit variables inX and outX (pre-defined by the BS2, don’t worry about declaring them) will represent the states of these pins. For example:

Output 2
Input 3
if (in3=0) then switchIsOff

Remember, the normal BS2 does NOT use serin/serout for I/O, everything is pin-addressable only. Also, you won’t be able to use the Spike relays that we use for FIRST as they are specific to the Isaac32(or 16) controllers.

The BS2 is capable of Serin/Serout. there are pins on the chip that correspond to Serial RX and Serial TX (Transmission and Recieving of data). To use a spike relay with one of the bs2’s simple the Black wire is a ground wire and the white and red wires are input on the relay. Red for reverse and white for forward. The problem I am having though is that using “Input” requires either a high or a low voltage. If there is no voltage present then the state of InX is apparently random. (Page 155 in the Basic Stamp Manual Ver 2.0) I didn’t sound right when I read it, but when I used the Debug function it appeared to be true

Yes, the BS2 can do Serin/Serout, but without the full Isaac32, there is nothing to Serin/Serout to. The easiest way I can think of for fixing the switch problem is to use a switch with three terminals. Connect to ground for off and +5 for on. Where did you find a pinout of the Spikes? I was looking for it on InnovationFIRST’s website, but couldn’t find it anywhere. Just curious.

i couldn’t find it either. So i just played a little on a low voltage until I found it. Note: It must be grounded to work. Do you have to use the input statement or just the InX after you declared it once? I think this code should work, have tried it yet because I can’t find a 9 pin serial cable. Does it sound right?

Input 0 'Low Pressure Setting for Minimum Pressure
Input 1 'High Pressure Setting for Maximum Pressure
Output 2
LastState VAR byte
Counter VAR nib
Check: 'If at or below Low pressure then turn on
Counter = Counter + 1
LastState = (LastState << 1) + In0
If Counter < 8 Then Check
Counter = 0
if LastState = 255 Then Run '8 in a row have been on (not Random)
LastState = 0
goto Check
Run: 'Run until High Pressure swith is open
if In1 = 0 then Full 'No signal - switch open
Out2 = 1
Goto Run
Out2 = 0
LastState = 0
goto Check

that is correct, you only need to declare the Input and Output once. As far as I can tell, the code looks right to me. If I understand it right, as soon as the pressure falls below the minimum, the pump will turn on and stay on until it reaches maximum. At that point, it will stay off until it drops below the minimum again. Correct? The only thing you might want to do is initialize all your variables (including out2) before starting the main loop.

Yeah, thats the hardware logic. I made a mistake on the the << operator but I fixed it. I’ll probably get around to testing it tomorrow when I can find a cable.

Good point, I didn’t even see that. Oh well…too much work with binary makes the brain go numb…

This is the code I ended up using. I connected In0 and In2 to Pin 1 and 3 respectively and set those pins to low. Which solved the problem of the whole random thing. I kinda got the idea from the 3 pole switch idea. I ended up bumping the output to pin 4. The problem with the other code is that it likes to be on 1 more than 0 and gave the illusion that the switches were open.

low 1
low 3
Output 4

if In0 = 1 then TurnOn
goto Check

if In2 = 0 then Full
Out4 = 1
Goto TurnOn

Out4 = 0
goto Check