Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
09.02.2010 at 18:10:07
News: Server upgrade went fine, you are now at the new system


Pages: 1
Range sensor to Flash problem (Read 3479 times)
jimblibs
YaBB Newbies
*
Offline

Arduino rocks

Posts: 8

Range sensor to Flash problem
23.05.2008 at 10:17:23
 
Hi everyone

This is my first post. I’m a newcomer to the world of microcontrollers but I’m very excited about the possibilities of integrating this platform with Flash and Processing.

I’m having some issues with the Ping))) Ultrasonic Range Sensor. I’m trying to send the signal from the sensor back into Flash but it just doesn’t seem to work. I’ve been to the playground and have downloaded the Glue classes (I’ve been using the example Flash files that came with Glue) and serproxy. Interms of sketches, I’ve tried Firmata, Arduino > Flash and Cuartielles’ code from http://www.arduino.cc/en/Tutorial/UltrasoundSensor. I’ve even tried to combine some of them together! Cuartielles’ sketch is the only one which appears to make the sensor work (flashing LEDs that range in brightness depending upon proximity) but Flash is not picking this up

Currently I’m hooking up SIG on the sensor to the digital 7 pin although I have tried many other setups.

Here is my serproxy.cfg code:

Code:
newlines_to_nils=false

comm_ports=3

comm_baud=57600
comm_databits=8
comm_stopbits=1
comm_parity=none

timeout=300

net_port3=5333 



and here is my Actionscript – taken from the Glue examples files:

Code:
import net.eriksjodin.arduino.Arduino;
import net.eriksjodin.arduino.events.ArduinoEvent;
import flash.events.Event;

var a:Arduino;
a = new Arduino("127.0.0.1", 5333);

a.addEventListener(Event.CONNECT,onSocketConnect);
a.addEventListener(Event.CLOSE,onSocketClose);

a.addEventListener(ArduinoEvent.FIRMWARE_VERSION, onReceiveFirmwareVersion);
a.addEventListener(ArduinoEvent.DIGITAL_DATA, onReceiveDigitalData);
a.addEventListener(ArduinoEvent.ANALOG_DATA, onReceiveAnalogData);

function onSocketConnect(e:Object):void {
	trace("Socket connected");
	// request the firmware version
	a.requestFirmwareVersion();
}

function onSocketClose(e:Object):void {
	trace("Socket closed");
}

function onReceiveAnalogData(e:ArduinoEvent):void {
	//trace("Analog pin " + e.pin + " on port: " + e.port +" = " + e.value);
	trace("analogue value = " + e.value);


	var newX:Number = ( e.value - 10 ) / 10;
	box_mc.scaleX -= ( box_mc.scaleX - newX ) / 8;
	box_mc.scaleY -= ( box_mc.scaleY - newX ) / 8;


	//var newY:Number = ( e.value - 10 ) * 80;
	//box_mc.y -= (box_mc.y - newY) / 5

}

function onReceiveDigitalData(e:ArduinoEvent):void {
	//trace("Digital pin " + e.pin + " on port: " + e.port +" = " + e.value);
	trace("digital value = " + e.value);
}

function onReceiveFirmwareVersion(e:ArduinoEvent):void {
	trace("Firmware version: " + e.value);
	trace("Port: " + e.port);
	initArduino();
}

function initArduino():void {
	a.setPinMode(13, Arduino.OUTPUT);
	a.writeDigitalPin(13, Arduino.HIGH);
	a.setPinMode(6, Arduino.INPUT);
	a.enableDigitalPinReporting();
	a.setAnalogPinReporting(3, Arduino.ON);
	a.setPinMode(11, Arduino.PWM);
	a.writeAnalogPin(11, 255);
	trace("Firmware version is: " + a.getFirmwareVersion());
	trace("Analog pin 3 is: " + a.getAnalogData(3));
	trace("Digital pin 4 is: " + a.getDigitalData(4));
} 



I hope someone can help. Thanks in advance

Back to top
 
 
View Profile   IP Logged
Franklin
Senior Member
****
Offline



Posts: 294
Lacomb, Oregon
Gender: male
Re: Range sensor to Flash problem
Reply #1 - 24.05.2008 at 00:42:25
 
Did it work for you when you used the code on the page you linked?
Back to top
 
 
View Profile   IP Logged
jimblibs
YaBB Newbies
*
Offline

Arduino rocks

Posts: 8

Re: Range sensor to Flash problem
Reply #2 - 24.05.2008 at 02:27:22
 
In my circumstance, Cuartielles’ code went as far as making the LED embedded within the PING))) device blink at varying levels of brightness, upon interacting with it. I could not, however pass this information into Flash. Frustratingly, I managed to pass this data into Flash using the MaxSonar Ultrasonic Range Finder and the Firmata a couple of weeks ago, but the next day it didn't (and hasn't since) worked.
Back to top
 
 
View Profile   IP Logged
jimblibs
YaBB Newbies
*
Offline

Arduino rocks

Posts: 8

Re: Range sensor to Flash problem
Reply #3 - 27.05.2008 at 23:52:20
 
Any ideas guys. I really am stumped on this one...
Back to top
 
 
View Profile   IP Logged
jimblibs
YaBB Newbies
*
Offline

Arduino rocks

Posts: 8

Re: Range sensor to Flash problem
Reply #4 - 02.06.2008 at 02:06:17
 
Still stuck - I noticed that the correct data is being printed into the Serial Monitor but this is not being passed into Flash via serproxy. Am I right in assuming the error must therefore be with Serproxy or actionscript? If the information is being printed in the Arduino software, surely the problem is elsewhere.

Here is the sketch by the way:

