Patrick Wang

Work is tough! Time to dream.

February 15, 2011
by Pat
0 comments

The Resistor Calculator – My first app

After several months of sighs and cringes, I have released my first mobile platform app, and first Android app. The application is called Resistor Calculator and can be found on the Android marketplace for $0.99 https://market.android.com/details?id=com.pat8037.resistor

It is very simple in functionality and general GUI, but for the task of identifying the resistance of a resistor, I think it works the best, given how I’ve longed for something like this through my time working on Arduino.

I will no doubt be updating the program, tweaking and improving and adding more features.

If you have purchased the app, and have feedback, feel free to comment or email me at patw.android (at) gmail (dot) com . My email is written this way to prevent spammers.

January 17, 2011
by Pat
0 comments

Android : sdcard emulator and eclipse

This post is going to be about how to implement a .iso image for use to simulate an sdcard when developing an Android application.

The following link is what Android developer offers with how to emulate sd card. http://developer.android.com/guide/developing/tools/emulator.html#sdcard

I got lost in it to honest…

I’m working on Windows platform so for now, this write up will be windows based.

First step is locate the mksdcard executable. Its inside of android-sdk – >tools.

Next, get a cmd screen running. go to your Start button menu, select Run or type run into the search bar. When the prompt comes on type ‘cmd’ without apostrophes in, and a black screen will show.

Now, with the mksdcard file, drag and drop it into your cmd prompt. Some text will appear and it’s simply the directory location of the mksdcard file. DO NOT press enter yet. There are some commands that we need to type in first.

From here we need to identify 2 key criteria of the iso: size and directory/name

For example -1024M         means make the iso 1024MB.M = Mb. There is also a K abbreviation, K = Kb

name – sdcard1.iso             you can use whatever filename just have the extension .iso at the end of it

You can also have C:\sdcard.iso       This is an example of specifying where to create the new iso to.  I didn’t know this, and I had no idea where my iso images went to after the cmd went through. Only after a search did I find it.

Below is an image of what it will look like.

Hopefully this has worked for you, and you are now looking at your newly create .iso file.

To push your bits and pieces files into the iso, I use a program called PowerIso. It can open the iso file, and allow you to simply drag-and-drop your necessary files into the iso. Everything is easier with drag n’ drop!

Last step is utilising the iso when the emulator runs. For this, I go through eclipse.

Selecting the project you want access the iso, in Package Explorer, right click, then select Run As and then Run Configurations. See image below.

When the new screen appears, select the Target tab on the right, and at the bottom you will see “Additional Emulator Command Line Options”

The command to use the iso is -sdcard. In the image below, I write “-sdcard C:\sdcard.iso” . Once again without the apostrophes.

Click the ‘Apply” button and Run!

Hopefully things worked out well. I notice that sometimes even after eclipse has installed the application, and run the activity, nothing shows. It may need a kick in the butt, so select the Home button, and rerun the program in the emulator. Sometimes it needed to be done twice. If that doesn’t work, check the console for unusual messages and errors.

Good Luck.

December 1, 2010
by Pat
3 Comments

Augmented Reality with Processing and Maya.

Augment means to add to. Augmented reality would therefore mean “adding to reality”. With Processing and Maya, it is possible to add virtual objects to our realities and be seen with a digital viewfinder for example, a webcam or mobile phone.

Processing is a java based programming IDE. It makes prototyping ideas a lot easier. Maya by Autodesk, is a 3D modeling package. I decided to model the Sukhoi Su-47 plane.

Here are some links to the necessary parts list.

Processing – http://processing.org/

OBJ Loader, library to import the Maya model – http://code.google.com/p/saitoobjloader/

Simple ARToolKit, library that makes AR happen (Critical) – http://www.bryanchung.net/?page_id=415

(Bonus) MultiARToolKit. The SimpleARToolKit can only handle one marker at a time. In Russia, Den Ivanov make multi-marker library – http://www.cleoag.ru/2009/12/04/multiple-ar-markers-library-for-processing/

Maya – this is optional as you can also make 3d objects with the code found in Processing. However it can be difficult. There are many 3d modeling programs out there and at Zero cost.

The final result. Maya on Left. Processing on Top Right. The result on Bottom Right.

Its not photoshop

