Sunday Mar 15, 2009

Video - Sun SPOT as environmental sensor

We have compiled a small video to demonstrate what Sun SPOT is and what work we are doing to find out its utility as an environmental sensor. We are working with organizations like ATREE and UNESCO for the same. Hope you like it! Special thanks to Tejaswini Kelkar and Vasusen Patil for making such a nice video!

 

 

Wednesday Oct 08, 2008

Video - Mobile Integrated Sun SPOTs System

Hi.

We have built a model using Mobile Phones and Sun SPOTs which completely removes the distance barrier of the Sun SPOT communication. I have already given a detailed account of the project in my blog entry Sun SPOT and mobile Controlled Wireless System.

We have made a small video of the project. Have a look.

Note - I am really sorry if Mr. Vasusen Patil sounds really scary doing the narration part. He will try and improve for our next videos. Or we will try and find a better voice ;-)

Cheers!!






Wednesday Sep 17, 2008

How to make simple 2 Player remote controlled Game using Sun Spot.

Hi.

 In my last blog I described how we can control a car using the Sun SPOTs. Here I will describe how we can make a silly 2 Player Game using Sun Spots and Basestation.

What will we do..

Here we will build a simple 2-D Game that will have 9 X 9 Grid. There will be two Balls - Greeen and Red. The Movements of the balls in the grid will be controlled by Sun SPOTs!

If the dots overlap, a message will be displayed. The goal of Green Dot is to catch the Red Dot!!(I know its really silly ;-))

Note that this is a simple prototype to demonstrate how we can control games using Sun SPOT.

Requirements:

Whole Sun Spot Development Kit.


 Building the Remote SPOT Application.

Remote Spot App will contain following code:

/\*\*
 \* 
 \* @author Jay Mahadeokar
 \*/

public class StartApp extends MIDlet {
    
    protected void startApp() throws MIDletStateChangeException {
       
        EDemoBoard demoboard = EDemoBoard.getInstance();
        IAccelerometer3D acc = demoboard.getAccelerometer();      
        while(true)
        {
            try{
                RadiogramConnection conn = (RadiogramConnection)Connector.open("radiogram://0014.4F01.0000.1231:10");
                Radiogram rdg = (Radiogram)conn.newDatagram(conn.getMaximumLength());
                try
                {
                    rdg.writeUTF(""+demoboard.getAccelerometer().getTiltX()+","+demoboard.getAccelerometer().getTiltY());
                    conn.send(rdg);
                    Utils.sleep(100);
                }
                catch (NoRouteException e)
                {
                }
                finally
                {
                    conn.close();
                }
            }
            catch(IOException e){
            }
        }
    }
    
    protected void pauseApp() {
        // This will never be called by the Squawk VM
    }
    
    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // Only called if startApp throws any exception other than MIDletStateChangeException
    }
}


Building the Host Application

The Host Application will contain following Four Files:

1. Configuration.java

/\*\*
 \* @author Jay Mahadeokar
 \*/
public class Configuration {
    //Number of rows in the Grid
    public static int MAXROWS = 9;
    //Number of columns in the Grid
    public static int MAXCOLUMNS = 9;
}

2. GridPanel.java

/\*\*
 \* @author Jay Mahadeokar
 \*/
public class GridPanel extends JPanel
{
    
    public PlayBoard playboard = new PlayBoard();
    
    double xInc, yInc;
    final int
        ROWS = Configuration.MAXROWS,
        COLUMNS = Configuration.MAXCOLUMNS,
        DRAW      = 0,
        FILL      = 1,
        PAD       = 20;
    
    public GridPanel()
    {
    }
     
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        double w = getWidth();
        double h = getHeight();
        xInc = (w - 2\*PAD)/COLUMNS;
        yInc = (h - 2\*PAD)/ROWS;
        // row lines
        double x1 = PAD, y1 = PAD, x2 = w - PAD, y2 = h - PAD;
        for(int j = 0; j <= ROWS; j++)
        {
            g2.draw(new Line2D.Double(x1, y1, x2, y1));
            y1 += yInc;
        }
        // col lines
        y1 = PAD;
        for(int j = 0; j <= COLUMNS; j++)
        {
            g2.draw(new Line2D.Double(x1, y1, x1, y2));
            x1 += xInc;
        }