Code:
/* Ultrasound Sensor
 *------------------
 *
 * Reads values (00014-01199) from an ultrasound sensor (3m sensor)
 * and writes the values to the serialport.
 *
 * http://www.xlab.se | http://www.0j0.org
 * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
 *
 */

int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13

void setup() {
  Serial.begin(9600);			// Sets the baud rate to 9600 - was Serial.begin(9600);
  pinMode(ledPin, OUTPUT);		// Sets the digital pin as output
}

void loop() {
  timecount = 0;
  val = 0;
  pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

  /* Send low-high-low pulse to activate the trigger pulse of the sensor
   * -------------------------------------------------------------------
   */

  digitalWrite(ultraSoundSignal, LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignal, LOW); // Holdoff

  /* Listening for echo pulse
   * -------------------------------------------------------------------
   */

  pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
  val = digitalRead(ultraSoundSignal); // Append signal value to val
  while(val == LOW) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
  }

  while(val == HIGH) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
    timecount = timecount +1;		// Count echo pulse time
  }
  /* Writing out values to the serial port
   * -------------------------------------------------------------------
   */
  ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue
  serialWrite('A'); // Example identifier for the sensor
  printInteger(ultrasoundValue);
  serialWrite(10);
  serialWrite(13);

  /* Lite up LED if any value is passed by the echo pulse
   * -------------------------------------------------------------------
   */

  if(timecount > 0){
    digitalWrite(ledPin, HIGH);
  }

  /* Delay of program
   * -------------------------------------------------------------------
   */

  Serial.print( "val = " + val );
  delay(100);
}


 



I have also changed the baud rate in Arduino and serproxy to 9600 and the line: a.setPinMode(6, Arduino.INPUT); to a.setPinMode(7, Arduino.INPUT); in Flash.




Back to top
 
 
View Profile   IP Logged
czliao
YaBB Newbies
*
Offline

Arduino rocks

Posts: 2

Re: Range sensor to Flash problem
Reply #5 - 02.06.2008 at 03:38:30
 
I am new to this too, and trying to figure out what's going on with the Glue AS3. I don't want to complain but seems like everyone is having such a easy time with it, but I just can't get values to show up on the flash output window.

Basically the firmware version wouldn't show up (I am testing the Simple_IO example). I'd get "Socket Conneted" and that's it.

As for you Jim, what do you get when you run your program now?
Back to top
 
 
View Profile   IP Logged
czliao
YaBB Newbies
*
Offline

Arduino rocks

Posts: 2

Re: Range sensor to Flash problem
Reply #6 - 02.06.2008 at 04:07:27
 
alas, this tutorial helped me passed that stage.
http://protolab.pbwiki.com/TutorialFlashSetup
Back to top
 
 
View Profile   IP Logged
jimblibs
YaBB Newbies
*
Offline

Arduino rocks

Posts: 8

Re: Range sensor to Flash problem
Reply #7 - 02.06.2008 at 11:20:07
 
Thanks for the reply czliao. Ill have a look at that when I get home. It looks as though I'm in the same bopat as you (simpleIO, Socket connected but no readings). I read somewhere last night that AS3 Glue needs to work with Firmata. Maybe that's where I'm going wrong. Firmata doesn't work with the Range sensor Im using so I'm using another sketch. I've tried to add the code from this sketch to Firmata but this also doesn't work.

Did you finally get it all working then from the information in the link you proided? A fixed version of AS3Glue sounds promising. I'll try this later and if it still doesn't work I'm going to have to write some custom actionscript to communicate with SerProxy. I'll post it if I get it working.
Back to top
 
 
View Profile   IP Logged
jimblibs
YaBB Newbies
*
Offline

Arduino rocks

Posts: 8

Re: Range sensor to Flash problem
Reply #8 - 03.06.2008 at 22:25:05
 
Ok so I managed to write some actionscript that receives and processes the data from the range sensor. It was far easier than I thought. Here it is:

Code:
/*
Author James Alliban - http://jamesalliban.wordpress.com

This code has been writted specifically to be used for interfacing with the PING Ultrasonic
Range Finder using the Arduino microcontroller and communicating via SerProxy. If anyone makes
anything interesting with it, or improves upon it in any way, please email me at
me@jamesalliban.co.uk

*/

package
{

	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.net.Socket;
	import flash.events.ProgressEvent;

	public class RangeFinderData
		extends Sprite
	{

		private var s				:	Socket;

		private var prevInput		:	String;		// the previously processed input (returned value)
		private var currInput		:	String;		// the currently processed input
		private var finalInput		:	String;		// the input after processing

		public function RangeFinderData()
		{
			init();
		}

		public function init() : void
		{

			s = new Socket("127.0.0.1", 5333);
			s.addEventListener(ProgressEvent.SOCKET_DATA, sData);

		}

		private function sData( e:ProgressEvent ) : void
		{

			// read the correct data from the socket. In this instance. This arrives in millimeters
			// preceeded by "A"
			var sData:String = s.readUTFBytes( s.bytesAvailable );

			if (isDataCorrect(sData)) {

				if (sData.indexOf( "A" ) == 0) {
					prevInput = currInput;
					currInput = sData.substr( 1 );
				} else {
					currInput += sData;
				}

				 trace( "prevInput = '" + prevInput + "'" );
			}
		}


		function isDataCorrect( sData:String ) : Boolean
		{
			// occasionally, between real results the data returned consists of a carriage return
			// then a zero.
			if (parseInt(sData) == 0 && sData.length > 1) return false;
			// another occasional unwanted reult
			if (sData == "") return false;
			if (sData == "0") return false;

			return true;
		}
	}
}

 



I hope this helps someone in the future.




Back to top
 
 
View Profile   IP Logged
Pages: 1