October 26, 2004

The McVoting Booth

mcvotingbooth.jpg

Here are the BS2 and the Processing codes I used to execute my "McVoting Booth." The voting booth allowed the voter to choose between Bush or Kerry. There was a button for each candidate. The Bush button always worked (to add votes to the Bush side), but the Kerry button worked some of the time, sometimes added votes for Bush instead, and sometimes did nothing at all.

THE BS2 CODE:
********************************************************************************************

SerInPin PIN 0 'serial IN pin (RXD - at the other end: TXD)
SerOutPin PIN 1 'serial OUT pin (TXD - at the other end: RXD)
SerInData VAR BYTE 'number to match to incoming data
SerWait CON 50 'ms to wait for input before timing out
N9600 CON 16468 'BS2 baudmode values: 16468/9600, 16416/19200, 16390/38400
'See SEROUT in the Basic Stamp manual for details.


test3:
PAUSE 100

IF IN2 THEN
SEROUT SEROUTPin, N9600,[DEC 1]
DEBUG "1"
ENDIF

IF IN4 THEN
SEROUT SerOutPin, N9600,[DEC 2]
DEBUG "2"
ENDIF
GOTO test3


********************************************************************************************

PROCESSING CODE:
********************************************************************************************
// McVoting Booth
// by Kellee Santiago

// A phony voting booth that reads off of two buttons.
// votes for Bush all of the time, the other button votes for Kerry sometimes,
// Bush at others, and sometimes does nothing.

// Created 20 Oct 2004

int bushVotes = 0; //declares the variable number of bushVotes and starts it at 0
int kerryVotes = 0; //declares the variable number of kerryVotes and starts it at 0
BFont theFont; //declared the variable of the font as "theFont"
int val; //reads the value off the serial port


void setup() {
beginSerial();//starts reading the serial port
size(400,200);//screensize
theFont = loadFont("Bauhaus.vlw.gz");//declared font - make sure to copy it into project folder!
fill(255,0,0);
stroke(255);
textFont(theFont, 48);

}

void loop() {
background(255);
BImage elephant;//declare image of rep. elephant
elephant = loadImage("tease.republican.gif");//loads image - have copy in project folder!
BImage donkey;
donkey = loadImage("tease.democrat.gif");
image(elephant, 120, 50); //sets the place of the image
image(donkey, 200, 50);


smooth();//smooths out font
fill(255,0,0);
text("bush", 40,75);
text(bushVotes,65,125);
fill(0,0,255);
text("kerry", 260,75);
text(kerryVotes,285,125);
}
void serialEvent() {
val = serial;
println(val);
if(val==49) {
bushVotes++; //reads value off serial port. Processing reads in ASCII, so when the
} //serial port sends out a 1, processing sees a 49.
else
if(val==50) {
if(random(10) < 3) {
kerryVotes++;
if(random(10) > 6){
bushVotes++;
//this is how i set up a basic random generator. When processing gets a 50 (ASCII for 2)
//it randomly generates a number from 1-10. If it's less than 3, Kerry gets a vote. If it's greater
//than 6, Bush gets a vote. Nothing happens if it's 3-6.
}
}
}
}
********************************************************************************************

Posted by kellee at 02:40 PM | Comments (0)

October 19, 2004

Processing and BS2

I'm trying to get Processing to read a binary input, here is the reference code:

// Binary Input
// by Mathias Dahlstrom

// Example of a binary input from a BX-24 chip using serial communcation.
// Running this examples requires you have a BX-24 microcontroller
// and peripheral hardware. More information can be found on the tutorial
// pages of Tom Igoe: http://stage.itp.nyu.edu/%7Etigoe/pcomp/examples.shtml
// Make sure to have the correct port selected in the "sketch" menu. Because
// this program uses the serial port, it will not work within a web browser.

// Created 12 February 2003

// State of the circle drawing
boolean circleExpanding = true;

// Size of the circle
float circleSize = 0;

