Serial.available() is 0

hello
i am trying to establish a serial-connection between an arduino uno (with motor-stepper shield) and flash (i am using serproxy in between).
flash tells me the socket is connected, but when i writeBytes the Serial.available() is always 0

#include <AFMotor.h>

AF_DCMotor motor( 4 );

char val;

void setup() {
  Serial.begin( 9600 );

  motor.setSpeed( 200 ); 
  motor.run( RELEASE );
}


void loop()
{
  Serial.println( Serial.available() );
  
  if( Serial.available() > 0 )
  {
    val = Serial.read();
    Serial.println( val );
    
    motor.setSpeed( 200 );
    motor.run( FORWARD );
  }
  
  delay( 100 );
}

in flash:
arduino = new Socket( “127.0.0.1”, 5331 );

arduino.writeUTFBytes(“D”);
arduino.flush();

can anybody tell me if there is something missing?!
of course, when i write: if( Serial.available() == 0 ) the motor drives…
its just that Serial.available() is always ‘0’

thank you very much!
flo

Where do you set the baud rate at the PC end?

well, thats a good question. where do i have to set it? :~ i cant figure out any option in flash ...

UPDATE: well, changing the ip-adress to "localhost" drives the motor even though Serial.available() is still printing 0. any ideas?!

by the way, opening the serial monitor crashes the arduino software pretty often... i've got no idea what thats all about.

where do i have to set it?

I have no idea but if it is a different speed to the arduino it will explain why it is not receiving anything.

i am using serproxy in between

This might mean looking at the serproxy for baud settings or looking at the documentation to see if it is a fixed rate. Also the number of data bits and parity have to match.

opening the serial monitor crashes the arduino software pretty often

That might happen if something else has already opened that same serial port.

oh my god, i was definitely too late last night.
i changed the baud-rate in that serproxy and had to change back that ip-adress.
now it works. thanks for that mate!!!
well, here is some code update. i think someone might be interested in…

with this you are able to change speed and direction of a single dc-motor from flash (without firmata and as3glue):

#include <AFMotor.h>

AF_DCMotor motor( 4 );

union u_tag
{
    byte b[4];
    float ival;
} u;

float value;



void setup() {
  Serial.begin( 9600 );

  motor.setSpeed( 0 ); 
  motor.run( RELEASE );
}



void loop()
{
  Serial.print( Serial.available() );
  
  
  if(Serial.available() > 3)
  {
    u.b[0] = Serial.read();
    u.b[1] = Serial.read();
    u.b[2] = Serial.read();
    u.b[3] = Serial.read();
    
    value = u.ival;

    Serial.print(value, DEC);
    
    Serial.print(0, BYTE);
    
    
    
    if( value == 0 )
    {
      motor.setSpeed( 0 );
      motor.run( RELEASE );
    }
    
    else if( value < 0 )
    {
     motor.setSpeed( value );
     motor.run( BACKWARD ); 
    }
    
    else if( value > 0 )
    {
     motor.setSpeed( value );
     motor.run( FORWARD ); 
    }
    
    
  }
}

flash (document-class called “Main”):

package 
{
	import flash.net.Socket;
	import flash.utils.Endian;
	import flash.events.MouseEvent;
	import flash.display.Sprite;
	import flash.events.Event;
	import fl.events.SliderEvent;
	import fl.controls.Slider;
	
	
	

	public class Main extends Sprite
	{
		private var arduino : Socket;
		private var draggerValue : Number = 0;
		
		
		
		
		public function Main()
		{
			init();
		}
		
		
		
		private function init()
		{
			arduino = new Socket();
			arduino.endian = Endian.LITTLE_ENDIAN;
			arduino.connect( "127.0.0.1", 5331 );
			
			arduino.addEventListener( Event.CONNECT, onSocketConnect );
			arduino.addEventListener(Event.CLOSE, onSocketClose );
			
			
			initUI();
		}
		
		
		
		private function initUI():void
		{
			var mySlider:Slider = new Slider();
				mySlider.minimum = 0;
				mySlider.maximum = 255;
				mySlider.liveDragging = true;
				mySlider.snapInterval = 1;
				mySlider.tickInterval = 25;
				mySlider.move(100, 100);
				mySlider.width = 255;
				
				mySlider.addEventListener( SliderEvent.THUMB_DRAG, thumbDragHandler );
				
			addChild( mySlider );
		}
		
		
		
		
		private function onSocketConnect( e : Event ):void
		{
			trace( "connected" );
		}
		
		
		private function onSocketClose( e : Event ):void
		{
			trace( "closed" );
			arduino.connect( "localhost", 5331 );
		}
		
		
		
		private function thumbDragHandler( event : SliderEvent ):void
		{
			draggerValue = event.value;
			
			arduino.writeFloat( draggerValue );

			arduino.flush();
			
			trace( draggerValue );
		}
		
		
	}
}

cheers :wink:
flo

edit: now i see that its not yet implemented to reverse the motors direction.
think i will supply this later on. :slight_smile: