May 2004

Serial Call-and-Response (Processing)

This example for Processing shows how to take in a multi-byte string of serial data and process it byte by byte. In this example, the computer sends an “A” to the microcontroller, and the microcontroller sends three bytes in response. Each byte represents a sensor value.

After sending the “A”, the computer reads each byte in, adding it to a string until it has three bytes in the string. It then parses each byte of the string out into an int, and assigns values to three variables from those bytes.

This example is written for Processing,by Casey Reas and Ben Fry. It was last updated for beta version 115.

Continue Reading »

Processing

Permalink

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 it can’t reach the required baud rate, so you have to use COM1. Wiring is as follows:

Continue Reading »

BX-24
circuits

Permalink

Intro to MIDI using PicBasic Pro

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

Continue Reading »

PicBasic Pro
circuits

Permalink

Random Numbers and Physical Computing

Most microcontrollers don’t have a random function. Random functions are not truly random, they’re actually a complex mathematical formula that results in a number that “seems” random. 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. A photoresistor read through an analog-to-digital converter, for example, will never give you a nice steady number, it always fluctuates with tiny changes in lighting that your eye can’t see. 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. And that’s just one of many examples. The fact is, data from sensors is filled with the noise of the real world. Plan for it in advance.

Technorati Tags: , ,


Continue Reading »


AVR
BX-24
PIC
PicBasic Pro
XBee
arduino/wiring
pBasic (Basic stamp)

Permalink

Branch

BRANCH allows branching to one of multiple subroutines depending on the value of a specified variable. It’s the equivalent of a case statement. PicBasic Pro also has a BRANCH statement, as does mBasic. It looks like this:

BRANCH value, [label1, label2, label3...]

If value = 0, the program goes to label1. If value = 1, the program goes to label2. If value = 2, it goes to label3, and so forth.

 

Here’s a BS2 program illustrating BRANCH:

 

Continue Reading »

pBasic (Basic stamp)

Permalink

Serial Call-and-Response (Director/Lingo)

Here’s an example where a desktop computer running Director receives data from a BX-24. In this case, the BX-24 is sending 3 bytes, one for each of 3 analog sensors. the Director program checks to see how many bytes there are in the serial port buffer. If there are none, it asks for data. If there are five, it reads the data into five variables. 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.

Continue Reading »

Lingo

Permalink

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. The FREQOUT command pulses a frequency on the given pin.


Continue Reading »

PicBasic Pro

Permalink

Stepper Motor Control

A stepper motor is a motor controlled by a series of electromagnetic coils. The center shaft has a series of magnets mounted on it, and the coils surrounding the shaft are alternately given current or not, creating magnetic fields which repulse or attract the magnets on the shaft, causing the motor to rotate.

This design allows for very precise control of the motor: by proper pulsing, it can be turned in very accurate steps of set degree increments (for example, two-degree increments, half-degree increments, etc.). They are used in printers, disk drives, and other devices where precise positioning of the motor is necessary.

Continue Reading »

BX-24
PicBasic Pro
arduino/wiring

Permalink

PicBasic Pro Debug Statement

The debug statement in picBasic Pro is a limited version of asynchronous serial communication. 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. Once that’s done, though, sending messages to the PC is a snap. Connect the whatever pin you use on te PIC to debug to the serial input of a PC (pin 2 on a DB-9 serial connector), and connect pin 5 of the DB-9 connector to ground. Then open HyperTerminal, set the baud rate to 9600, and run this program.

Continue Reading »

PicBasic Pro

Permalink

ADC In (Low Level Version)

The analog-to-digital converters on the 18Fxx2, 16F87x, and 16F81x series PICs (and others) are of 10-bit resolution. This means that when they measure an incoming voltage, they compare that voltage to a reference voltage, and give you the comparison represented as a 10-bit number (0-1023).

To use the analog-to-digital converters on a PIC through picBasic Pro without using ADCIN, you need to know something about the special memory registers on the PIC related to the ADC. The registers you need are as follows (for more on these registers, see the data sheet):

  • ADCON0 - ADC configuration register 0
  • ADCON1 - ADC configuration register 1
  • TRISA/TRISE - input/output state register for port A (TRISE is for port E, on the 40-pin PICs only)
  • ADRESH - ADC conversion result register, high byte
  • ADRESL - ADC conversion result register, low byte

Continue Reading »

PicBasic Pro

Permalink