Friday, December 24, 2010

Dorkbot SoCal Dec. 28

Dorkbot SoCal 42: Snowball Blaster Demo in Santa Clarita

***** Tuesday, December 28, 2010
***** 7:00pm
***** The Driveway of Ric Turner
***** Santa Clarita, CA 91354

Google map:

Ric Turner - Snowball Blaster
http://www.youtube.com/watch?v=xDZtIirXXtQ




This is a special holiday edition of Dorkbot SoCal, held at perhaps the most ambitious light display in Southern California. We'll meet at the driveway of Ric Turner at 7pm on Tuesday December 28th 2010, and he'll demo and explain his latest Christmas Light video game project, Snowball Blaster.

Ric Turner is a former Disney Imagineer who created special effects for theme park attractions and shows such as Space Mountain, The Haunted Mansion, and the Finding Nemo Submarine Voyage.

Snowball Blaster Description

Hop in Santa's electric training sled and grab the game controller for an adventure in snowball dodging. Press the left button to move left and the right to move right. Make it past all the snowballs for a big light show! (nobody has made it yet!) Game is easy enough for kids and challenging for adults... and quite addictive.

Snowball Blaster has 128 channels of Light-o-rama controlled by a PC. The game logic is running on a Basic Stamp which accepts inputs from the player switches and controls the Red Arrows with sold state relays. The BS also sends logic level triggers to the LOR system for Game start and Crash. The snowballs, scoreboard (and the rest of the light show live in the LOR program.) There are separate LOR programs for Attract, Crash and Game play. The BS knows when the snowballs reach the bottom, and compares that to where it knows the Arrow is to detect crashes.

The game is designed around the limitation of having very few positions to light up. The timing of when they light up is more versatile, so that's where the game lives. It's easy to learn, starts easy and gets harder pretty quick. The audio is broadcast on FM so people watching in cars get a good show too.

Come on out, and bring your friends and family!

Saturday, November 13, 2010

AtCrashSpace app

This is the support page for the AtCrashSpace app.

This app allows you to see if the Crash Space hackerspace in Los Angeles is open. If you are connected to a network inside Crash Space, you can also "check in" to indicate your presence.

Saturday, October 09, 2010

Dorkbot SoCal Oct. 16

Dorkbot SoCal 41

***** Saturday, October 16, 2010
***** 1:00pm
***** Machine Project
***** 1200 D North Alvarado Street
***** Los Angeles, CA 90026
***** Google map of Machine Project

David Resnick - Undulating Flux
http://www.davidresnick.me/

Undulating Flux is David's first-year project in the Arts Computation Engineering program at UC Irvine. The goal of Undulating Flux is to bring the participant into what psychologist Mihalyi Csikszentmihalyi termed a flow state, described as a state of being wherein action follows upon action according to an internal logic that seems to need no conscious intervention by the participant. Undulating Flux explores these questions by setting up a transduction chain wherein a vibrationist sends intense music and motion-synced vibrations into the participants body. The technology behind this project centers around the Nintendo Wii remote and the Max programming environment. The wiimote data is streamed into Max wherein parameters are set to control the intensity of each vibrator individually. A Max package called Maxuino is used to send the control data to an Arduino microcontroller, which is connected to the motors.




Theron Trowbridge - DIY 3D Printing

Theron Trowbridge lives in Los Angeles and manages the digital video encoding department of a Hollywood post production facility. A life-long DIY-er, he is a founding member of CRASH Space, a hackerspace in Los Angeles, where he helped build, maintain, and upgrade multiple MakerBot Cupcake CNCs. He has also 3D objects for priting and is a regular contributor to Thingiverse. In his spare time, Theron creates and performs weird computer-generated electronic music under the monicker Bangsplat.




Kevin Nelson - Nexus Pyrosphere
http://nexusorg.org/category/fire-art/pyrosphere-fire-art/

Created by the Nexus group, The PyroSphere is a 22 ft diameter geodesic sphere, elevated on five 15 ft legs for a total hieght of 37 ft. The sphere itself has 92 flame effect valves, each located at one of the sphere's 92 vertices, which emits a 3 to 4 ft fire ball, controlled individually by a microcontroller.

Thursday, September 23, 2010