I have the code I used posted below which I mashed together primarily with the example coding from the OBJ library and SimpleAR library. Some pointers. When you have made your model in Maya, the usual save is a .mb file. When you export as a .obj file you get two files: a .mtl and .obj . You need BOTH in your sketch. Its a simple task of marque selecting the files in your folder and drag and drop them into the Processing IDE. If you want to use more than one marker of different variety, you need the MultiARToolKit library. That’s it really, experiment and have fun!

//By Patrick Wang. 2010.  Credits to Bryan Chung's AR toolkit library

import JMyron.*;                    //for the Ar
import processing.opengl.*;        //For the model
import pARToolKit.SimpleARToolKit;  //for the AR

import saito.objloader.*;          //For the Model

OBJModel model;                    //For the Model

JMyron m;
PImage img;
SimpleARToolKit ar;                //new AR object
int capWidth, capHeight;

void setup() {
size(800, 600, OPENGL);            //width, height, graphic performance

model = new OBJModel(this, "su47_001.obj", "relative", QUADS);      //adjust the file name to your model's file name.
model.scale(50);                                                    //scaling the size of the object when in view

capWidth = 320;
capHeight = 240;
m = new JMyron();
m.start(capWidth, capHeight);
m.findGlobs(0);

img = createImage(capWidth, capHeight, ARGB);
ar = new SimpleARToolKit(this, capWidth, capHeight);
ar.loadPattern("patt.hiro", 80, 0.0f, 0.0f);                       //Pattern is the marker, in this case pattern Hiro.
ar.register("showPlane");                                          //use the showPlane to display ontop of Marker
stroke(200,200,0);
}

void draw() {
background(0);
m.update();
m.imageCopy(img.pixels);
img.updatePixels();
hint(DISABLE_DEPTH_TEST);
image(img,0,0,width,height);
hint(ENABLE_DEPTH_TEST);
if (ar.findMatch(img,100)) {
ar.showObject();
}
}

void showBox(SimpleARToolKit _a) {
noFill();
box(50);
fill(255);
}

void showPlane(SimpleARToolKit _a) {
fill(255);
//box(80,80,80);    //optional
//sphere(40);      //optional
scale(0.2);      //the scale here can also scale object
translate(0,0,40);
rotateX(PI);
rotateY(PI);
rotateZ(0);
model.draw();            //the only real line of code to make the model appear.
}

October 25, 2010
by Pat
0 comments

Charlieplexing on the Arduino. More bang for buck!

I recently had to try and understand charlieplexing. After some fact finding, youtube videos and some algebra, I got it.

I thought I’d link this video I watched on Youtube which I found very concise and covers half the leg work.

So, after watching the video, here are some key points.

  • Charlieplexing gives you more leds for much less pins.
  • Each pin can have one of three states: high, low or input
  • To calculate pins needed use this formula: pins = n(n-1), where n = number of leds you want to control. When doing this for my 15 led setup, I realised you can’t factorise n²-n-15. So you just go up to use 20 leds. You don’t have to use all 20.

All these facts are well and good but how do I figure out wiring and the combination to control a particular led.

The following values are total numbers of leds you can charlieplex together, but definitely goes beyond just 90.
1×2 = 2,
2×3=6,
3×4=12,
4×5=20,
5×6=30,
6×7=42,
7×8=56,
8×9=72,
9×10=90…

Lets take the 4 pin setup for 12 leds.

AA AB AC AD
BA BB BC BD
CA CB CC CD
DA DB DC DD

When wiring up your combinations, you wire up to different pins for each leg of an led. In the above table of letter combinations, if you took out AA,BB,CC,DD, you are left with 12 combinations!  If we just supplement the letters for pin values on an arduino we get this.

1,1 1,2 1,3 1,4
2,1 2,2 2,3 2,4
3,1 3,2 3,3 3,4
4,1 4,2 4,3 4,4

Something which resembles co-ordinates. Excluding, 1,1-2,2-3,3 and 4,4 the remaining pin combinations provide control.

Now onto code.

We are so very fortunate that a library for charlieplexing exists and it just cuts down a lot of potential clutter. http://www.arduino.cc/playground/Code/Charlieplex

The code is relatively straight forward. You have to declare which pins you’ve used on the arduino. Then start declaring off each of your led co-ordinates.

Good luck!

October 16, 2010
by Pat
0 comments

Arduino Bluetooth on the cheap and easy!