        x1 = PAD + playboard.xPos1 \* xInc + 1;
        y1 = PAD + playboard.yPos1 \* yInc + 1;
        g2.setPaint(Color.red);
        g2.fill(new Ellipse2D.Double(x1+5, y1+5, xInc - 15, yInc - 15));
                    
        x1 = PAD + playboard.xPos2 \* xInc + 1;
        y1 = PAD + playboard.yPos2 \* yInc + 1;
        g2.setPaint(Color.GREEN);
        g2.fill(new Ellipse2D.Double(x1+5, y1+5, xInc - 15, yInc - 15));
    }
 
    public void check()
    {
         if(playboard.check())
            JOptionPane.showMessageDialog(this,"Caught!!!");           
    }   
}

3. PlayBoard.java

/\*\*
 \*
 \* @author Jay Mahadeokar
 \*/
public class PlayBoard {

    public int xPos1 = 5,yPos1 = 5;
    public int xPos2 = 4,yPos2 = 4;
    
    public PlayBoard()
    {
    }
    public void move1(int x,int y)
    {
           if(x==1)
               if(x+xPos1<Configuration.MAXCOLUMNS)
                   xPos1++;
           if(x==-1)
               if(xPos1>0)
                   xPos1--;
           if(y==1)
               if(y+yPos1<Configuration.MAXROWS)
                   yPos1++;
           if(y==-1)
               if(yPos1>0)
                   yPos1--;
               
        System.out.println("x1: "+x+" y1: "+y);
        
    }
    public void move2(int x,int y)
    {
           if(x==1)
               if(x+xPos20)
                   xPos2--;
           if(y==1)
               if(y+yPos20)
                   yPos2--;
    }
    public boolean check()
    {
        if(xPos1 == xPos2 && yPos1 == yPos2)
        {
            xPos1 = 4; yPos1 = 4;
            xPos2 = 5;
            yPos2 = 5;
            return true;
        }
        else 
            return false;
    }
}


4. SunSpotHostApplication


/\*\*
 \*
 \* @author Jay Mahadeokar
 \*/

public class SunSpotHostApplication {
 
    public void runGame()
    {
        GridPanel gridPanel = new GridPanel();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(gridPanel);
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
 
        while(true)
        {
             try
             {
                RadiogramConnection conn = (RadiogramConnection) Connector.open("radiogram://:10");
                Radiogram rdg = (Radiogram)conn.newDatagram(conn.getMaximumLength());
 
                try 
                {
                    conn.receive(rdg);   
                    System.out.println(rdg.getAddress());
                    String s = rdg.readUTF();
                    System.out.println(s);
                    String accArr[] = s.split(",");
 
                    double x = Double.parseDouble(accArr[0]);
                    double y = Double.parseDouble(accArr[1]);
 
                    System.out.println("xtilt: "+x+", ytilt: "+y);
 
                    int passx = 0,passy = 0;
                    if(x>0.5)
                        passx = 1;
                    if(x<-0.5)
                        passx = -1;
                    if(y>0.5)
                        passy = 1;
                    if(y<-0.5)
                        passy = -1;
 
                    if(rdg.getAddress().equals("0014.4F01.0000.12B6"))
                    gridPanel.playboard.move1(passx, passy);
 
                   if(rdg.getAddress().equals("0014.4F01.0000.1A29"))
                    gridPanel.playboard.move2(passx, passy);
 
                    gridPanel.repaint();
                    gridPanel.check();
                }
                catch (NoRouteException e)
                {
                }
                finally
                {
                    conn.close();
                }
            }
            catch(Exception e){
            }
        }
    }
 
    public static void main(String[] args) {
        SunSpotHostApplication app = new SunSpotHostApplication();
        app.runGame();
    }
}


