Arduino to FlowStone test project.
Posted: Wed May 18, 2011 6:03 pm
Hello,
This is my first "test project" using the Arduino (Uno) together with FlowStone.
I use the A0 line of the Arduino to control the pitch of a sound based on voltage input.
Here is the sketch for the Arduino that sends data from A0 (analog input 0) to Flowstone:
(I use a servo to turn a Sharp GP2D120 IR Range-sensor. The shorter the distance, the higher the pitch. Works great! VERY Stable!)
----------------------------- cut here----------------------------------------
#include <Servo.h>
/*
AnalogReadSerial_turnServo
Reads an analog input on pin 0, prints the result to the serial monitor
(Also sweeps the servo its full arc without using PC processor time.)
This example code is in the public domain.
*/
Servo myservo; //create servo object to control a servo
const int analogInPin = 0; // Analog input pin
void setup() {
myservo.attach(8); // attaches the servo on pin 8 to the servo object
Serial.begin(9600); // start talking
}
int pos = 0; // variable to store the servo position
void readval()
{
byte dummy; // keep in sync
if (Serial.available());
dummy = Serial.read();
int sensorValue = analogRead(analogInPin); // Sharp sensor value
Serial.println(sensorValue*1.0, DEC); // Send raw data (range)
delay(200);
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
readval(); // range?
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
readval(); // range?
}
Serial.println(999, DEC); // flag end of full sweep
}
------------------------------cut here---------------------------
(Using th Arduino to control the servo 'frees up" FlowStone and every full sweep (0 to 180 and 180 to 0) I send out a flag for synchronization.)
Just program the above sketch into the Arduino. Attach the Arduino to the USB port (I use COM:3 at 9600 baud).
Load the FlowStone program and turn on the upper switch, that should do it! (Turn on your PC sound to hear the tones.)
(I use the Com_Port_Tester.fsm FlowStone program as the basis of my very basic FlowStone Arduino "module".)
So far I haven't done much with integer array I store (press the red trigger button to reset the index and clear the array).
This was a fun and highly educational project and I am sure so much more can be done!
This is my first "test project" using the Arduino (Uno) together with FlowStone.
I use the A0 line of the Arduino to control the pitch of a sound based on voltage input.
Here is the sketch for the Arduino that sends data from A0 (analog input 0) to Flowstone:
(I use a servo to turn a Sharp GP2D120 IR Range-sensor. The shorter the distance, the higher the pitch. Works great! VERY Stable!)
----------------------------- cut here----------------------------------------
#include <Servo.h>
/*
AnalogReadSerial_turnServo
Reads an analog input on pin 0, prints the result to the serial monitor
(Also sweeps the servo its full arc without using PC processor time.)
This example code is in the public domain.
*/
Servo myservo; //create servo object to control a servo
const int analogInPin = 0; // Analog input pin
void setup() {
myservo.attach(8); // attaches the servo on pin 8 to the servo object
Serial.begin(9600); // start talking
}
int pos = 0; // variable to store the servo position
void readval()
{
byte dummy; // keep in sync
if (Serial.available());
dummy = Serial.read();
int sensorValue = analogRead(analogInPin); // Sharp sensor value
Serial.println(sensorValue*1.0, DEC); // Send raw data (range)
delay(200);
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
readval(); // range?
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
readval(); // range?
}
Serial.println(999, DEC); // flag end of full sweep
}
------------------------------cut here---------------------------
(Using th Arduino to control the servo 'frees up" FlowStone and every full sweep (0 to 180 and 180 to 0) I send out a flag for synchronization.)
Just program the above sketch into the Arduino. Attach the Arduino to the USB port (I use COM:3 at 9600 baud).
Load the FlowStone program and turn on the upper switch, that should do it! (Turn on your PC sound to hear the tones.)
(I use the Com_Port_Tester.fsm FlowStone program as the basis of my very basic FlowStone Arduino "module".)
So far I haven't done much with integer array I store (press the red trigger button to reset the index and clear the array).
This was a fun and highly educational project and I am sure so much more can be done!