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)

March 03, 2004

BS2 listings & Max patch from 3-2-04 class

Here's everything we did in the during the second half of our marathon session last night, cleaned up and commented.

switch.bs2
switch+LED.bs2
switch+LED+pot.bs2
switch+LED+pot+serial.bs2
newMaxtoBS2.pat

Posted by Perry at 12:35 PM | Comments (0)

November 26, 2003

Video tracking drives stepper motor

A demonstration of how to use softVNS motion tracking to rotate a stepper motor.

Basic Stamp program listing
Max/MSP/softVNS patch
snapshot of stepper motor setup
closeup of stepper motor & switch

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

November 19, 2003

Hacking a servo for continuous rotation - links

http://www.gorobotics.net/articles/article.php?name=servohack
http://www.seattlerobotics.org/guide/servohack.html
http://www.acroname.com/robotics/info/ideas/continuous/continuous.html
http://www.dprg.org/projects/2003-05a/

Posted by Perry at 11:56 PM | Comments (1)

November 17, 2003

Unipolar Stepper Motor Control

external links:
Stampworks Experiment #26: Stepper Motor Control (PDF)
ULN2003 spec sheet (PDF)
BEAM Reference Library article on Stepper Motors
Jones on Stepping Motors

internal links:
Basic Stamp program (revised version of StampWorks program)
circuit diagram (revised version of StampWorks diagram)
snapshot of small stepper setup

links to components @ All Electronics:
ULN2003 Darlington Array
a small 12V 7.5 deg/step unipolar stepper motor
a larger 5V 7.5 deg/step unipolar stepper motor
a larger 5V 1.8 deg/step unipolar stepper motor

NOTE: You will need a separate power supply for the motor.

Sorting out the wires:

Unipolar stepper motors have six leads. Internally, they have two windings, each with three of the six leads. One of these three leads is a center tap on its respective winding; this lead gets wired to V+. The other two leads are connected to each end of the winding, and when either is successively grounded, it creates an opposite magnetic field. By alternately energizing the two windings in each of two directions, the rotor can be stepped in a clockwise or counterclockwise direction.

To sort out the leads on a unipolar stepper motor with 6 wires: Use a multimeter to measure the resistance between pairs of leads. Each pair of leads will give one of three possible results: a fairly low resistance, twice this resistance, or a very high resistance (typically in megaohms).

Try to find a trio of leads with low resistance. Of these three leads, the one that gives identical results with the other two is the common. The other two together should give you twice the resistance of either of them with the common. Label the two groups of three leads each 1 and 2 (don't worry about which is which; see below), and label each of the commons as C.

Now, if you connect the common to V+, by momentarily connecting each of the other two leads to ground, you should be able to make the motor shaft jump slightly clockwise and counterclockwise. Call the clockwise lead A, and the counterclockwise lead B. Find the A and B leads for both groups 1 and 2.

Each wire is now labeled: 1A, 1B, 1C and 2A, 2B, 2C. Connect 1C and 2C to V+, and connect the other wires to your control pins in this order: 1A, 2A, 1B, 2B. If clockwise and counter-clockwise are flipped once you wire everything up, then switch 1 and 2 (ie, 2A, 1A, 2B, 1B).

Posted by Perry at 09:10 PM | Comments (0)

November 06, 2003

October 06, 2003

wiring

quick question:

I feel like I've got the reading of wiring diagrams down ok, or at least to the point where I know what's going on. However, I'm looking to try out some more complex stuff, and I'm wondering where one goes to get wiring diagrams for, say, a rotary switch, or whatever - something we haven't covered in class. I'm guessing I should probably go buy a electronics book, but if anyone has any suggestions, I'm more than welcome to them.

thanks.

Posted by will at 08:56 AM | Comments (1)

September 27, 2003

Microcontroller Madness: Class Pix 9/25/03

DSCN5778.jpg
View image

DSCN5779.jpg
'where's that resistor?'

DSCN5782.jpg
View image

Posted by at 09:03 AM | Comments (0)

September 25, 2003

Basic Stamp 2 code for communicating with MaxMSP

'{$STAMP BS2}

'BASIC STAMP 2 FIRST PROJECT - COMMUNICATION WITH MAX/MSP

'WHAT SHOULD HAPPEN:
'When a serial message is received on pin 2, the light is turned on or off.
'When the switch is opened or closed, a serial message is sent out on pin 3.

'NOTE: after downloading this program, remove the programming cable from the
'Mac serial port, and plug in the custom serial cable to communicate with Max/MSP.
'Also, you will have to quit out of MacBS2 (or Virtual PC) before you run Max/MSP.

'DECLARE INS & OUTS
input 0 'switch
output 1 'relay
input 2 'BS2 serial receive, mac TXD (transmit)
output 3 'BS2 serial transmit, mac RXD (recieve)

'DECLARE VARIABLES
prevSwitchState var bit
serButtonByte var byte 'serial input from Mac - 1 for button down, 2 for button up

'INITIALIZE VARIABLES
prevSwitchState = 0 'start with switch off

'MAIN LOOP

TOP:
serIn 2,16468,50,CHECKSWITCH,[serButtonByte] 'branch to CHECKSWITCH if 50 ms pass
if serButtonByte = 2 then LIGHTON
if serButtonByte = 1 then LIGHTOFF

CHECKSWITCH:
if in0 <> prevSwitchState then ONOROFF 'branch if switch state changed
goto TOP

LIGHTON:
high 1 'turn on light
'debug "Light ON",cr
serOut 3,16468,["light_ON_"] 'report light on
goto TOP

LIGHTOFF:
low 1 'turn off light
'debug "Light OFF",cr
serOut 3,16468,["light_OFF"] 'report light off
goto TOP

ONOROFF:
if in0 = 1 then SWITCHON 'if 1 then switch on
if in0 = 0 then SWITCHOFF 'if 0 then switch off
goto TOP

SWITCHON:
prevSwitchState = 1
'debug "Switch ON",cr
serOut 3,16468,["switch_ON"] 'report switch on
goto TOP

SWITCHOFF:
prevSwitchState = 0
'debug "Switch OFF",cr
serOut 3,16468,["switchOFF"] 'report switch off
goto TOP

Posted by at 08:45 PM | Comments (1)

Basic Stamp circuits & Max patch

View Basic Stamp 2 Circuits

View Max Patch

Posted by at 08:26 PM | Comments (2)