Deploy  the Spot Applications on Sun Spots. Connect the Basestation and Run the Host Application!

PS: Though the game looks really stupid, we can use it as a platform to control better games having better GUI's. We have the basic logic ready to control anything using Sun Spots. We just need to do the tedious Game Building Code now!

We are currently working on it!! Stay tuned!!!

Cheers!

Tuesday Sep 16, 2008

Making a Remote Controlled Car using Sun SPOT

Hi!

 Recently we made a small remote controlled car using Sun SPOTs and IC L293D. See for yourself how easy it can get using Sun SPOTs powered by Java!!


Requirements:

1. Sun SPOT Kit.  (Two Sun SPOTs)

2. IC L2393D.

3. DC Motors 2 Nos.

4. A car which you can dismantle and control using DC Motors having enough space to accomodate Sun SPOT and circuit..

5. Patience and some nice coffee and refreshments!!!


Hardware:

The Hardware basically centers around Sun SPOTs and DC Motors controlled by IC L293D.

The Basic Model is as Follows:

Here remote Sun SPOT will send data to Sun SPOT on car which will drive the IC according to DC IO pins D0 - D3.  The IC will drive the Motors which will run the car.

The circuit diagram for the IC is as follows. I think its self explanatory.




Software:

The Software consist of two parts:

1. Remote Control Spot.

Make a new Sun Spot Application say - "RemoteSpot" and add the following code to the StartApp file:


  
 
  package org.sunspotworld.demo;

import com.sun.spot.io.j2me.radiogram.Radiogram;
import com.sun.spot.io.j2me.radiogram.RadiogramConnection;
import com.sun.spot.peripheral.NoRouteException;
import com.sun.spot.peripheral.Spot;
import com.sun.spot.peripheral.radio.IRadioPolicyManager;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;
import com.sun.spot.sensorboard.peripheral.IAccelerometer3D;
import java.io.IOException;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.spot.util.IEEEAddress;
import com.sun.spot.util.Utils;
import javax.microedition.io.Connector;
 
    
 /\*\*
 \* Remote Spot will send Tilt values to the Car Spot.
 \* 
 \* @author Jay Mahadeokar
 \*/

public class StartApp extends javax.microedition.midlet.MIDlet {
    
    EDemoBoard demoboard = EDemoBoard.getInstance();
    
    protected void startApp() throws MIDletStateChangeException {
        
        IRadioPolicyManager rpm = Spot.getInstance().getRadioPolicyManager();
        IEEEAddress myAddr = new IEEEAddress(rpm.getIEEEAddress());
        System.out.println("Hi! my address = " + myAddr.asDottedHex());
        
        //This is my Car Sun SPOT address 
        IEEEAddress bsAddress = new IEEEAddress(new String("0014.4F01.0000.1231")); 
        IAccelerometer3D acc = demoboard.getAccelerometer();      
        
        while(true)
        {
            try{
                RadiogramConnection conn = (RadiogramConnection)Connector.open("radiogram://0014.4F01.0000.1A29:10");
                Radiogram rdg = (Radiogram)conn.newDatagram(conn.getMaximumLength());
                try
                {
                    //Get control called and value sent to car spot!
                    rdg.writeUTF(""+getControl());
                    conn.send(rdg);
                    Utils.sleep(200);  // Sleep for sometime!
                }
                catch (NoRouteException e)
                {
                    System.out.println ("No route to 0014.4F01.0000.1A29");
                }
                finally
                {
                    conn.close();
                }
            }
            catch(IOException e){
                System.out.println("There is a problem opening the connection");
            }
        }

    } 