//The setup defines screen size and color setup.
void setup()
{
size(200, 200);
beginSerial(19200);
noStroke();
fill(204);
ellipseMode(CENTER_RADIUS);
}

// The loop checks for what state the circle should be
// drawn into and performs the drawing.
void loop()
{
background(0);

if(circleExpanding) {
ellipse(width/2, height/2, circleSize, circleSize);
circleSize += 0.5;
}else{
ellipse(width/2, height/2, circleSize, circleSize);
circleSize -= 0.5;
}
if(circleSize > width/2) {
circleSize = width/2;
}
if(circleSize < 10) {
circleSize = 10;
}
}

// Function is called when ever a new byte from the
// BX-24 is avaliable for reading.
// It controls what input the user is generating and
// sets the corresponding drawing mode.
void serialEvent()
{
// Checks the ASCII code sent from the basicX chip.
// '48' is the code for '0' and '49' is the code for '1'
if(serial == 0) {
circleExpanding = false;
}
if(serial == 1) {
circleExpanding = true;
}
println(serial);
}
*******************************
Here is my code for BS2:

SerInPin PIN 0 'serial IN pin (RXD - at the other end: TXD)
SerOutPin PIN 1 'serial OUT pin (TXD - at the other end: RXD)
SerInData VAR BYTE 'number to match to incoming data
SerWait CON 50 'ms to wait for input before timing out
N9600 CON 16468 'BS2 baudmode values: 16468/9600, 16416/19200, 16390/38400
'See SEROUT in the Basic Stamp manual for details.

DEBUG CR,"Program starting ...",CR

test:
IF IN2 THEN
HIGH 11
SEROUT SerOutPin,N9600,[DEC 1,CR]
DEBUG "1"
ELSE
LOW 11
SEROUT SerOutPin,N9600,[DEC 0,CR]
DEBUG "0"
ENDIF
GOTO test

************************************

But everytime I run the Processing program, it just makes a circle that expands. Blah!

Posted by kellee at 03:07 PM | Comments (1)

October 16, 2004

sources for electronics components

Parallax Basic Stamp microcontrollers, sensors, components, modules, robotics
Acroname sensors, motor, robotics, Brainstem microcontroller
Mondotronics robots & robotics components
Jameco huge selection of electronics components
Digi-Key gargantuan selection of electronics components
All Electronics large selection of surplus electronics; cheap, local.
EarthLCD LCD panels, touchscreens
Electronic Goldmine surplus components, cheap
Images SI Inc sensors, actuators, components

Posted by Perry at 05:25 AM | Comments (0)

October 15, 2004

October 14, 2004

October 12, 2004

Instructions for making a serial communication cable

To program a Basic Stamp, you can use the 9-pin RS232 serial port that's built in to the carrier board. However, to communicate between the Stamp and a multimedia tool (such as Director, Max/MSP or Processing), you'll need to build a serial cable that ends in bare wires, so that you can connect it directly to two Stamp I/O pins, which you'll use for serial input and output.

Here is a diagram of the cable you'll need to build:
stampSerialCable2.gif

Following are detailed instructions for one method of making this cable.

Use a 9 pin female D-sub connector [Radio Shack 276-1538].
The solder terminals are numbered from left to right, top row first.
serial1.jpg
You will want to find some way to hold the connector in place while
you solder it (such as a vice, a clamp, a weight, or a piece of tape).
Use .032 diameter light-duty rosin-core solder [Radio Shack 64-005].
Fill terminals 2, 3 and 5 with solder. (Heat the terminal with the soldering
iron and then hold the solder to the terminal until it flows into it).
serial1.jpg
I recommend using a green wire for ground [5],
a black wire for BS2 serial in [3], and a red wire
for BS2 serial in [2]. Strip 1/4 inch of insulation
on each wire. Coat the bare wire with solder.
serial1.jpg
Reheat the solder in each terminal.
serial1.jpg
When it is liquified, push the appropriate wire
into the terminal and hold it until it hardens.
serial1.jpg
I recommend soldering the necessary 22K resistor
inline with the BS2 serial in cable.
serial1.jpg
That's it. Now you're ready to test communications
between the Stamp and your authoring tool.

