Monthly Archives: May 2004

Serial Call-and-Response (Processing)

// Starting position of the ballboolean firstContact = false; // Whether we’ve heard from the microcontrollervoid setup() { size(256, 256); // Stage size noStroke(); // No border on the next thing drawn // Set the starting position of the ball (middle of the stage) xpos = width/2; ypos = height/2; // Print a list of the serial ports, for debugging purposes: println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Keyspan adaptor, so I open Serial.list()[0]…. // (in case you tend to start Processing before you start your // external device): if (firstContact == false) { delay(300); port.write(65); }}void serialEvent(Serial port) { // if this is the first byte received, // take note of that fact: if (firstContact == false) { firstContact = true; } // Add the latest byte from the serial port to array: serialInArray[serialCount] = port.read(); serialCount++; // If we have 3 bytes: if (serialCount > 2 ) { xpos = serialInArray[0]; ypos = serialInArray[1]; fgcolor = serialInArray[2]; // print the values (for debugging purposes only): println(xpos + “\t” + ypos + “\t” + fgcolor); // Send a capital A to request new sensor readings: port.write(65); // Reset serialCount: serialCount = 0; }}The microprocessor is reading its sensors, then listening for a byte of data from the Director program. Continue reading

Posted in Processing | Comments Off

MIDI for the BX-24

This page covers the details of MIDI communication on the BX-24. To send MIDI out from the BX-24, you use the serial commands. You need to set the baudmode to match MIDI settings. You can’t use COM3 for MIDI, because … Continue reading

Posted in BX-24, circuits | Comments Off

Intro to MIDI using PicBasic Pro

This page covers only the details of MIDI communication on the PIC using PicBasic Pro.

Posted in PicBasic Pro, circuits | Comments Off

Random Numbers and Physical Computing

That can take up lots of processing time, so it’s usually the first function to go when writing a microprocessor language.In fact, most of what you do in programming physical computing projects is to figure out how to deal with the world’s natural randomness and make it look smooth…. Your consciousness is a great leveller for the sensors that are your eyes, ears, skin, nose, and taste buds When you move a photoresistor from one room to another, your readings will be totally different, and all of a sudden, you have to re-calculate what is "average" and what constitutes the lighting change that you want. Continue reading

Posted in AVR, BX-24, PIC, PicBasic Pro, XBee, arduino/wiring, misc, pBasic (Basic stamp) | Tagged , , | Leave a comment

Branch

BRANCH allows branching to one of multiple subroutines depending on the value of a specified variable…. If value = 1, the program goes to label2. Continue reading

Posted in pBasic (Basic stamp) | Comments Off

Sound in to a Microntroller

Microcontrollers can take sound in as an analog input, for crude measurements. While 8-bit ones  (the Basic Stamp, BX-24, PIC, Arduino, etc) are not fast enough to read the frequency difference between various sounds, they can read sound levels. A … Continue reading

Posted in BX-24, arduino/wiring, circuits | Tagged , , , , | Leave a comment

Serial Call-and-Response (Director/Lingo)

It runs this checking routine repeatedly (in the exitframe or idle), so that if there are some bytes, but not a full three, it skips the whole routine and goes about its other business.This example uses Geoff Smith’s SerialXtra version 1.0 for Director. The full version of the Director code can be downloaded as a Director .dir file here, or as a text file (the main movie script) here.Lingo side:on exitFrame doSerial go the frameend on doSerial — see if the port’s been opened: If serialObject.isPortOpen() then If serialObject.charsavailable() = 0 then –send a byte to ask for data SerialObject.writeChar(“A”) End if If SerialObject.charsAvailable() >=3 then –first byte sent by microcontroller: MyVar = SerialObject.readNumber() –next byte sent by microcontroller: MyVar2 = SerialObject.readNumber() –third one sent by microcontroller: MyVar3 = SerialObject.readNumber() end if end if end The microprocessor is reading its sensors, then listening for a byte of data from the Director program. Continue reading

Posted in Lingo | Comments Off

Analog in using RCTIME

The RCTIME command is used to obtain a varying number from the charge or discharge of a capacitor in a resistor-capacitor circuit. The PWM command produces a modulated pulse on an oputput pin to simulate a varying voltage. Continue reading

Posted in PicBasic Pro | Comments Off

Stepper Motor Control

for i = 1 to 100 thisStep = i mod 4 call stepMotor(thisStep) next ‘ move motor backward for i = 100 to 1 step -1 thisStep = i mod 4 call stepMotor(thisStep) next loopEnd Subsub stepMotor(byref whatStep as integer) ‘ sets the value of the eight pins of port c to whatStep register.portc = motorStep(whatStep) call delay (0.1) ‘ vary this delay as needed to make your stepper step.end subPicBasic Pro code:start: High PORTB.0′ set variables:x VAR BYTEsteps VAR WORD stepArray VAR BYTE(4)clearTRISD = %11110000PORTD = 255input portb.4Pause 1000stepArray[0] = %00001010stepArray[1] = %00000110stepArray[2] =%00000101stepArray[3] = %00001001main: if portb.4 = 1 then steps = steps + 1 else steps = steps – 1 endif portD = stepArray[steps //4] pause 2 GoTo main pBasic (Basic Stamp 2) code:’ set variables:x var bytestepper var nibsteps var word’ set pins 8 – 10 as outputs, using DIRS to do so:dirs.highbyte = %00001111main: steps = 200 gosub clockStep pause 1000 gosub counterClockStep pause 1000goto mainclockStep: debug “counter” , cr for x = 0 to steps lookup x//4, [%1010,%1001,%0101,%0110], stepper outs.highbyte.lownib = stepper pause 2 nextreturncounterclockStep: debug “clockwise”, cr for x = 0 to steps lookup x//4, [%0110,%0101,%1001,%1010], stepper outs.highbyte.lownib = stepper pause 2 nextreturnWiring Code (for Arduino board):This example uses the Stepper library for Wiring/Arduino…. You can use// any digital I/O pins.#include <Stepper.h>#define motorSteps 200 // change this depending on the number of steps // per revolution of your motor#define motorPin1 8#define motorPin2 9#define ledPin 13// initialize of the Stepper library:Stepper myStepper(motorSteps, motorPin1,motorPin2); void setup() { // set the motor speed at 60 RPMS: myStepper.setSpeed(60); // Initialize the Serial port: Serial.begin(9600); // set up the LED pin: pinMode(ledPin, OUTPUT); // blink the LED: blink(3);}void loop() { // Step forward 100 steps: Serial.println(“Forward”); myStepper.step(100); delay(500); // Step backward 100 steps: Serial.println(“Backward”); myStepper.step(-100); delay(500); }// Blink the reset LED:void blink(int howManyTimes) { int i; for (i=0; iFor more on steppers, see the DC motor notes on this site. Continue reading

Posted in BX-24, PicBasic Pro, arduino/wiring | Comments Off

PicBasic Pro Debug Statement

You have to define the debug port and pin, the baud rate, and the mode at the top of your program, and you can’t change any of these settings within the progam…. Here’s a photo of the connections: And here’s the schematic for the DB-9 connector (note: the above diagram does not include the 22Kohm resistor shown in this schematic): Note the different modes you can use to display a variable. Continue reading

Posted in PicBasic Pro | Comments Off