Ducted Fan and Arduino

So I was looking for more of a breeze...




...seems like I've got some good breeze now with the 56mm ducted fan. Be careful, these ducted fans will slice your finger off!


Below is the sketch that works with the Great Planes ESC (adapted from other people's ESC sketches). It arms the ESC, then sweeps the speed up, stop, back to full speed, and sweeps back down to off.

#include <Servo.h>

Servo myservo;

void arm(){
// arm the speed controller, modify as necessary for your ESC
Serial.println("arming");
setSpeed(30);
delay(2000);
setSpeed(90);
delay(2000);
Serial.println("armed");
setSpeed(30);
delay(2000);
}

void setSpeed(int speed){
// speed is from 0 to 100 where 0 is off and 100 is maximum speed
//the following maps speed values of 0-100 to angles from 0-180,
int angle = map(speed, 0, 100, 0, 180);
myservo.write(angle);
}

void setup()
{
Serial.begin(115200);
myservo.attach(9);
arm();
}

void loop()
{
int speed;

Serial.println("Sweeping up");
for(speed = 37; speed <= 90; speed += 1) {
setSpeed(speed);
Serial.println(speed);
delay(100);
}
setSpeed(30);
delay(1000);
Serial.println("Sweeping down");
for(speed = 90; speed > 37; speed -= 1) {
setSpeed(speed);
Serial.println(speed);
delay(100);
}
Serial.println("30 halting...");
setSpeed(30);
delay(5000);
}

Sunday, September 19, 2010

Brushless Motor Test

I hooked up a Great Planes Ammo 20-40-3500 In-Runner Brushless Motor attached to Great Planes Silver Series 25A Brushless ESC 5V/2A BEC powered by Radio Shack 7.2V battery and controlled by Arduino servo library.

This ESC has three control wires. Brown is ground, Red is the ESC "battery eliminator ciruit (BEC)" +5V, and Orange is the servo pulse control. I hooked up the Brown wire to the Arduino ground, and the Orange wire to Arduino pin 9, and left the Red wire not hooked to anything:




Friday, September 17, 2010

Cross-method PHY2PHY?

So I'm all in to physical-to-physical interactions over the Internet (PHY2PHY), but here is an interesting cross-method interaction which is just asking to be extended over the Internet:

Saturday, September 11, 2010

Speeding up Arduino PWM

If you ever need to speed up the Arduino PWM frequency, here is an example. You can manipulate the counter prescalar with TCCR1B, and the amount it counts up each cycle with ICR1:

int i;

void setup()
{

pinMode(2, OUTPUT); // direction pin
digitalWrite(2, LOW); // set direction CW

TCCR1A = 0x00; // sets timer control bits to PWM Phase and Frequency Correct mode
TCCR1B = 0x12; // sets timer control bits to Prescaler N = 8
ICR1 = 500; // Upper Timer Limit

analogWrite(9,1); // for Geckodrive controller you want a very short on pulse

Serial.begin(115200);
Serial.println("Delaying 100...");
delay(100);

}

void loop()

{
for(i=500;i>70;i=i-1){
Serial.println(i);
ICR1=i;
delay(20);
}
for(i=70;i<500;i=i 1){
Serial.println(i);
ICR1=i;
delay(20);
}
}


I believe the prescalar leads to 16 MHz / 8 = 2 MHz, then I count up to 500 meaning about 4 kHz frequency output, then I move it up to a 70 count or 28.5 kHz.

Wednesday, September 08, 2010

Ducted fans!

When you are starting a new tech art project, you are engaging in a search for the best way to implement your idea.

As soon as you make a large purchase, you immediately will find an even better solution!

I've had lots of fun with the servomotors, but now I am wondering about ducted fans and from the R/C hobby world for breath-over-IP, it sure would be a BLAST!

They appear to have electronic speed control, but I wonder how fast they can speed up/slow down. Also I'd need a 34A @ 11V power supply, not hard for a big battery, but tougher for a 120V based system.

These R/C electric airplane motors are much faster than industrial servomotors (8-20 kRPM versus 3-4 kRPM), so I suspect their props are probably more efficient (more lift, less drag). Apparently you can get the motor and esc together or a ducted fan motor/prop/esc together well. But you better put some mesh on it or you will slice off someone's finger!

Saturday, September 04, 2010

Geckodrive accuracy test



I hooked up the quadrature encoder outputs from one Tohoko Ricoh Type 7K00011 servomotor into an Arduino. I am using the input pull-up trick of doing a digitalWrite(HIGH) on the quadrature input pins. The quadrature A and B inputs are translated by the Arduino program into the step and direction signals into Geckodrive 320X controller attached to a second 7K00011 servomotor.

One thing I found is that to ensure accuracy, the pulses going to the Geckodrive 320X must have a very short high time. I started with a 500 uS high time, but the second motor was not tracking the first one very closely. I ended up with 10 uS high time for the pulse, and that seemed to keep the two motor shafts perfectly synchronized. The Geckodrive is rated for Step Pulse "1" Time down to 1.5 uS.

A second thing I found is that for every one quadrature step on the first motor, I needed to send four pulses to the Geckodrive. There is something in the spec sheet that says "Feedback Resolution: X4 Encoder Line Count", so maybe that explains it.

Here is the code for this example (which can help you with quadrature encoder decoding in general as well):

//
// Use quadrature sensors in one unpowered motor to
// drive other powered motor in synchronized fashion
//

int a=0; // current quadrature A
int b=0; // current quadrature B
int al=0; // last quadrature A
int bl=0; // last quadrature B

void setup() {
pinMode(2, OUTPUT); // step to Geckodrive
pinMode(3,OUTPUT); // direction to Geckodrive
digitalWrite(3,LOW);
pinMode(6, INPUT); // A quadrature input
pinMode(7, INPUT); // B quadrature input
digitalWrite(6,HIGH); // pull-up A input
digitalWrite(7,HIGH); // pull-up B input
}

void pulse(int direction)
// perform one pulse
{
unsigned long wait=0;
digitalWrite(3,direction); // signal direction
for(int i=0;i<4; i){
wait=micros();
digitalWrite(2,HIGH);
while(micros()-wait<10); // high for 10 uS
digitalWrite(2,LOW);
wait=micros();
while(micros()-wait<15); // low for at least 15 uS
}
}

void loop()
{
a=digitalRead(6); // read quadrature A
b=digitalRead(7); // read quadrature B

// decode quadrature input
// and pulse in proper direction

if((al != a) || (bl != b)){
if((al == 0) && (bl == 0)){
if((a==0)&&(b==1)){
pulse(LOW);
}else if((a==1)&&(b==0)){
pulse(HIGH);
}
}
if((al=0)&&(bl=1)){
if((a==1)&&(b==1)){
pulse(LOW);
}else if((a==0)&&(b==0)){
pulse(HIGH);
}
}
if((al==1)&&(bl==1)){
if((a==1)&&(b==0)){
pulse(LOW);
}else if((a==0)&&(b==0)){
pulse(HIGH);
}
}
if((al==1)&&(bl==0)){
if((a==0)&&(b==0)){
pulse(LOW);
}else if((a==1)&&(b==1)){
pulse(HIGH);
}
}
}
// record history of last quadrature state
al=a;
bl=b;
}

Friday, September 03, 2010

Linux SBCs with Ethernet - too many!

Finally, the affordable (~$100) Linux SBC with Ethernet is here.

The Chumby Board is now available for $89. Add USB Ethernet connector for $15, and you've got yourself a $104 Ethernet-enabled Linux SBC with:
  • Freescale iMX.233 processor running at 454 MHZ
  • 64 MB onboard RAM
  • Comes with 512MB uSD card with 100 MB Linux installation all ready to go
  • 3 USB ports (2 after you add Ethernet)
  • Built-in Lithium Ion/Polymer battery charger and 5V boost converter for portable projects
  • 1.9W mono speaker amplifier into 4ohm (0.1" JST onboard connector)
  • Microphone input (0.05" JST onboard connector)
  • LCD controller with 2mm output port
  • 3.5mm A/V output jack with stereo audio and NTSC/PAL composite video
  • Quadrature encoder connections onboard
  • 5-way joystick on-board
  • MMA7455 3-axis +-2G to +-8G accelerometer on-board
Very interesting, and great competition to the Mini2440 board, which is $89 with Ethernet, with the same amount of RAM and 128MB of flash RAM on board (can be as big as 1GB for more money). The Mini2440 doesn't have the NTSC/PAL video, accelerometer, or battery charger.

I am having some trouble getting DHCP to work on the Mini2440 with the base Linux/Qtopia load (based on Busybox, it evidently uses udhcpc which requires me to write a not-well-documented script).

Meanwhile my SheevaPlug finally showed up ($99, but with 120VAC supply):


SheevaPlug

Not much time to play with it the SheevaPlug yet. I am intending to use it for an Ethernet-to-serial application (using a USB-to-serial converter).

The GPIO lines are pretty much hidden in the SheevaPlug, whereas the Mini2440 and Chumby Board have them easily available.

On the other hand, SheevaPlug ships with Python, so development on it is a breeze!

Thursday, September 02, 2010

Geckodrive is awesome

I am very impressed with the Geckodrive 320x. It works very well with the Tohoko Ricoh Type 7K00011 Servo Motor. I used an Arduino as the pulse source to control the speed:




As you hook up the Geckodrive 320X, follow the instructions step by step, and don't forget to hook Terminal 5 (ERR/RES) to Terminal 7 (Encoder +5VDC), or else the controller won't work. Also for the Tohoko Ricoh Type 7K00011 Servo Motor, you should set switch SW6 (HEDS) to "ON" to provide an active pullup for the encoder.

And the 320X didn't even get very warm - great heat engineering!

The Geckodrive is a highly precise device. You drive it with pulses. Each pulse means the motor is to move ahead on pulse on the encoder. Of course, motors can just speed up and slow down infinitely fast, so if you change the input pulse rate, there is a brief period of error where the Geckodrive applies a higher duty cycle PWM to the motor to catch up. However if the error is too much (configurable by DIP switches on the Geckodrive), the controller assumes there is a fault, stops for a second, accepts the new position as "good" and starts again.

At the end of the video above, I am probably trying to drive the motor faster than it can actually go, thus the controller faults out.

Also you can't just start the motor at its highest speed. You might have to start it at a slightly lower pulse rate and ramp it up to a higher speed, or else the controller might fault out. I am going to experiment with increasing the 256 count following error limit to the 2048 count following error limit and see how that changes the ability to do a cold start to a high speed.

Also I may try a sneaky thing where I hook up the encoder from a second motor to an Arduino, read the quadrature input to generate a pulse and direction signal, and send that into the Geckodrive to see if my twisting of the rotor on the undriven motor is reflected in the driven motor.

I think the Geckodrive and Tohoko Ricoh Type 7K00011 Servo Motor may work not only for "Breath 2 - the proportional version" but also for Ouija board over IP. I have to put a fan on the motor and see if I get a good breeze from it.

Tuesday, August 31, 2010

Meltdown

There is pretty much no heat sink on the Pololu Jrk 21v3 USB Motor Controller with Feedback. So basically that means if you try to do any kind of serious control of start/stop/speed of a real motor (say 24V / 0.3A), you will end up melting it. There isn't much in the manual about how to even mount a heat sink, the thing is so small and there is plenty of exposed solder blobs that it would be tough to do. Having made other motor controllers get seriously hot in the past using PWM control, I guess I'm not surprised.

I'm moving up to the Geckodrive G320X. The whole bottom of it is a heat sink.


Wednesday, August 18, 2010

Going servo part 2

So I went ahead and purchased:

Tohoko Ricoh Type 7K00011 Servo Motor (whose technical details are in this document)


and to power it all: 24VDC @ 6.5A power supply.

I suspect this is way overkill for a fan, but it should be interesting to enter the world of servomotors.






Wednesday, August 11, 2010

Going Servo

So I have this desire to redo "Breath" using a servomotor to accurately actuate breath strength, rather than just on/off. Here are some options:

1) Pololu has a 3A Motor Controller with feedback($49.95). It works with a tach on a motor, and you can interrogate it over USB to control/configure it and get all kinds of neat info. It also works with TTL, PWM, and analog input for control.

2) Geckodrive G320X 20A ($114) motor controller that works with a quadrature encoder. It only accepts pulse control. This is probably great if I needed bi-directional strict control of a big expensive motor with a quadrature encoder, but is probably overkill for a fan.

3) Encodergeek's Model 100 3A ($99) motor controller. It isn't clear to me if it works with tach or quadrature encoders (though he sells quadrature encoders, so you'd think it would work with them) and does pulse and analog control. He also sells his own 3A motors with encoders for $40, as well as compatible gearboxes, encoder wheels, encoders.

Also I'd need a motor. A case fan needs to spin up to 2K-3K RPM or so. I saw some motors with tach encoders over at All Electronics in Van Nuys, maybe I'll check there and see what they have.

Wednesday, August 04, 2010

Updates

Here are some quick updates:

My Breath OSC Interface App is now on iTunes, hurrah!

I am picking up from three years ago on DogCeleration. Especially now that my beagles are in LA and just had their first movie released, I thought they should join the art world as world. They key to interfacing with the Bluetooth BlueRadios on OS X is Zterm, just remember to hit shift when you run it to choose the right connection.

Alberto Gaitán recently mentioned the existance of Pachube, "realtime sensor, energy and environment data", which includes wind sensor data. Which would be a great source for "wind over IP" to a servomotor driven fan.

I also recently picked up a Mini2440, which is an awesome Linux-capable ARM-based SBC with Ethernet, serial ports, A/D converters, a cheap camera, and much more! I am still exploring it, but it seems pretty cool.


Tuesday, July 13, 2010

Breath OSC Interface iPhone App Support

This page is for support of the Breath OSC Interface iPhone App. Please feel free to ask any questions or provide bug reports below.


Friday, June 11, 2010

Ordered SheevaPlug

So I went ahead and put in an order for a SheevaPlug. They say it will take "2-3 weeks" from order date. I ignored the GuruPlugs because of the reported heat problems. I may use the SheevaPlug as a "more reliable/powerful" network interface for physical computing systems like Arduino that can hang off of its USB. I may also use it as an el-cheapo "meet-in-the-middle" server for PHY2PHY projects.

No sooner had I ordered the SheevaPlug did I see a neat mini-systemboard ALIX3d2. LAN / 2 miniPCI / LX800 / 256 MB / USB / 500 MHz AMD Geode LX800, $99. Needs an external DC power supply. But, hmmm.

Then I saw the Mini2440. Also in the $100 department, it has a 405 MHz Samsung S3C2440A ARM920T chip, a 3.5″ touch screen display, 2MB NOR flash, 64MB SRAM, and 128MB NAND flash, Ethernet, USB, COM, audio out. It comes preinstalled with Linux 2.6.3 and a Qtopia graphics. There seems to be a version without the touch screen a bit cheaper here. And it appears to have a cheap camera available as well. And, oh yeah, it has 8‐channel 10 bit A/D converter with sample and hold, and a bunch of digital GPIOs (more info here). And here is a video of the GPIO at work. This sounds like an awesome system for PHY2PHY projects, it could be its own webcam and webcam display as well.


Tesseract OCR

If you need a free OCR program, try Tesseract. It is awesome!!! Skip GOCR.

No problems building it on OS X. One thing you may need to know is to use ImageMagick "convert" command with "-depth 8" to build TIFF files that Tesseract can read.

Saturday, June 05, 2010

Breath-over-IP redux

So honestly, my breath-over-IP project is not at cool as I want it to be. It actually an on/off system rather than a more "analog" transmission of breath speed.

The problem is that the anemometer impeller and the output fan both have too much inertia. The anemometer impeller is incredibly sensitive, but once it starts spinning it can take several seconds to stop, even without any breath. The fan is the same way, once you turn it off, it takes several seconds to spin down.

So I am contemplating redoing Breath-over-IP using a servo motor and servo controller. This should allow me to speed up and slow down the fan motor very quickly. On the breath sensor side, I could use a pressure sensor chip.

Finally, I'd like to solve my networking challenges using a plug based Linux PC with a USB-attached Arduino. That way I can do very complex networking in Python on the plug computer, and let the Arduino handle analog/digital I/O, which it does well.

So that's my plan...

Wednesday, March 10, 2010

Physical Computing Talk TONIGHT [Thousand Oaks]

“Physical Computing – Interaction Design and Systems Engineering”

Wednesday, 10 March 2010, 6:30-8:30pm

Meetings are free and open to the public. Parking is free.

Carlyn Maw, a co-founder of CrashSpace, a Los Angeles Hackerspace, formerly an instructor and graduate of NYU ITP, presents an introduction to Physical Computing.

Physical Computing is a hands-on multidisciplinary approach to interaction design and systems engineering. It is neither electrical engineering light nor advanced hobby electronics, but rather a holistic approach to invention and problem solving. Practitioners are frequently experts in their fields who want to harness the power of electronics within their own discipline. Examples include:

· A musician composing a symphonies based on data collected from sensors on the body.
· An occupational therapist working to develop a pressure vest for children with sensory modulation disorders.
· A scientist tracking monkeys.
· A fashion designer creating a dress that unfurls like a flower.

Physical Computing methodologies quickly grab the imagination of beginners by treating electronics and programing as tools which extend what the new-comer already knows rather than as complete separate realms of expertise. With an emphasis on learning by doing and rapid prototyping, Physical Computing provides a quick pay off for those just starting out and for experts making “sketches.”
Additionally, Physical Computing has become a way of life for the communities forming around it. People around the world are working to increase the accessibility of the making things way of life. Carlyn will provide an overview of the conceptual approaches, tools, people and communities that are contributing to Physical Computing today.

Monday, March 01, 2010

Ignite LA tonight (Monday, March 1)

Tonight is Ignite/LA, the event where speakers get 5 minutes/20
slides/15 seconds per slide to give a lightning presentation.

At the last Ignite/LA, talks included:
- The Future of Money
- Turning AI gurus into Comets and Star Field Explosions
- Bubble Nets among Humpback Whales

- A talk by former Dorkbot SoCal speaker Heather Knight on Social Robotics:

- A talk on physical interactions over IP by myself

You MUST sign up to attend tonight ASAP here:


7PM
Cinespace
6356 Hollywood Boulevard
Los Angeles, CA 90028

Cinespace is an awesome venue, and after the talks you stay there for
live band karaoke hosted by Cedric Yarbrough of Reno 911.

-Thomas
http://www.t11s.com

Tuesday, February 23, 2010

Dorkbot SoCal March 20, 2010

Dorkbot SoCal 39

***** Saturday, March 20, 2010
***** 1:00pm
***** Machine Project
***** 1200 D North Alvarado Street
***** Los Angeles, CA 90026
***** Google map of Machine Project

Ruth West, Todd Margolis, Joachim Gossmann
http://www.atlasinsilico.net/

"ATLAS in silico" is the result of a vibrant collaboration between artists and scientists spanning new media, computer science, metagenomics, biology, and engineering.

Ruth West is an artist with background as a molecular genetics researcher. She is Director, Interactive Technologies for CENS (Center for Embedded Networked Sensing) on the UCLA campus and is concurrently an Artist-Research Associate at the UCSD Center for Research in Computing and the Arts, where she is the first CALIT2 New Media Artist crossing over to the Digitally Enabled Genomic Medicine Layer.

Todd Margolis is currently the Technical Director of the Center for Research in Computing and the Arts (CRCA) at UCSD. In 2004, he received his MFA in Electronic Visualization from the Electronic Visualization Laboratory at the University of Illinois at Chicago. He is a founding member of the immersive and interactive art and technology non-profit organization, Applied Interactives, and also a member of the art collaborative Sine::apsis Experiments.

Joachim Gossmann is an audiocentric media artist interested in a true interdisciplinary discourse between science and the senses. He is currently working on a PhD in Computer Music at the Center for Research and Computing in the Arts at U. C. San Diego. He also holds a a Tonmeister degree from University of the Arts, Berlin, a MFA in Composition/Experimental Sound Practices from the Californian Institute of the Arts, and has 6 years of professional experience in research, production and development of music in experimental media working at Fraunhofer IMK and the Center for Arts and Media Technology in Karlsruhe, Germany.



Dane Picard
http://www.danepicard.com/

Dane holds an MFA from CALARTS, and creates electronic sculptural works that blur the line between organic and inorganic.



MluM
http://mlum.com
MLuM is a Long Beach and Singapore based punceptual histriophonic art ensemble, comprised of multi-national artists whose creato-researchive interests include: The utilization and/or incorporation of scientific, scientistic and pseudo-scientific technologies, methodologies, idealogies and procedures in(to) aesthetic and artistic processes and practices; The aesthetics of sustainability; Sustainability as artistic tradition and genre; The geographics of social networking pertaining to the environmentics of location and mindset; Performance orientations relative to interactive systems within improvisational structures and environments; Charting influence within the aesthetic-ismos.

Always in search of collaborators, MLuM will deliver a paper (presented at MUSICACOUSTICA, Beijing) entitled "Databasethetics."


Tuesday, January 26, 2010

Breath-over-IP for Arduino

This is the code for breath-over-IP for an Arduino. This code uses the NewSoftSerial library, and assumes the use of a Lantronix Xport / Xport Direct (perhaps with a LadyAda Ethernet Shield).

#include <NewSoftSerial.h>

// breath-over-IP for Arduino

unsigned long time = 0; // time of last edge
int minTime = 25; // minimum time for edge
int good = 0; // number of consecutive good (fast) edges
int minGoods = 20; // minimum number of consecutive good (fast) edges to indicate breath

int ledPin = 13; // on-board LED pin
int irLedPin = 10; // IR LED attached to pin 12 with 220 ohm resistor
int irDetPin = 0; // IR phototransistor attached to analog 0 with 5V and 10K
int relayPin = 11; // solid-state relay pin

unsigned long onTime = 0; // relay on time'

int i=0; // counts up received breath packets for diagnostics
int light=0; // whether IR detector sees light or dark
int lastLight=0; // what IR detector saw last time
int state=0; // current state of state machine for reading HTTP

char c=0;

unsigned long sendTime=0; // last time breath packet was sent out

NewSoftSerial xport(3,2);

void setup()
{
pinMode(relayPin,OUTPUT);
digitalWrite(relayPin, LOW);

Serial.begin(57600);
xport.begin(9600);
xport.print("GET /update?d=B2&s=0 HTTP/1.1\r\nHost: phy-to-phy.appspot.com\r\n\r\n");
pinMode(ledPin, OUTPUT);
pinMode(irLedPin, OUTPUT);
digitalWrite(irLedPin, HIGH);
//Serial.print("Starting up");
}

void loop()
{
//Serial.println(analogRead(irDetPin));
if(analogRead(irDetPin)>850){
light=0; // impeller blade blocking IR
}
else{
light=1; // impeller blade not blocking IR
}

if(light != lastLight){
// edge
if(millis()-time<minTime){
// fast edge
good++;
}
else{
// not fast edge
good=0;
}
time=millis();
lastLight=light;
}

if(good>minGoods) {
// enough good (fast) edges
digitalWrite(ledPin,HIGH);
if(millis()-sendTime>100){
// send a breath, not too fast though
//Serial.print("I'm sending a breath\n");
xport.print("GET /update?d=B2&s=1 HTTP/1.1\r\nHost: phy-to-phy.appspot.com\r\n\r\n");
sendTime = millis();
}
}
else{
// not enough good (fast) edges
digitalWrite(ledPin,LOW);
if(millis()-sendTime>500){
// send a non-breath, not too fast though
//Serial.print("I'm sending a non-breath...\n");
xport.print("GET /update?d=B2&s=0&q=B1 HTTP/1.1\r\nHost: mylameapp.appspot.com\r\n\r\n");
sendTime = millis();

}
}
if(millis() - onTime > 5000){ // timeout after 5 seconds
digitalWrite(relayPin,LOW);
}

while(xport.available()){
c=(char)xport.read();
//Serial.print(c);
if((c=='B') && (state==0)){state=1;}
else if((c=='1') && (state==1)){state=2;}
else if((c==':') && (state==2)){state=3;}
else if((c=='1') && (state==3)){
digitalWrite(relayPin,HIGH);
onTime = millis();
//Serial.print("REMOTE BREATH!!!\n");
state=0;
}
else if((c=='0') && (state==3)){
digitalWrite(relayPin,LOW);
//Serial.print("No remote breath\n");
}
else state=0;
}
}