Price is a huge problem when trying to implement bluetooth onto an Arduino project.
Firstly, is the price of a Arduino Bluetooth board. At $140ish USD and easily >$200AUD, it is definitely not cheap. Furthermore, it requires the use of screw terminals to power the device. Dangerous if not careful.

So for much of my time, I’ve researched around to find a way to implement bluetooth on the cheap. Researching and exploring so many websites. Below I will present a stock list of what you might need to setup the sub $100 Arduino Bluetooth!.

1. Arduino USB. You can use Duemilanove or for the richer of you out there, the new UNO. I usually go to LittleBirdElectronics. $37.11AUD – $42AUD

2. Xbee Shield. $19.95AUD I found an shield which fits what I need. http://www.australianrobotics.com.au/?q=node/50

.

Unlike the original ‘L’ shaped shield, this gives me access to my precious pins, allowing me to place ontop more shields. . And unlike the newer xbee shield, it just removes off the prototyping holes, which I don’t have a need for.

3. The final piece that makes it possible is a Bluetooth Bee. http://www.seeedstudio.com/depot/bluetooth-bee-p-598.html?cPath=2.

This little device will fit snuggly into the xbee shield. with a few lines of code in setup to initialise this little device, you’ll have bluetooth signals flying in your work space. $23.50 USD.

Of course this doesn’t take into account the cost of shipping all these items. The most difficult to find has been the bluetooth bee. Hopefully, one day when one of these sites have everything you need in the one site, and also offer free shipping(e.g littlebird and australianrobotics) when >$50, it’s good times.

Total cost: 37.11 + 19.95 + 23.50USD(I just say $25). = $80.56 AUD.

Guess what? No Soldering ! So anyone who is new to the electronics prototyping scene can take it easy with the setup.

//Update.

/* I discovered this bluetooth shield from the people of ITead Studio. http://iteadstudio.com/store/index.php?main_page=product_info&cPath=18&products_id=179 It reminds me of some of the xbee shields. It’s all been soldered, so no soldering required, and plug-&-play-esque. If you don’t have any shields on top, then this is okay. If you plan to have other shields on top and they have connection pins to access the ISCP, then this is still okay. Otherwise, this shield will block access due to digital pins 0-2 being used, and you may need to trim pins off your shield if you plan to use this (urgh). */

October 7, 2010
by Pat
6 Comments

Arduino bluetooth with temperature sensor send data to mobile phone

In the previous post, I had code to read a temperature sensor.  http://www.ph0t0n.com.au/arduino-bluetooth-with-temperature-sensor/ . The sensor was attached to an Arduino bluetooth board. Now, with the code below, we’ll have the temperature data sent to your mobile phone and your phone can now become ‘sensor’. As a bonus, when you press your number ’5′ key on your mobile phone, after you have begun reading the temperature, you will be able to input a mobile phone number, and then send the temperature information is someone!

For this, we used Mobile Processing http://mobile.processing.org/.Based off Processing, it simplifies java based mobile phone application development by A LOT as you will see with the code below.

When the Arduino bluetooth board transmits anything, it will be received as byte data ( 8 bits for 1 byte).  Therefore some conversion is needed before we can make sense of the values.

Below is the code. But here is a zip file of the code, and midlet files, so you can install onto your Java based phone. mobile_BT_temperature_withMSGv2_forWeb

Arduino bluetooth 2 mobile phone

Arduino bluetooth 2 mobile phone

Arduino bluetooth 2 mobile phone

//Me holding the temperature sensor an affecting the reading

Arduino bluetooth 2 mobile phone

//Adapted from Adrian Lombard and Dr. Andy Dong.
//By Patrick Wang. B.Design Computing. University of Sydney. October 2010.

import processing.bluetooth.*;
import processing.messaging.*;
/*Have had problems with Mobile Processing messaging.
Would not allow me to send to some devices. I could send to Nokia based devices
but nothing received on iPhones or Android based phones*/

import javax.wireless.messaging.*;    //This library is better

import java.io.*;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;

Bluetooth bt;                      //new bt device
Service[] services;

PFont font;

int state;
String msg;
Client c;

Messenger m;

final int STATE_START = 0;   //different states, similiar to events.
final int STATE_FIND  = 1;    //find devices
final int STATE_HOST  = 2;
final int STATE_PLAY  = 3;    //once connected to device