    //Returns the numeric value corresponding to the current Tilt Positions of
    //Sun SPOT
    //Return values only if Tilt > 0.5 or Tilt < -0.5
    public int getControl()
    {
        int ret = 0;
        try {

            double xTilt = demoboard.getAccelerometer().getTiltX();
            double yTilt = demoboard.getAccelerometer().getTiltY();

            if (xTilt > 0.5 && yTilt < 0.5 && yTilt > -0.5) {
                ret = 110;
            }
            if (xTilt < -0.5 && yTilt < 0.5 && yTilt > -0.5) {
                ret = 101;
            }
            if (yTilt > 0.5 && xTilt < 0.5 && xTilt > -0.5) {
                ret = 100;
            }
            if (yTilt < -0.5 && xTilt < 0.5 && xTilt > -0.5) {
                ret = 1000;
            }
            
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return ret;
    }
    

    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
        ITriColorLED [] leds = EDemoBoard.getInstance().getLEDs();
        for (int i = 0; i < 8; i++) {           // turn off the LEDs when we exit
            leds[i].setOff();
        }
    }

    protected void pauseApp() {
    }

}

2. Car Spot Application.

Make another Sun Spot App and add following code to StartApp. This Spot will be placed on Car and will drive the IC.

 
import com.sun.spot.io.j2me.radiogram.Radiogram;
import com.sun.spot.io.j2me.radiogram.RadiogramConnection;
import com.sun.spot.peripheral.NoRouteException;
import com.sun.spot.peripheral.Spot;
import com.sun.spot.peripheral.radio.IRadioPolicyManager;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;
import com.sun.spot.sensorboard.peripheral.IAccelerometer3D;
import java.io.IOException;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.spot.util.IEEEAddress;
import com.sun.spot.util.Utils;
import javax.microedition.io.Connector;
 
    
 /\*\*
 \* Remote Spot will send Tilt values to the Car Spot.
 \* 
 \* @author Jay Mahadeokar
 \*/

public class StartApp extends javax.microedition.midlet.MIDlet {
    
    EDemoBoard demoboard = EDemoBoard.getInstance();
    
    protected void startApp() throws MIDletStateChangeException {
               
        //This is my Car Sun SPOT address 
        IEEEAddress bsAddress = new IEEEAddress(new String("0014.4F01.0000.1231")); 
        IAccelerometer3D acc = demoboard.getAccelerometer();      
        
        while(true)
        {
            try{
                RadiogramConnection conn = (RadiogramConnection)Connector.open("radiogram://0014.4F01.0000.1A29:10");
                Radiogram rdg = (Radiogram)conn.newDatagram(conn.getMaximumLength());
                try
                {
                    //Get control called and value sent to car spot!
                    rdg.writeUTF(""+getControl());
                    conn.send(rdg);
                    Utils.sleep(200);  // Sleep for sometime!
                }
                catch (NoRouteException e)
                {
                    System.out.println ("No route to 0014.4F01.0000.1A29");
                }
                finally
                {
                    conn.close();
                }
            }
            catch(IOException e){
                System.out.println("There is a problem opening the connection");
            }
        }

    } 

    //Returns the numeric value corresponding to the current Tilt Positions of
    //Sun SPOT
    //Return values only if Tilt > 0.5 or Tilt < -0.5
    public int getControl()
    {
        int ret = 0;
        try {

            double xTilt = demoboard.getAccelerometer().getTiltX();
            double yTilt = demoboard.getAccelerometer().getTiltY();

            if (xTilt > 0.5 && yTilt < 0.5 && yTilt > -0.5) {
                ret = 110;
            }
            if (xTilt < -0.5 && yTilt < 0.5 && yTilt > -0.5) {
                ret = 101;
            }
            if (yTilt > 0.5 && xTilt < 0.5 && xTilt > -0.5) {
                ret = 100;
            }
            if (yTilt < -0.5 && xTilt < 0.5 && xTilt > -0.5) {
                ret = 1000;
            }
            
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return ret;
    }
    

    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
        ITriColorLED [] leds = EDemoBoard.getInstance().getLEDs();
        for (int i = 0; i < 8; i++) {           // turn off the LEDs when we exit
            leds[i].setOff();
        }
    }

    protected void pauseApp() {
    }
}

Thats It!!! Now biuld the Apps and Deploy On Sun SPOTs. Mount the Car SPOT on Car and control it using Remote Spot!!

