Using FlowStone to (Basically) Control an Arduino!

Hello! fellow Arduino users,

(I "stumbled" into this and thought it was way-cool!)

To control the brightness of a LED on Arduino Pin 9 to ground (I have an Uno, and don't forget the series resistor!), from FlowStone (1.1.3).
(Note: I am using Windows 7 64bit Home Premium and the Arduino-0022 version sketch editor.)
Use this demo sketch:

/*
Dimmer
NOTE: Accepts Hex Value from FlowStone "Com_Port_Tester.fsm"!!!
Demonstrates the sending data from the computer to the Arduino board,
in this case to control the brightness of an LED. The data is sent
in individual bytes, each of which ranges from 0 to 255. Arduino
reads these bytes and uses them to set the brightness of the LED.

The circuit:
LED attached from digital pin 9 to ground.
Serial connection to Processing, Max/MSP, or another serial application

created 2006
by David A. Mellis
modified 14 Apr 2009
by Tom Igoe and Scott Fitzgerald

This example code is in the public domain.

*/

const int ledPin = 9; // the pin that the LED is attached to

void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}

void loop() {
byte brightness;

// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
// set the brightness of the LED:
analogWrite(ledPin, brightness);
}
}

Then I went to the FlowStone website and found a program called "Com_Port_Tester.fsm".

Run this in FlowStone diagram with the com port set (mine is on COM3) and insure you have "Hex" set to "True".
Enable the top "Switch" to turn the com port on (green light on FlowStone SHOULD light).

In the input box (labeled "s" on both sides) enter a hex number from 00 to FF (FF is 255)
The LED on pin 9 on the Arduino SHOULD change brightness!

Next steps hopefully will allow FlowStone to read back the analog ports, control bit input/output, PWM, and servos!
(This will allow COMPLETE FlowStone control of the Arduino with no special software in FlowStone OR on the Arduino.)

***** I NEED LOTS OF HELP HERE so please take this example and run with it!!!!

(FlowStone is an AWESOME way to control an Arduino!!!)

Respectfully,
WillBuilder

Hello again,

I am going to continue my own thread about how to go a step forward and reliably read analog data into FlowStone (from an Uno).

My modified sketch:

/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor (in this case FlowStone!)
Also control a LED on pin 9 with that (scaled) analog value.
(I am reading back from a Sharp IR range-finder and that is the reason for the delay(200) )
(The "dummy" serial read just help keep things in better sync.)
This example code is in the public domain.
*/

// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
Serial.begin(9600);
}

void loop() {
byte dummy;

if (Serial.available());
dummy = Serial.read();
int sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
Serial.println(sensorValue, DEC);
delay(200);
}

I again use "Com_Port_Tester"

(I leave "Hex" turned to "false" this time. I also send (s) a "0" but most other characters should work too.)

On to bigger and better things!

Again, I am doing pretty well with the Arduino code (so far...) but any help would be greatly appreciated!

Respectfully,
WillBuilder

BTW I use Scratch too with the latest S4A (now with servo position control.) It's awesome, but that is another topic entirely...

outputValue = map(sensorValue, 0, 1023, 0, 255);

Perhaps you should look at how many steps are required to essentially divide sensorValue by 4.

Good point, PaulS. Well worth thinking about.

I need LOTS of help with writing the Arduino Sketch to interface with FlowStone. I am pretty good at short sketches, but NOT at long ones....

I DO believe the final result, with an easy to use FlowStone module would be well worth the effort.

Hello,

What I really need help with now is to read data back from the Unu ADC (like I do in the above sketch) AND be able to control a
SERVO by sending it an integer from say 0 to 179. So I tried "mashing" some servo control code into the above sketch...
I got no error messages, but I also couldn't get the SERVO and (again my above sketch) to work together.
My "code" is so poor quality I don't want to even show it here. :~
(I did run the servo demo "sweep" sketch and the the servo worked as it should, sweeping nicely.)