byte[] inBuffer = new byte[2];  //store the bytes read from arduino in array.
//For the temperature sensor, there are only two digits, e.g 2 and 0 for temperature 20 C

SendMessage sm;

String message;
int counter;

void setup() {
font = loadFont();
textFont(font);
bt = new Bluetooth(this, 0x1101);
m = new Messenger(this);

sm = new SendMessage();
counter = 1;
}

void draw() {
background(255);

if (state == STATE_START) {
fill(0);
textAlign(LEFT);
text("Arduino Bluetooth 2 Mobile Phone. \n1. Find ArduinoBT", 2, 2, width - 4, height - 4);
}
else if (state == STATE_FIND) {
fill(0);
textAlign(LEFT);
if (services == null) {
text("Looking for an ArduinoBT...\n\n" + msg, 2, 2, width - 4, height - 4);
}
else {
String list = "ArduinoBT found\n\n";
for (int i = 0, length = length(services); i < length; i++) {
list += i + ". " + services[i].device.address + "\n";      //this will list discovered devices
}
text(list, 2, 2, width - 4, height - 4);
}
}

else if (state == STATE_PLAY) {
c.readBytes(inBuffer);     //Assigning assign the readBytes data into the inBuffer array for storing.
String data = new String(inBuffer);        //change the byte values into strings data
if (inBuffer != null) {
text("Current Temperature: " + data, 2, 2, width - 4, height - 4);             //draw the message
}
text("Current Temperature: " , 2, 2, width - 4, height - 4);
}
}

void libraryEvent(Object library, int event, Object data) {
if (library == bt) {
switch (event) {
case Bluetooth.EVENT_DISCOVER_DEVICE:
msg = "Found device at: " + ((Device) data).address + "...";
break;
case Bluetooth.EVENT_DISCOVER_DEVICE_COMPLETED:
msg = "Found " + length((Device[]) data) + " devices, looking for service...";
break;
case Bluetooth.EVENT_DISCOVER_SERVICE:
msg = "Found ArduinoBT service on " + ((Service[]) data)[0].device.address + "...";
break;
case Bluetooth.EVENT_DISCOVER_SERVICE_COMPLETED:
services = (Service[]) data;
msg = "Search complete.";
break;
case Bluetooth.EVENT_CLIENT_CONNECTED:
c = (Client) data;
state = STATE_PLAY;
break;
}
}
}

void keyPressed() {
if (state == STATE_START) {
switch (key) {
case '1':                      //if keyPressed is equal 1.
services = null;            // it will begin the search
bt.find();                  //bt.find goes through the whole process of bluetooth searching
state = STATE_FIND;
msg = "Looking for ArduinoBTs...";
break;
}
}
else if (state == STATE_FIND) {        //this section will help connect to which device is found
if (services != null) {
if ((key >= '0') && (key <= '9')) {
int i = key - '0';
if (i < length(services)) {
msg = "connecting...";
c = services[i].connect();
state = STATE_PLAY;
msg = "ready";
}
}
}
}
else if ( state == STATE_PLAY) {
String data = new String(inBuffer);        //change the byte values into strings data
if (keyPressed) {
if (key == '5') {
try {
String mob;      //declaring string for mobile phone number
mob = textInput("Enter Phone Number","+61",12);    //+61 is country code for AUS
sm.sendSMSData(mob, "Current Temperature: " + data);
counter++;
}
catch (java.io.IOException err) {
//must have this here to catch exception errors.
}
}
}
}
}

void destroy() {
bt.stop();
}

public class SendMessage
{
public SendMessage() {
}
void sendSMSData(String address, String msg) throws IOException
{
MessageConnection smsconn = null;

address = "sms://" + address;

try
{
smsconn = (MessageConnection)Connector.open(address);
TextMessage tmsg = (TextMessage)smsconn.newMessage(MessageConnection.TEXT_MESSAGE);
tmsg.setAddress(address);
tmsg.setPayloadText(msg);
smsconn.send(tmsg);
}
catch (java.io.IOException err)
{

}
catch (java.lang.SecurityException e)
{

}
catch (java.lang.IllegalArgumentException iae)
{

}

if (smsconn != null)
{
try
{
smsconn.close();
}
catch (IOException ioe)
{
}
}
}
}

October 6, 2010
by Pat
0 comments

Arduino bluetooth with temperature sensor

