# Category Archives: BX-24

## Controlling Inkjet Printers from a microcontroller

There was an interesting thread on the Sketching in Hardware mailing list a while back on how to control an inkjet printer.   Wendy Ju started the discussion. Following are some of the links from that thread: A closed, proprietary portable … Continue reading

Posted in arduino/wiring, AVR, BX-24, circuits, pBasic (Basic stamp), PIC | Tagged | 1 Comment

## Serial Call-and-Response (Microcontroller side)

If the incoming value is a valid byte (i.e. 0 – 255), the program then reads two analog inputs and one digital input. It divides the anaog inputs by 4 to convert the ranges to 0 = 255, and sends all three sensor values out serially. Continue reading

Posted in arduino/wiring, BX-24, PicBasic Pro | Comments Off on Serial Call-and-Response (Microcontroller side)

## Linearizing Code for Sharp GP2D120 Infrared Ranger

Arduino/ATMega8 hardware connections: A0/PC5: potentiometer on analog in 1 D0/PD0/RX0: Serial input from the PC via MAX232 or hex inverter D1/PD1/TX0: Serial output to PC via MAX232 or hex inverter Distance ranging formula comes from Acroname, http://www.acroname.com: http://www.acroname.com/robotics/info/articles/irlinear/irlinear.html Created 6 Oct. 2005 Updated 25 Oct. 2005 */int val; // outgoing ADC valueint distance = 0;//function prototype:void blink(int howManyTimes);void setup(){ // start serial port at 9600 bps: beginSerial(9600); blink(3);}void loop(){ // read analog input: val = analogRead(0); // send analog value out: printString(“Analog Value =\t”); // Calculate linear slope of reading (thanks, Acroname!): distance = (2914 / (val + 5)) – 1; printInteger(distance); printString(“\n\r”); // wait 10ms for ADC to reset before next reading: delay(10); }// Blink the reset LED:void blink(int howManyTimes) { int i; for (i=0; i< howManyTimes; i++) { digitalWrite(13, HIGH); delay(200); digitalWrite(13, LOW); delay(200); }}Written for the BX-24: ‘GP2D120 sensor example ‘by Tom Igoe ‘ Reads a changing voltage from a GP2D120 IR ranging sensor ‘ on analog input 0 and sends the result out in ASCII-encoded ‘ decimal numbers. ‘ Analog in is on pin 15 of the BX-24 ‘ Distance ranging formula comes from Acroname, http://www.acroname.com:’ http://www.acroname.com/robotics/info/articles/irlinear/irlinear.html ‘ created 6 Oct 2005’ Updated 25 Oct. 2005 dim val as integer ‘ outgoing ADC valuedim distance as integersub main () call blink(3)do’ read analog input: val = getADC(15) ‘ Calculate linear slope of reading (thanks, Acroname!): distance = (2914 / (val + 5)) – 1 ‘ send analog value out: debug.print “Distance = “; cStr(distance) ‘ wait 10ms for ADC to reset before next reading: call delay(0.01) loopend sub’ Blink the reset LED:sub blink(byVal howManyTimes as integer) dim i as integer for i=0 to howManyTimes call putPin(26, 1) call delay(0.2) call putPin(26,0) call delay(0.2) nextend subWritten in PicBasic Pro, tested on a PIC18F252:’ GP2D120 sensor example’ by Tom Igoe ‘ Reads a changing voltage from a GP2D120 IR ranging sensor’ on analog input 0 and sends the result out in ASCII-encoded’ decimal numbers. Continue reading

Posted in arduino/wiring, BX-24, PicBasic Pro | Comments Off on Linearizing Code for Sharp GP2D120 Infrared Ranger

## Qprox Capacitive Touch Sensors

These sensors work best as touch sensors, with the conductor embedded just below the surface of the object — for example, with the sensor underneath a cloth covering, cardboard covering, etc. The closer you can put the conductor to the chip that reads it, the better…. For this example, I used a QT113, but you can use the QT113H with the same circuit.Note: Digikey carries these sensors in the US, so there is no need to order directly from England.The wiring for the QT sensors is as follows: The connecting wire between the sensor and the pin is sensitive to touch as well. Continue reading

Posted in arduino/wiring, BX-24, PicBasic Pro | Comments Off on Qprox Capacitive Touch Sensors

## DC Motor Control with a TIP120 Transistor

Here’s the schematic for the capacitors and the regulator:The simplest program for this would be as follows (on the BX-24): Sub main() call delay(0.5) ‘ start program with a half-second delay do call putPin(13,1) call delay(1.0) call putPin(13,0) call delay(0.5) loopend sub In PicBasic Pro, the code would be as follows: pause 500 ‘ start program with a half-second delay main: high PORTD.2 pause 1000 low PORTD.2 pause 1000goto mainFor pBasic and mBasic, use the PicBasic Pro example and change the pin names.If your power supply for the microcontroller is compatible with your motor, you can wire the motor supply in parallel with the 5V regulator. For example, I use a 12V DC 1000 mA power adaptor, so I can use a 12V motor, if the power from the motor is wired in parallel with the 5V regulator’s input, like so:Note that the motor and the BX24 need a common ground (in our case, they get it through the transistor’s base; see above schematic).A motor controlled like this can only be turned in one direction. Continue reading

Posted in BX-24, pBasic (Basic stamp), PicBasic Pro | Comments Off on DC Motor Control with a TIP120 Transistor

## 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 on MIDI for the BX-24

## 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

| Tagged , , | Leave a comment

## 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 arduino/wiring, BX-24, circuits | | Leave a comment

## 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 arduino/wiring, BX-24, PicBasic Pro | Comments Off on Stepper Motor Control