Add

Making Things + AS3 – Part 4 Serial LCD


Serial LCD

UPDATE – it seems that the classes I have been using are out of date!
Making things has released a library that works with the mchelper application which I actually haven't been able to get working with this example. Also Adam Robertson has developed a library that works with flex. I tried porting this library to this example but had no luck. And finally, Ignacio/Nacho, from John Barton's earlier posts has developed a library as well as updates to the Flosc application which I am in the process of testing.

While I haven't gotten any of the examples working with the LCD, each of them is excellent in its approach and I'm trying to round up John, Liam, Adam, Ignacio, and myself and see if we can make this a collaborative effort. Things have slowed down a bit with work and the Flash Forward convention, but stay tuned for more updates. In the meantime, the included code I have does work if you want to tinker and get a feel for what's going on with the controller.

Anyone else who is interested, give me a shout!


Be sure to read parts 1-3. Still haven't tackled the getting data from the board issue yet. I wound up having a lot of fun getting this experiment working and got sidetracked. So this is an example and how-to on getting the making things controller to send serial data to an LCD screen. There's a weather RSS example out there that doesn't use flash. This is a scaled down version of that as I haven't had a chance to get the board working via an internet connection. So what we have here is a simple text input swf that will send the text to the LCD. So let's get this thing hooked up first. Obviously you will need an LCD screen with serial capability. I purchased mine from SparkFun here. Try not to let the GPS modules distract you ;)

Here's a diagram of the connections for the controller:

Make Controller Serial LCD Diagram Flash AS3

You might be wondering where that green wire is going. Well if you look really close, you'll see a set of punched out solder points. This is the serial/RS232 interface connection area. There are points for 3.3v, TX, RX, and some others as well. The TX is the one we need for transmitting the serial data. Grnd to Grnd, 5V to VO, and TX on the board to RX on the LCD. Make sure the power jumper for the digital bank is set to 5V (It's not in the diagram). Go here for more on that. There is a sub-mini pot on the back of the LCD for adjusting contrast.

package com.hydrotik.make {
 
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.utils.Timer;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.net.URLRequest;
	import flash.media.Sound;
	import flash.media.SoundChannel;
 
	import flash.text.*;
 
 
 
	import org.fwiidom.osc.*;
 
	public class MakeSerialLCD extends Sprite {
 
		private static const STR_LOCAL_IP:String = "169.254.73.165";
 
		private static const STR_REMOTE_IP:String = "192.168.0.200";
 
		private static const NUM_PORT:Number = 10000;
 
		private var oscConn:OSCConnection;
 
		private var tf:TextField;
 
		public function MakeSerialLCD() {
			//Initialize connection to the FLOSC server
			oscConn = new OSCConnection(STR_LOCAL_IP, NUM_PORT);
			oscConn.addEventListener(OSCConnectionEvent.ON_CONNECT, onConnect);
			oscConn.addEventListener(OSCConnectionEvent.ON_CONNECT_ERROR, onConnectError);
			oscConn.addEventListener(OSCConnectionEvent.ON_PACKET_IN, onPacketIn);
			oscConn.addEventListener(OSCConnectionEvent.ON_PACKET_OUT, onPacketOut);
			oscConn.addEventListener(OSCConnectionEvent.ON_CLOSE, onClose);
			oscConn.connect();
		}
 
		private function onConnect(evtEvent:OSCConnectionEvent):void {
			trace("FLOSC Connection established");
 
			oscConn.sendOSCPacket(new OSCPacket("/serial/baud", [9600], STR_REMOTE_IP, NUM_PORT));
 
			var button1:Sprite = new Sprite();
			button1.graphics.beginFill(0xCC6666);
			button1.graphics.drawRect(20, 10, 40, 20);
			button1.buttonMode = true;
			button1.addEventListener(MouseEvent.CLICK, onClick1Handler);
			addChild(button1);
 
			tf = new TextField();
			tf.background = true;
			tf.border = true;
			tf.backgroundColor = 0x00FF66;
			tf.maxChars = 32;
			tf.multiline = true;
			tf.width = 120;
			tf.height = 32;
			tf.wordWrap = true;
			tf.x = 80;
			tf.y = 10;
			tf.type = TextFieldType.INPUT;
			tf.restrict = "A-Z 0-9!.\"\'?";
			tf.tabEnabled = true;
			tf.tabIndex = 0;
 
			addChild(tf);
		}
 
		private function onConnectError(evtEvent:OSCConnectionEvent):void {
			trace("FLOSC Connection error");
		}
 
		private function onClose(evtEvent:OSCConnectionEvent):void {
			trace("FLOSC Connection closed");
		}
 
 
		private function onPacketIn(evtOSC:OSCConnectionEvent):void {
			trace("\t>> data received: " + evtOSC.data.name + " " + evtOSC.data.data);	
		}
 
		private function onPacketOut(evtOSC:OSCConnectionEvent):void {
			trace("\t>> data sent: " + evtOSC.data.name + " " + evtOSC.data.data);	
		}
 
		private function onClick1Handler(event:MouseEvent):void {
			parseString(tf.text);
			tf.text = "";
		}
 
 
		private function parseString(str:String):void {
			//Initialize LCD
			oscConn.sendOSCPacket(
				new OSCPacket("/serial/char", [254], STR_REMOTE_IP, NUM_PORT)
			);
			//Clears LCD
			oscConn.sendOSCPacket(
				new OSCPacket("/serial/char", [1], STR_REMOTE_IP, NUM_PORT)
			);
			//Loop and send ascii dec
			for(var i:int = 0; i<str.length ; i++){
				oscConn.sendOSCPacket(
					new OSCPacket("/serial/char", [str.charCodeAt(i)], STR_REMOTE_IP, NUM_PORT)
				);
			}
		}
 
	}
 
}