Below is an alpha version of arduino bluetooth coupled with electronic brick shield. This application is for my findOut project. Currently the code only supports for a basic temperature sensor. There is code for a temperature/humidity sensor, 3 axis accelerometer, and 2 axis compass to be uploaded soon.  Here are some pictures as well.

The electronic brick shield, analog temperature sensor and buckled 3 wire, came from Seeedstudio depot, located in China.

Please note, I have encountered a problem where the rest button on the electronic brick shield will not reset the bluetooth board as bluetooth board I have, does not have header pins for reset!

To run the code you will need Arduino. They have now up to version 0210 i believe. can be download at the following link for windows, mac or linux! http://arduino.cc/en/Main/Software

//By Patrick Wang. University of Sydney. Oct, 2010

int Temperature =  0;      //Temperature pin in Analog 0
int ledPin =  13;         // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup()   {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
Serial.begin(115200);       //Communication on ArduinoBTs is only on  this baud rate 115200
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{

//Serial.println("Current Temperature:");
Serial.print(((analogRead(Temperature) + 252 -500)/10));            //Read the analog port, and then calculate a temperature from a voltage  value
}

Setting this device up is very simple, and straight forward. No soldering is required and most items are plug and play almost. This gives a real boost for beginners and people starting out in electronics. Breadboard can be daunting, but in this case there is no need for a breadboard.

The Arduino bluetooth board is the most expensive bit of kit in this alpha version, costing above $200AUD. I will be working on a version 2, that will cut the cost dramatically whilst maintaining ease of use. It will need to involve an xbee shield and bluetooth module in the form of xbee.

September 22, 2010
by Pat
0 comments

Bushfires, Arduino and a Mobile phone

For most of the year, I’ve been tinkering with Arduino and mobile phone application development. The premise is a bushfire. During a bushfire, communications can become difficult. Power lines fall, telecommunications disable, poor reception, etc. A lack of information is what is most deadly. Being able to identify position, direction the veracity of an impending  fire front is important when residents in bushfire prone areas make a choice to stay-or-go.

My project firstly attempts to address the problem of limited communications by using the basic short message service (SMS) as a means for people to communication their local surrounding’s situation. It is hoped that the information collected could be used in the aid of distributing fire fighting resources for effectively and provide timely warnings for residents. The choice to use SMS was simple, voice communications can drop out. Web connection is no possible whilst out in the bush because of poor mobile telecommunications in rural areas and even if a connection is made, the speeds are terribly slow. A SMS can be typed up even whilst inside a black spot of no signal coverage. The person can forget about the message but once into area of signal coverage , “BAM”, message is still sent.

Secondly, the project aims to make the mobile phones communicate to external sensory hardware, such as a temperature sensor. It is unfortunate that all mobile phones can’t be ‘hacked’ in an easy way to outfit a phone to do even more, e.g hook up a weather station to the phone. There has been attempts, no doubts there, but nothing simple. The next best solution is to utilise the bluetooth protocols to enable phone-to-Arduino communication. What is Arduino you might ask? Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. – http://www.arduino.cc/

So why is this an aim? Once again, information is important, and situations like a bushfire, it’s always good to know what the actual weather conditions are, instead of just ‘really hot’ or ‘really windy’.

Finally, the last aim is to make this final software capable of being used in other contexts. Maybe in wildlife protection. Maybe in traffic updates. Who knows. That is exactly why this project is developed to be open ended. If my readings of crowdsourcing has taught me anything is that I won’t be able to think of everything.

The Arduino system currently utilises an Arduino Bluetooth board. (Hi Marcus). It is possibly the most expensive piece of equipment in this project. The board enables me to communication to my Nokia E71 and Nokia N73 (Hi, Nokia) via Blueooth. Currently in development is figuring out how to make a typical Arduino Duemilanove, relatively cheap board, attach a bluetooth module in a solderless method, to help cut costs down as much as possible. The key is ease of use as this project intends to bring people of non electrical and limited computing knowledge. Oh, and low start up costs.Attached to this board is the Electronic Brick. Under normal circumstances, development on Arduino will mean using breadboards, soldering irons, and messy cabling which from experience has been flaky. What this “shield” (it is what they call to boards which attach on top of the original Arduino board) does is it provides simple and secure connection to various sensors with buckled wiring.

In the coming weeks I will begin posting the all important code!