Posted by Perry at 11:58 PM | Comments (2)

October 11, 2004

Communicating between the Stamp and an authoring tool

  1. Connect the black wire (the one with the 22k resistor) from your serial communication cable to the Stamp's Pin 0. Connect the red wire to the Stamp's Pin 1. Connect the green wire to ground.
  2. Load the following program into your Stamp programming software and download it to the Stamp: serialCableTest.bs2
  3. The Stamp should print to the debug window: "Program starting ...", and then every few seconds "Waiting for serial input ..."
  4. Remove the programming cable from the Mac/PC's serial port, and replace it with the communication cable (the one that's connected to pins 0, 1 and Ground).
  5. Now load one of the following three programs into your chosen authoring tool:
  6. Before you run any of these programs, make sure you've selected the correct serial port.
    • Max/MSP/Jitter: By sending the serial object a "print" message, you can determine by letter (a, b, c, d, etc) which port is which and then replace the parameter in the serial object.
    • Director: Typing "put findports()" into the message window lists all available ports. Replace "USA191" with the correct port (if you are using a Keyspan adapter, read the comments for some useful details).
    • Processing: make sure to select the correct serial port from the Sketch menu before running the program.
  7. Run the program. Your authoring tool should initiate a two-way communication with the Stamp, sending it the number 100 to trigger the next count from 0 to 400 and back again.
Posted by Perry at 09:06 AM | Comments (3)

October 10, 2004

Reading a variable resistor with the Basic Stamp

Here is a diagram of the circuit you will need to build to use the BS2 command RCTIME to read any variable resistor (such as a potentiometer, photoresistor, bend sensor, force sensing resistor, etc).

rcCircuit.gif

The following Basic Stamp file demonstrates the use of RCTIME to read a variable resistor.

resistor.bs2

Posted by Perry at 11:37 AM | Comments (0)

October 09, 2004

Reading various sensors with the BS2

Bend Sensor
Accelerometer
Force Sensing Resistor
PIR Motion Detector

Posted by Perry at 08:24 AM | Comments (0)

October 08, 2004

October 07, 2004

circuit diagram for reading a switch with the BS2

switch.gif

Posted by Perry at 01:08 AM | Comments (0)

October 06, 2004

troubleshooting Basic Stamp programs

Things to try if something isn't working:

  • Make sure the pin numbers in your code match the pin numbers in your circuit.
  • Make sure that your connections are connected on your breadboard - it's easy to mistakenly plug something into an adjacent row.
  • Make sure you've selected the correct serial port.
  • On the Mac, run Keyspan Serial Assistant (found in the Applications folder) to make sure that your Keyspan USB Adaptor is being recognized.
  • Make sure you've selected the correct flavor of Basic Stamp.
  • Remember, VDD = +5V, VSS = ground
  • Make sure you are formatting your variables correctly when you print them out with DEBUG or send them over the serial port as SEROUT. Numbers default to bytes, you will often want to format them as integers using DEC.
  • Try pressing the RESET button on the Stamp board.
  • Put in lots of DEBUG statements so that you can pinpoint the problem.
  • Try quitting MacBS2 and restarting; on a couple of occasions, I've had it stop communicating with the Stamp while appearing to still be working.
  • I strongly recommend using red wire for connections to +5V, green wire for connections to ground, and black (or other colors) for connections to input/output pins.

Posted by Perry at 06:03 PM | Comments (0)

October 05, 2004

links to Basic Stamp software

Parallax Basic Stamp Editor 2.1 for Windows
MacBS2 Editor for OS X
Basic Stamp Tokenizer MacBS2 should install this automatically, but it doesn't
SerialXtra for Director

Posted by Perry at 11:50 PM | Comments (0)