The code is pretty straight forward. It's not doing anything too exciting other then sending the data. I have one OSC command sending a baud rates and a couple other OSC commands that clear the existing text on the screen and prepare it for a fresh batch of characters. Other things you'll notice is that I have a restriction of chars attached to the input field. You can play with this and add lowercase if you like.

Below I've included the changes I made to the OSC class:

package org.fwiidom.osc { 
	/**
	 * @author adam
	 *(based originally on demo code included with Flosc)
	 * 
	 * (c) 2007 Fwiidom.org
	 */
 
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.XMLSocket;
	import flash.xml.XMLDocument;
	import flash.xml.XMLNode;
 
	public class OSCConnection extends EventDispatcher {		
 
		protected var mSocket:XMLSocket;
		protected var mPort:Number;
		protected var mIp:String;
 
		protected var mDefaultSendPort:Number  = 10000;
		protected var mDefaultSendIp:String = "192.168.5.210";
 
		protected var mConnected:Boolean;
 
		public function OSCConnection(inIp:String, inPort:Number) {
			super();
			mIp = inIp;
			mPort = inPort;			
		}
 
		public function connect () : void {
			trace("OSCConnection.connect()");
			mSocket = new XMLSocket();
			mSocket.addEventListener(Event.CONNECT,onConnect);
			mSocket.addEventListener(Event.CLOSE,onClose);
			mSocket.addEventListener(DataEvent.DATA,onXml);
 
			mSocket.connect(mIp,mPort);
 
			//if (!mSocket.connect(mIp,mPort)) onConnectError();
		}
 
		public function disconnect () : void {
			mSocket.close();
			mConnected = false;
		}
 
 
		// *** event handler for incoming XMLDocument-encoded OSC packets
		protected function onXml (e:DataEvent) : void {
			var inXml:XMLDocument = new XMLDocument(e.data);
			trace("OSCConnection.onXml---"+inXml);
			// parse out the packet information
			var n:XMLNode = inXml.firstChild;
			if (n != null && n.nodeName == "OSCPACKET") {
				parseXml(n);
			}	
		}
 
 
		// *** event handler to respond to successful connection attempt
		protected function onConnect (succeeded:Boolean) : void {
			trace("OSCConnection.onConnect(succeeded)");
			if(succeeded) {
				trace ("success");
				mConnected = true;
				dispatchEvent(new OSCConnectionEvent(OSCConnectionEvent.ON_CONNECT,null));
			} else {
				trace ("fail");
				onConnectError();
			}		
		}
 
 
		// *** event handler called when server kills the connection
		protected function onClose (e:Event) : void {
			trace("OSCConnection.onClose()");
			mConnected = false;
			dispatchEvent(new OSCConnectionEvent(OSCConnectionEvent.ON_CLOSE));
		}
 
 
		protected function onConnectError() : void {
			trace("OSCConnection.onConnectError()");
			mConnected = false;		
			dispatchEvent(new OSCConnectionEvent(OSCConnectionEvent.ON_CONNECT_ERROR));
		}
 
		// *** parse the messages from some XMLDocument-encoded OSC packet	
		protected function parseXml(node:XMLNode) : void {
			trace("/------------------- OSCConnection.parseXml(node) ");
			trace (node);
			trace("------------------- /");
			if (node.firstChild.nodeName == "MESSAGE") {
				var message:XMLNode = node.firstChild;
 
				var name:String = message.attributes.NAME;			
				var data:Array = [];
				for (var child:XMLNode = message.firstChild; child != null; child=child.nextSibling) {
					if (child.nodeName == "ARGUMENT") {
						var type:String = child.attributes.TYPE;
						//boolean
						if (type=="T" || type=="F") {
							data.push((type=="T")?true:false);	
						} else if (type=="f") {
							//float
							data.push(parseFloat(child.attributes.VALUE));
//////------------------------------------------------------------------------///////////////////////////////////////////////////
//////	Added new type "i", as "f" is not a type in the Make Controller
//////------------------------------------------------------------------------///////////////////////////////////////////////////
						} else if (type=="i" || type=="I") {
							//float
							data.push(parseInt(child.attributes.VALUE));
						} else
						//string
						if (type=="s") {
							data.push(child.attributes.VALUE);
						}	
					}
				}
 
				var packet:OSCPacket = new OSCPacket(name, data, node.attributes.address, node.attributes.port);
				packet.time = node.attributes.time; 	
				dispatchEvent(new OSCConnectionEvent(OSCConnectionEvent.ON_PACKET_IN,packet));					
			}
			else { 
				// look recursively for a message node
				for (var subchild:XMLNode = node.firstChild; subchild != null; subchild=subchild.nextSibling) {
					parseXml(subchild);
				}
			}
		}
 
 
 
		// *** build and send XMLDocument-encoded OSC
 
		public function sendOSCPacket(outPacket:OSCPacket) : void {
			var xmlOut:XMLDocument = new XMLDocument();
 
			var osc:XMLNode = xmlOut.createElement("OSCPACKET");
			osc.attributes.TIME = 0;
			osc.attributes.PORT = outPacket.port;
			osc.attributes.ADDRESS = outPacket.address;
 
			var message:XMLNode = xmlOut.createElement("MESSAGE");
			message.attributes.NAME = outPacket.name;
 
			for (var i:Number=0;i<outPacket.data.length; i++) {
				// send everything as a string
				// NOTE : the server expects all strings to be encoded
				// with the escape function.
				var argument:XMLNode = xmlOut.createElement("ARGUMENT");			
				setType(argument, "i"); //argument.attributes.TYPE = "s";
				setValue(argument, escape(outPacket.data[i])); //argument.attributes.VALUE = escape(outPacket.data[i]);
				message.appendChild(argument);
			}
 
			osc.appendChild(message);
			xmlOut.appendChild(osc);
 
 
 
			if (mSocket && mConnected) {
				//trace ("XMLDocument SEND - ");
				trace (xmlOut);
				mSocket.send(xmlOut);
				dispatchEvent(new OSCConnectionEvent(OSCConnectionEvent.ON_PACKET_OUT,outPacket));
			}
		}
 
 
		private function setType(arg:XMLNode, str:String):void{
			arg.attributes.TYPE = str;
		}
 
		private function setValue(arg:XMLNode, str:String):void{
			arg.attributes.VALUE = str;
		}
 
	}
}