You can control car by tilting Spot:

Left - To Move left and accelarate.

Right - To move Right and Accelarate.

Down - To Move the Car Forward.

Up - To Reverse.

Note: The connections of circuit may be really tedious and may take a lot of time!

 
  



Thanks a lot to Mr. Abhishek Hisaria who designed the Hardware.

 
  



Some Pictures:

 

Thats Me!! The Car The Car Again!!

See more Pictures at: http://picasaweb.google.com/jai.mahadeokar/SunBlog

Cheers!!

 

 

Wednesday Sep 03, 2008

Sun SPOT Wiki

Hello!

We have been working on Sun SPOT for quite some time now, and during the course we realized that documentation for Sun SPOTs is not as good as it is for some of the other Sun  Technologies like Netbeans or Opensolaris..  

Example - The Netbeans Wiki is a great start for someone who is new to Netbeans world and wants to learn from scratch..

 So, we thought of documenting whatever we do using Sun SPOTs and we have created the SRKNEC Sun SPOT wiki project! Till now we have contributed four wiki documents! Please see the SPOT Wiki Index for more details..

I hope this will be helpful for other Sun SPOT enthusiasts..  I also hope that other Sun SPOT freaks would like to contribute to the wiki!

Cheers!

-Jay Mahadeokar,

Sun Campus Ambassador,

SRKNEC, India.

Tuesday Sep 02, 2008

Sun Spot and Mobile Controlled Wireless System

 Hello!

I have already blogged about this on the CA community...

Me, and my colleagues are working on the Sun SPOT technology which in itself is mind-blowing! We are planning to implement a Wireless Controlled System using the Sunspot device and Mobile phones. Here I will give a brief idea of the project.


Basic Principle

Basically we will have a mobile phone connected to a DTMF decoder IC along with some hardware circuit. This mobile phone will be on Auto Answer. The circuit has 4 digital output pins. These signals will be given to the 4 general purpose IO pins of Sun SPOT.

Now a mobile (situated in any part of the world) will call the host mobile and once the two are in connection, the signals at the IO pins will vary according to the Key pressed by the calling mobile. Now, we have 12 keys in standard mobile, so we will have 12 different signals going in to the Sun SPOT (Logically - 16 as we have 4 O/P lines).

The Sun Spot will do different jobs according to the key pressed by the calling mobile. We plan to control remote sun spots that will communicate with the connected sunspot according to the keys pressed. So we can have a complete control system that can be monitored and controlled from any part of the world.

Hardware

1. MT8870 dtmf decoder ic
2. 100k resitor 2pc.
3. 300k resistor 1pc.
4. 3.57945Mhz crystal oscillator
5. 0.1 uf capacitor 2pc.
6. 4 LED
7. connecting wires....



Software

Currently I have made a sample demo SunSpot application that continously listens to the IO pins and whenever there is any change in the input signal, a different thread is launched and a job corresponding to the input signal is launched. For now, I am just glowing the Leds of Sun Spot in different patterns.

The complete tutorial for the application can be seen here. (Note that we will be uploading whatever code and tutorials we accomplish on the wiki created as per the link)


Current Status

Both the preliminary Hardware and the basic software is ready and tested.

To be Implemented

1, We need to implement a password mechanism for a system, such that the system will work only after certain code is supplied at the start.

2. Currently we are thinking of controlling simple things like controlling devices using remote SPOTs (From anywhere in the world.)

3. We are also thinking on a way in which we can send some signals back to the calling mobile. This can be used to send useful information.


The implementation ideas for the project seem to be boundless, and any new ideas suggestions are welcome!!

Note: Special thanks to Abhishek Hisaria
IV Year Electronics,
SRKNEC, Nagpur, India.

He has completely designed the hardware and will be our hardware man in the future also!!!!


- Regards,
Jay Mahadeokar

About

I am the Sun Campus Ambassador for SRKNEC, India. Here I will blog about my college activities,and Sun's open source technologies like Netbeans, Opensolaris, Sun SPOTs etc..

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today