How to connect Arduino Leonardo to Adboe Flash

I can’t send data to my Flash project via leonardo since Uon is available. I use leonardo to connect the bluetooth device and below is the code.

#include <SoftwareSerial.h>


SoftwareSerial mySerial(10, 11); // RX, TX
byte c;

void setup()  
{

  Serial.begin(9600);
  while (!Serial) {
  }
  Serial.println("Start!!");

  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop()
{
  if (mySerial.available()){
    c = mySerial.read();
      Serial.write(c);
  }
}


I send “Hello” From phone to Uno, the Serial port show “Hello”.

Run serproxy and Flash. Then Send “Hello” from phone to Uno, the output of Flash will show “Hello”.


I send “Hello” From phone to Leonardo, the Serial port show “Hello”.

Run serproxy and Flash. Send “Hello” from phone to Leonardo, the output of Flash will not show “Hello”.

phone (bluetooth) -----> (bluetooth) Leonardo (USB) -------> (USB) PC

It is available that using the phone to send data to serial port of leonardo through bluetooth but my Flash project can’t receive the data after serproxy was opened.

#.cfg

newlines_to_nils=false

comm_baud=9600

comm_databits=8

comm_stopbits=1

comm_parity=none

timeout=300

comm_ports=4 
#when I use Uno, comm_ports=3
net_port4=5331
#when I use Uno, net_port3=5331
import flash.events.Event;
import flash.display.Sprite;
import flash.net.Socket;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.utils.Endian;

const TOGGLE_LED_STATE:String= "t";
const EOL_DELIMITER:String = "\n";
var _socket:Socket;
var _proxyAddress:String = "127.0.0.1";
var _proxyPort:int = 5331;

function onAddedToStage():void
{
 removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
 stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
 _socket = new Socket();
 _socket.addEventListener( Event.CONNECT, onConnect ); 
 _socket.addEventListener( Event.CLOSE, onClose ); 
 _socket.addEventListener( ProgressEvent.SOCKET_DATA, onSocketData );
 _socket.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
 _socket.addEventListener( SecurityErrorEvent.SECURITY_ERROR, onSecurityError );
 _socket.endian = Endian.LITTLE_ENDIAN;
 _socket.connect(_proxyAddress, _proxyPort);
}

function onConnect(event:Event):void
{
 trace("Socket Connected");
}

function onSocketData(event:ProgressEvent):void{
 var data:String = _socket.readUTFBytes( _socket.bytesAvailable );
 trace(data);
}

function onKeyPressed(evt:KeyboardEvent):void
{
 trace("onKeyPressed");
 if(!_socket.connected)
 {
 trace("You must be connected to send a command to the Arduino.");
 return;
 }
 switch (evt.charCode) {
 case Keyboard.A:
 trace(bg_mc.currentFrame);
 trace(bg_mc.totalFrames);
 break;
 case Keyboard.B:
 bg_mc.nextFrame();
 break;
 default:
 trace("keyCode:", evt.keyCode, "charCode:", evt.charCode);
 }
 _socket.flush();
}

function onClose(event:Event):void
{
 trace("Socket Closed");
}

function onIOError(event:IOErrorEvent):void
{
 timer.stop();
 timer.removeEventListener(TimerEvent.TIMER,counting);
 question_mc.visible = false;
 trace("IOErrorEvent : " + event.text);
}

function onSecurityError(event:SecurityErrorEvent):void
{
 trace("SecurityErrorEvent : " + event.text);
}

onAddedToStage();

Server thread launched
Server<5> - thread stared
Server<5> - EOF from sock
Server<5> exiting

Althought it is connected, leonardo can’t send data to Flash and I tried to use Serial1 to replace Serial.

anybody can help me to solve this problem, please!!

Chiman: It is available that using the phone to send data to leonardo but my Flash project can't receive the data after serproxy was opened.

You will need to explain this in a lot more detail.

Are you sending data to a phone? What sort of phone?

Have you a simple terminal program for the phone so you can verify that the data can be received properly?

On a Leonardo there should be no need to use SoftwareSerial because Pins 0 and 1 are available as Serial1.

...R

Robin2:
On a Leonardo there should be no need to use SoftwareSerial because Pins 0 and 1 are available as Serial1.

…R

Thank you for your suggestion and I find that those ways are work in communication between Leonardo and android app, but I think the problem is about the com port.

function onConnect(event:Event):void
{
trace(“Socket Connected”);
}

The above is work. After opening the serproxy and it show
“Server thread launched
Server<5> - thread stared”

The output in Flash trace Socket Connected but it can’t receive any data that I type in arduino or phone.
Is it can’t receive the “Serial.print” in arduino?

function onSocketData(event:ProgressEvent):void{
var data:String = _socket.readUTFBytes( _socket.bytesAvailable );
trace(data);
}

This process is for the flash receive data from arduino.

Chiman: but I think the problem is about the com port.

What com port?

I thought you were sending data to a Phone?

If you have the Leonardo connected to a PC using a USB cable then you should use Serial rather than Serial1

This process is for the flash receive data from arduino.

I have no idea what you mean by that. If you want help you will have to explain it fully.

...R

Sorry, It is the first time for me to use the forum, so the explanation may not fully.

Robin2: I thought you were sending data to a Phone?

If you have the Leonardo connected to a PC using a USB cable then you should use Serial rather than Serial1

My phone is used as input . Leonardo is connected to a PC using a USB cable and I have tried Serial and Serial1.

Since I need to connect the Flash and open serproxy, the serial port of Leonardo can't use. So I use my phone to be the input. I check it is no problem if I don't open the serproxy. I think that the problem is not in the phone.

When I use Uno to replace Leonardo, this connection has not any problem and I can use my phone to communicate with Flash via Uno.

The case is that if I use Leonardo, I just can send data to the arduino Serial port using my phone. After open the serproxy, the Flash programme cannot receive any data from arduino.

Does this diagram indicate what you are trying to do? (If not, please provide a correct diagram).

phone (bluetooth) -----> (bluetooth) Leonardo (USB) -------> (USB) PC

In that case the Leonardo communicates with the phone using Serial1 and with the PC using Serial.

But I still have no idea where Flash or this serproxy thing come into the picture. Are they on the PC or on the phone? Please explain in detail what Flash and serproxy are supposed to do.

If they are on the PC can you first use a terminal program (perhaps the Arduino Serial Monitor or puTTY) to confirm that the Leonardo can send data to the PC.

Because of the way the Leonardo creates a serial connection to the PC it can be a bit more troublesome than an Uno or Mega.

...R

I added the pic in the above. I confirm that the Leonardo can send data to the PC. I have tried other ways like putty and I can send data to PC. So I think the problem is about the serproxy or the Leonardo board do not support. And I found many page in the internet, no any page can give me the answer.

And I want to ask that do the mega32u4 not support this function?

Chiman: I added the pic in the above.

I am even more confused now.

Can you put your original post back the way it was and post the new information in a new Post after this Post

A Thread should make sense when read in chronological order.

...R

You right, I am confused too. Sorry for my poor writing skill. I tried to organize this post and open a new post. I hope you can understand the new post.

Link to OP's newer Thread

...R