Making Things Serial LCD Source

The Discussion

see what everyone is saying

  • Nacho September 6th, 2007 at 5:36 am #1

    Hi Donovan!

    Try to check the updated AS3 classes I made to have an OSC connection from a Flosc server. Maybe you have some great ideas to improve them. You can find the sources at http://code.google.com/p/flosc/ (I've created a new project to update and continue Ben Chun's work :) )

  • John Barton September 12th, 2007 at 3:36 pm #2

    Nice work. I'm glad that my updated AS3 classes and articles were able to get you started. Although at this point, since the new release of the MakingThings classes and the updated mchelper, I'm still evaluating if I'm going to continue with working on flosc and my updated Fwiidom classes or start over and begin hacking on the MakingThings classes.

  • [...] Connecting AS3 and Flex with the real world. Link [...]

Respond

get in on the action.

* Required

revatio efects buy lisinopril viagra order online erectile dysfunction medications I Need To Buy Viagra drugs on line cheap msm food allergies muscle building diet osteoporosis hormon ultram dosage levitra without prescription buy viagra in canada buy desyrel buy mexiletine buy phentermine online without prescription where to buy soma lithium carbonate women and viagra medications on line ultram er alprazolam no perscription viagra online without prescription type 2 diabetes diazepam pharmacology lower high blood pressure how to get big muscles discount dog products starlix buy deltasone health vitamins ultram dosage tooth whitening dentist buy pain meds now a reliever of arthritic pain hoodia patches cheap decadron reduce cholesterol naturally asthma control cheap generic viagra online fitness muscle online treatment for aids body building online course throat infection treatment increasing breast size naturally buy celebrex online buy antibiotics cheap online clomid testosterone booster patch nutritional diet for osteoporosis treating aids in africa blood pressure diet order vitamins order viagra online cymbalta vs lexapro xanax without prescription cheap pet health care buy prevacid buy prevacid soma 250 drug for nausea where to buy soma natural cure for erectile dysfunction ear pain right side back pain dog calming pills ordering viagra dental antibiotics antifungal strategies help the pain januvia cheap diabetes type 2 bronchitis diarrhea cimetidine dose alprazolam acne tips blood pressure buy cheap tooth whitening product prevacid online water pill buspirone dosage prescription phentermine buy beconase lower leg pain vitamins for women new antibiotic drug dog health care weight loss after baby skin cancer treatments high blood pressure yerba diet self help alcoholism benicar generic cure blood clot eye infections in dogs bph prostate family pharmacy zyban pharmacy atarax generic high blood pressure drug list buy xanax online buy natural antibiotics list how to white teeth avalide generic viagra cialis levitra medician for heart attacks phentermine prescription alcoholism new treatment help for depression heart failure medicine buy retin a buy levitra online with fast delivery body fat lose weight loss web sites buy nimotop herpes simplex new blood pressure drug how do a stop smoking flu shots herpes treatment enhance sexual performance effects of celexa viagra shop increase male volume treatment for chest pain cats bladder side effects clomid face wrinkles allegra klonopin effects relieve joint pain drugs that relieve pain new cat products human parasite ultram dosing tab tramadol carb blocker medication to stop smoking order viagra online in germany anxiety info ambien viagra gel use of xanax for anxiety online drugs without prescription weight loss health health ambien online buy viagra online cheap alternative medicine cholesterol mestinon blood pressure meds treatment parkinsons disease buy viagra without prescription methocarbamol effects pet health care information what is saw palmetto buy cialis online without a prescription flu drugs celebrex information gout cures buy orlistat on line sildenafil dosage blood pressure medication names ultram dosing order viagra canadian drug online big muscle fluconazole 150mg lasix cheap ashwagandha dosage side effects of ativan body acne treatment buying viagra online without prescription body building programs cat health care natural pet products viagra order body building tips high blood calcium level estradiol pill tips for weight loss back pain medications atenolol withdrawal vermox xanax dose antibiotics bronchitis cialis cialis information how to white teeth diabetes blood sugar levels pravastatin sleep disorders remedy viagra superactive diet pills hypnotherapy cds viagra cheep carisoprodol purchase cat anxiety buy alcoholism medications nausea cure how do a stop smoking relieve joint pain oral ketoconazole clonazepam pharma california cold flu calcium channel blocker hypertension prednisone allergy Cealis Lavetra effects of levitra professional anti allergic drug drugs for hiv body building online course dog ear problem super flu quickly stop smoking bad body odor atlas rx viagra abilify 10mg nolvadex 20mg hair loss treatment uk anti obesity chloramphenicol triphala sleep disorder treatment information on ambien remedy for hair loss when are beta blockers prescribed myasthenia gravis risperdal anxiety symptoms high blood pressure cure snoring chronic heart failure medicines valium with no prescription buy alcoholism medications generic pain medication alternative treatment arthritis diovan prescription latest diet pill effects of levitra professional clomid drug xanax without prescription online hair loss for men purchase viagra online hair loss products for men lamictal viagra online usa xenical no prescription pneumonia vs bronchitis prednisone 10 mg diflucan buy celebrex online anti fungus products endep liver infection treatment order indomethacin penis enlagement augmentin medication hair loss prevention treatment for yeast infection pyridium chest pain symptoms flovent generic valium with no prescription prevention of diabetes breast enhancement new york levitra do for men ginkgo biloba prescription lipitor klonopin zoloft order medication to aid in sleeping diabetes type 2 medicines for insomnia weight loss and fitness high blood pressure info purchase levitra online cialis on line health support discount prescription medications alprazolam no perscription how to purchase cialis acne free antifungal sinus women insomnia valium maximum dosage osteoporosis bone health buspar online discount cialis levitra viagra cure bronchitis prostate cancer treatment protonix overactive bladder medications skin cancer treatment effects klonopin yeast infection remedies fluconazole interaction canada online pharmacy viagra healthy women's vitamins expected weight loss with phentermine how to purchase cialis about cialis body building buy product how to buy cialis male erectile dysfunction femara drug topamax parkinson medications male bladder problems diabetes health care system haldol medication withdrawal zyrtec buy hyzaar cat hairball remedies cheap florinef lipitor use drugs for pain celebrex cealis lavetra Viagra Cialis Levitra buy nimotop how to increase fertility buy pain medicine online insomnia sleep problems cheapest place buy viagra online tooth whitening systems haldol medication information on levitra cialis advice bactroban price of drugs seroquel for anxiety malaria preventative effects of allegra body building info vytorin generic bladder problem solutions dog health help cialis cheap no prescription beta blockers bronchitis antibiotics back pain anti-fungal natural arthritis cures buying viagra online in britain penis development cheapest generic cialis snoring woman stretch penis purchase generic viagra virility gum viagra and sports buy proscar soma on line diet supplements that work breast enhancer pills how to enlarge breast buy cialis generic online dog bowel problems pet health information enhance breast acai alpha blocker medications cialis best on-line drugstore infection dog ears enhance sexual performance weight loss male sexual power cat health info clean dogs ears ultram used for gout medicines effective weight loss program improve sexual confidence cialis levitra viagra sildenafil kamagra cat skin disorders female sexual enhancement creams prozac on line bentyl drug diarrhea in pregnancy insomnia pills helping high blood pressure buy plendil lipitor use weight loss support group online buy plan b remedies for stomach ulcers cancer cure phentermine with no perscription best weight loss products online pain doctors buy vitamin a breast enhancer how to build muscle generic abilify free pain pills by mail breast enhancement products prostate cancer support accupril cymbalta medication small penis ramipril capsules depression symptoms treatment penis enhansment blood pressure drug names herpes medications to buy free smoking treatment online carisoprodol lasix drug depression and anxiety buy griseofulvin without prescription free weight loss tips klonopin pill viagra cialis levitra diet drug online enhancement breast atacand generic get viagra prescription online verapamil drug zyban what is hoodia overactive bladder in men buy tramadol cheap treatment for chronic fungal infection zoloft buy white spots on face pediatric diarrhea paxil information buy online cialis weight loss doctor online brain cancer treatment new weight loss drug levitra pro medication for depression relieve joint pain naturally enhancement breast health information bone health general drugs for hiv nexium drug premature ejaculation cure promethazine tablets treatment for dry skin erectile dysfunction cure online viagra without prescription best weight loss solutions drug allergies buy buy cialis online now cancer drug acessrx buy tooth whitening products parkinson disease medicine free hoodia