(See, I am "stuck" already in writing the control sketch. Someone does need to step in and write some serious code! :grin:)

I can start this project but that is about all I can do for it.

Thanks in advance,
WillBuilder

My "code" is so poor quality I don't want to even show it here.

You want help with it, or not? Your choice.

there is a trouble with this code :

  byte dummy;
  
  if (Serial.available());
  dummy = Serial.read();
  int sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);  
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);
  Serial.println(sensorValue, DEC);
  delay(200);
}

if (Serial.available()); do nothing ....

may be I would be better to write it with {} like :

  byte dummy;
  
  if (Serial.available())
  {
     dummy = Serial.read();
     int sensorValue = analogRead(analogInPin);
     outputValue = map(sensorValue, 0, 1023, 0, 255);  
     analogWrite(analogOutPin, outputValue);
     Serial.println(sensorValue, DEC);
     delay(200);
 }

or

  if (Serial.available())
     dummy = Serial.read();

  int sensorValue = analogRead(analogInPin);
  outputValue = map(sensorValue, 0, 1023, 0, 255);  
  analogWrite(analogOutPin, outputValue);
  Serial.println(sensorValue, DEC);
  delay(200);

considering what you want to do

Hello,
and Thanks for the helping to explore the "Serial.available()" routines, the one in the sketch below works well for me.
(One thing I want to add is a PING))) ultrasound ranger on the same servo and look at its data at the same time.
(Not much of my own code here, just some glued together code a few demos, but better understanding them
will help with improving my ability to create better sketches.)

This sketch is for my simple IRDAR (Infra-Red Detection and Ranging) app.

#include <Servo.h>
/*
AnalogReadSerial_turnServo
Reads an analog input on pin 0, and prints the result to serial output
(Also sweeps the servo its full arc without the PC's help.)
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, 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
}

The Uno sweeps the servo, and then the sends the raw Sharp range-finder data back so that FlowStone can process (DSP) and display it.

Future versions will hopefully let FlowStone interact more with servo operation (speed, etc).
Adding a second servo for elevation (as well as the azimuth) control is an interesting idea for the future too.
(I would also like to experiment with a "home-made" IR or ultrasonic ranging device with a setup similar to the that inside the Sharp sensor.)

hello dude
I'm iniciating with flowstone and I cant put the serial Port comunicating with arduino connected to COM5.Did you have some example so I can open it in flowstone to see how you make the conections?
I need to make a GUI for a university project and I blocked.
Thanks for your time

hello dude :slight_smile:

My first post at the beginning of this topic was pretty much complete in how to get an Arduino (in my case an Uno) working
with FlowStone, no special software in FlowStone is needed. Try the "sketch" in the first post (in the ardino-0022 editor/programmer.)
Then I used:

Com_Port_Tester.fsm (all credits go to fixstuff555 for that)
at DSP Robotics Support • Search
(I am not sure how long that link will last, just search for "Com_Port_Tester.fsm")
(My Uno was on COM3, but COM5 should work too.)

Just out of curiosity which university are you going to?

and...
your welcome

Hi, dunno how policies are on necroposting (sorry in advance)
but i REALLY would like to expand on this.

I found a great project on the FlowStone forums:
http://www.dsprobotics.com/support/viewtopic.php?f=3&t=567&p=10371&hilit=arduino#p1770

As i try to wrap my head around the code (i only had some minor experience yet) i would like to integrate this PWM code here as one of the pinmodes in that sketch, as they are both in hex...
But i think the problem starts right there, that the sketch on the FlowStone forum is binary and thus controls 8 on/off states on the pins in one hex byte (00 to FF) and uses 3x a byte per update. While PWM would utilise one for a single pin in order to control brightness in the nice resolution of 256 values.
Is it possible to control the 6 PWM pins at once? Or should i come up with a mechanism to interleave the updating sends?

Anyone care to have a look with me? Maybe the originators of this post? (therefore my necropost)
cheers!