Go Down

Topic: Arduino ignoring Flash (Read 1 time) previous topic - next topic

thedarkglove

Hi,

I hope someone can help me out here.... this has ruined my day. So close but something aint right... :(

I have been trying to get this to work:

http://www.youtube.com/watch?v=ogSvvYSdews

Everything seems to be as it should but my Arduino doesn't seem to receive the 0's and 1's sent from Flash.

What works:
My flash file runs and serproxy displays "Server thread launched" and "server(7) - thread started"
I did a little idiot testing and found that this failed if the Arduino wasn't connected or if I changed the settings in the serproxy config file, so it seems to be connected.

My flash trace statements show up when I push and release the button, proving that the functions are being called.

Another thing I have done to test my Arduino is OK is to not use serproxy, changed my "if(incoming == 0)" to "if(incoming == 50)" and used the serial monitor to send keystrokes... the LED will switch off if I send it "2" and on if I send it anything else....


So that leads me to think that the all important 0's and 1's aren't getting from Flash to the Arduino and are being squished by the proxy somehow.

Here's my code:

AS3
Code: [Select]

package
{
    import flash.display.Sprite;
    import com.greensock.*;
    import flash.display.Sprite;
    import flash.net.Socket;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.events.MouseEvent;
   
   
    public class myArduinoFlash extends Sprite
    {
        public var test
        public static const PORT:Number = 5337;
        public static const LOCALHOST:String = "127.0.0.1";
       
        private var socket:Socket = null;
       
        public function myArduinoFlash()
            {
                trace ("myArduinoFlash is Running!");
               
                super();
                init();
               
            }
            private function init():void
            {
                socket = new Socket();
                socket.addEventListener(Event.CONNECT, doSocketConnect);
                socket.addEventListener(Event.CLOSE, doSocketClose);
                socket.connect(LOCALHOST, PORT);
            }
            protected function doArcadeDown(event:MouseEvent):void
            {    trace ("doArcadeDown");
                socket.writeInt( 1 );
                trace("down");
            }
            protected function doArcadeUp(event:MouseEvent):void
            {    trace ("doArcadeUp");
                socket.writeInt( 0 );
                trace("up");
            }
            protected function doSocketConnect(event:Event):void
            {
                trace ("doSocketConnect");
                btnarcade.addEventListener(MouseEvent.MOUSE_DOWN, doArcadeDown);
                btnarcade.addEventListener(MouseEvent.MOUSE_UP, doArcadeUp);
            }
            protected function doSocketClose(event:Event):void
            {    trace ("doSocketClose");
                btnarcade.removeEventListener(MouseEvent.MOUSE_DOWN, doArcadeDown);
                btnarcade.removeEventListener(MouseEvent.MOUSE_UP, doArcadeUp);
            }
           
    }
}



serproxy.cfg

Code: [Select]

# Config file for serproxy
# See serproxy's README file for documentation

# Transform newlines coming from the serial port into nils
# true (e.g. if using Flash) or false
newlines_to_nils=true

# on a mac you will need to add this
#serial_device1=/dev/tty.usbserial-A6004osh

# Comm ports used
#comm_ports=1,2,3,4,5,6,7
comm_ports=7

# Default settings
comm_baud=9600
comm_databits=8
comm_stopbits=1
comm_parity=none

# Idle time out in seconds
timeout=300

# Port 1 settings (ttyS0)
net_port1=5331

# Port 2 settings (ttyS1)
net_port2=5332

# Port 3 settings (ttyS2)
net_port3=5333

# Port 4 settings (ttyS3)
net_port4=5334

# Port 7 settings (ttyS6)
net_port7=5337



Arduino
Code: [Select]

int ledPin = 13;

void setup()
{               
  Serial.begin( 9600 );
  pinMode(ledPin, OUTPUT);   
}

void loop()
{
  int incoming = 0;

  if( Serial.available() > 0)
  {
    incoming = Serial.read();
   
    Serial.print("I received: ");        // used for testing in Serial Monitor
    Serial.println(incoming, DEC);

    if(incoming == 0)
    {
      digitalWrite(ledPin, LOW);    // set the LED off
    } else {
      digitalWrite(ledPin, HIGH);   // set the LED on
    }
   
   Serial.println(incoming);
  }
  delay(200);              // wait for a second

}



I am a bit of a noob so I wouldn't be surprised if it was something obvious..... but after 7 hours, I  have given up.

Any ideas?

Thanks.

TDG.

nickgammon

Try this:

http://arduino.cc/forum/index.php?action=printpage;topic=54974.0

Pertinent suggestions seem to be:


  • Writing an int writes 4 bytes but you are only receiving 1, try writing a byte

  • You need to possibly flush the socket after writing

Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

thedarkglove

Hi Nick,

Thanks for the quick reply, just didn't have a chance until now to try out your suggestion.

TBH I don't really understand how to write just one byte... but adding a flush after each write worked.

What I don't understand is why I had to add a flush and Mr Adobe didn't....

AS3 code for those who want to see where I put the flush:
Code: [Select]

protected function doArcadeDown(event:MouseEvent):void
{ trace ("doArcadeDown");
socket.writeInt( 1 );
socket.flush();
trace("down");
}
protected function doArcadeUp(event:MouseEvent):void
{ trace ("doArcadeUp");
socket.writeInt( 0 );
socket.flush();
trace("up");

nickgammon


TBH I don't really understand how to write just one byte...


Code: [Select]
socket.writeByte (1);
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

thedarkglove

*hangs head*

Yes.

That makes sense.

Thanks, Nick.

Go Up