Monday, September 6, 2010

Arduino Map






Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Determine Postition Of Sun With Arduino

//Provides sun position (relative) from static variables

#include <math.h>
#define pi    3.14159265358979323846
#define twopi (2*pi)
#define rad   (pi/180)
#define EarthMeanRadius     6371.01 // In km
#define AstronomicalUnit    149597890 // In km

//Input Variables --------------------- TIME HAS TO BE IN UT (UNIVERSAL TIME)! NO TIME ZONES OR SUMMER TIMES --------
//My last modifications were probably at this time on this date!
int Year = 2010; //year
int Month = 7; //month
int Day = 3; //day
float Hours = 16; //hour
float Minutes = 38; //minutes

float Longitude = 1.4756; //enter longitude here
float Latitude = 1.5763; //enter latitude here
//--------

//Program Variables
float ZenithAngle;
float Azimuth;
        float RightAscension;
float Declination;
        float Parallax;
        float ElevationAngle;

float ElapsedJulianDays;
float DecimalHours;
float EclipticLongitude;
float EclipticObliquity;
//--------

void setup() {
 Serial.begin(9600);
}

void sunPos(){


// Auxiliary variables
float dY;
float dX;

// Calculate difference in days between the current Julian Day
// and JD 2451545.0, which is noon 1 January 2000 Universal Time

float JulianDate;
long int liAux1;
long int liAux2;
// Calculate time of the day in UT decimal hours
DecimalHours = Hours + (Minutes / 60.0);
// Calculate current Julian Day
liAux1 =(Month-14)/12;
liAux2=(1461*(Year + 4800 + liAux1))/4 + (367*(Month
- 2-12*liAux1))/12- (3*((Year + 4900
+ liAux1)/100))/4+Day-32075;
JulianDate=(float)(liAux2)-0.5+DecimalHours/24.0;
// Calculate difference between current Julian Day and JD 2451545.0
ElapsedJulianDays = JulianDate-2451545.0;

// Calculate ecliptic coordinates (ecliptic longitude and obliquity of the
// ecliptic in radians but without limiting the angle to be less than 2*Pi
// (i.e., the result may be greater than 2*Pi)

float MeanLongitude;
float MeanAnomaly;
float Omega;
Omega=2.1429-0.0010394594*ElapsedJulianDays;
MeanLongitude = 4.8950630+ 0.017202791698*ElapsedJulianDays; // Radians
MeanAnomaly = 6.2400600+ 0.0172019699*ElapsedJulianDays;
EclipticLongitude = MeanLongitude + 0.03341607*sin( MeanAnomaly )
+ 0.00034894*sin( 2*MeanAnomaly )-0.0001134
-0.0000203*sin(Omega);
EclipticObliquity = 0.4090928 - 6.2140e-9*ElapsedJulianDays
+0.0000396*cos(Omega);

// Calculate celestial coordinates ( right ascension and declination ) in radians
// but without limiting the angle to be less than 2*Pi (i.e., the result may be
// greater than 2*Pi)

float Sin_EclipticLongitude;
Sin_EclipticLongitude= sin( EclipticLongitude );
dY = cos( EclipticObliquity ) * Sin_EclipticLongitude;
dX = cos( EclipticLongitude );
RightAscension = atan2( dY,dX );
if( RightAscension < 0.0 ) RightAscension = RightAscension + twopi;
Declination = asin( sin( EclipticObliquity )*Sin_EclipticLongitude );

// Calculate local coordinates ( azimuth and zenith angle ) in degrees

float GreenwichMeanSiderealTime;
float LocalMeanSiderealTime;
float LatitudeInRadians;
float HourAngle;
float Cos_Latitude;
float Sin_Latitude;
float Cos_HourAngle;
GreenwichMeanSiderealTime = 6.6974243242 +
0.0657098283*ElapsedJulianDays
+ DecimalHours;
LocalMeanSiderealTime = (GreenwichMeanSiderealTime*15
+ Longitude)*rad;
HourAngle = LocalMeanSiderealTime - RightAscension;
LatitudeInRadians = Latitude*rad;
Cos_Latitude = cos( LatitudeInRadians );
Sin_Latitude = sin( LatitudeInRadians );
Cos_HourAngle= cos( HourAngle );
ZenithAngle = (acos( Cos_Latitude*Cos_HourAngle
*cos(Declination) + sin( Declination )*Sin_Latitude));
dY = -sin( HourAngle );
dX = tan( Declination )*Cos_Latitude - Sin_Latitude*Cos_HourAngle;
Azimuth = atan2( dY, dX );
if ( Azimuth < 0.0 )
       Azimuth = Azimuth + twopi;
Azimuth = Azimuth/rad;
// Parallax Correction
Parallax=(EarthMeanRadius/AstronomicalUnit)
*sin(ZenithAngle);
ZenithAngle=(ZenithAngle //Zenith angle is from the top of the visible sky (thanks breaksbassbleeps)
+ Parallax)/rad;
                ElevationAngle = (90-ZenithAngle); //Retrieve useful elevation angle from Zenith angle
}

void loop(){
  sunPos(); //Run sun position calculations
  Serial.print("Elevation Angle:  ");
  Serial.println(ElevationAngle, 0); //Print Elevation (Vertical) with no decimal places as accuracy is not really great enough
  Serial.print("Azimuth:  ");
  Serial.println(Azimuth, 0); //Print Azimuth (Horizontal) with no decimal places
  if(ElevationAngle < 0)
  Serial.println("The sun has set. Get some sleep!");
  delay(10000); //Delay 10 seconds - Values aren't going to have changed anyway as they are currently static variables!
}

Funnel IO - Wireless Freedom...



I had ordered one Funnel IO around 10 days back. Eagerly waiting for it to come. A specifically designed to exploit the wireless abilities of the Arduino board.
Having a unique characteristic of being programmed wireless, this board packs loads of features like programmability with FTDI cable.
On-board pin configuration holes for XBee chip for fast interfacing.
Can’t wait to get my hands on one. Will keep you posted on any new developments.

Arduino Taskbar Icon FIx

Ever wondered why the Arduino IDE generates a Java application like icon on your taskbar? well, because its a Java application..!! Now aI have got something interesting for you.
You can really change the way that icon looks and turn it into the original more perky Arduino icon. I have tested it on my Windows 7 and works fine. A 10 second job… :)
All you need to do is to download this and copy the extracted files to your arduino/java/bin folder.
This is how it will look like:

Robotics and Physical Computing Workshop

robotics and physical- computing workshop
topics include programming of microcontroller, designing of robots, interfacing various sensors and interfacing with other platforms
platforms and software interfacing include:
 arduino
 matlab
 processing
 flash
 autoit
 wireless sensor networks (over 433 MHz and 2.4 GHz unlicensed bands)
exclusive introduction to microsoft robotics studio
all course material will be freely provided to participants
fees: 200 INR per participant
timings: saturdays: 1pm to 5pm & sundays: 9am to 1pm
duration: 1 month
contact info: hardik pandya (9824340535)
adesh shah (9558528374)
registrations from 6th sep and batches start from 18th sep
(limited vacancy – register soon)
VASCSC will award certificates to all participants on completion

AutoIt - Just Overpowers You...

Well, I have come to know about a great script generator on Windows platform. Used mostly to generate externally excited events, we have interfaced Nanchuck and come up with something like a Nunchuck mouse application. We have been successful in moving the cursor… Clicking algorithm coming in a day or two. But it could not have been possible without the AutoIt.
Guys, do have a look at the AutoIt tool at www.autoitscript.com to know its awesome functionality. Well, in the general introduction and examples section, the Mouse Cursor Randomizer itself is a great little tweak you can use to frighten the hell out of your friends. It virtually inhibits the user from controlling the mouse and moves cursor randomly on the screen. You must have a look at that.
I would share the mouse.au3 script here. Paste it in your editor and see the execution.
Func exitthescript()
Exit
EndFunc
HotKeySet(“{F3}”, “exitthescript”)
While 1
$posx = Random( 1, 1000 )
$posy = Random( 1, 1000 )
MouseMove( $posx, $posy )
Sleep( 100000000000000000000000 )
WEnd
Func exitthescript() Exit EndFunc HotKeySet(“{F3}”, “exitthescript”)
While 1
$posx = Random( 1, 1000 )
$posy = Random( 1, 1000 )
MouseMove( $posx, $posy )
Sleep( 100000000000000000000000 )
WEnd

Wii Nunchuck and Arduino


For past ten days, I was desperate to get that neat little Accelerometer that came in the 250/- Rs Nunchuck to work with my Duemilanove. Finally I got it running and I am documenting it here.
How To Connect:
The Real Photograph:
The Nunchuck uses the I2C communication bus for the output signals. The color codes I had to use for the nunchuck I used were:
Red – Power (+3.3 V strictly)
White – Ground
Green – Analog In 4
Black – Analog In 5
Here, the Green and Black wires are coming as SDA and SCK signals as a TWI communication.
Here’s my code:
#include <Wire.h>
#include <string.h>

#undef int
#include <stdio.h>

uint8_t outbuf[6];  // array to store arduino output
int cnt = 0;
int ledPin = 13;

void
setup ()
{
  beginSerial (19200);
  Serial.print ("Finished setup\n");
  Wire.begin ();  // join i2c bus with address 0x52
  nunchuck_init (); // send the initilization handshake
}

void
nunchuck_init ()
{
  Wire.beginTransmission (0x52); // transmit to device 0x52
  Wire.send (0x40);  // sends memory address
  Wire.send (0x00);  // sends sent a zero.
  Wire.endTransmission (); // stop transmitting
}

void
send_zero ()
{
  Wire.beginTransmission (0x52); // transmit to device 0x52
  Wire.send (0x00);  // sends one byte
  Wire.endTransmission (); // stop transmitting
}

void
loop ()
{
  Wire.requestFrom (0x52, 6); // request data from nunchuck
  while (Wire.available ())
    {
      outbuf[cnt] = nunchuk_decode_byte (Wire.receive ()); // receive byte as an integer
      digitalWrite (ledPin, HIGH); // sets the LED on
      cnt++;
    }

  // If we recieved the 6 bytes, then go print them
  if (cnt >= 5)
    {
      print ();
    }

  cnt = 0;
  send_zero (); // send the request for next bytes
  delay (100);
}

// Print the input data we have recieved
// accelerometer data is 10 bits long
// so we read 8 bits, then we have to add
// on the last 2 bits.  That is why I
// multiply them by 2 * 2
void
print ()
{
  int joy_x_axis = outbuf[0];
  int joy_y_axis = outbuf[1];
  int accel_x_axis = outbuf[2] * 2 * 2;
  int accel_y_axis = outbuf[3] * 2 * 2;
  int accel_z_axis = outbuf[4] * 2 * 2;

  int z_button = 0;
  int c_button = 0;

 // byte outbuf[5] contains bits for z and c buttons
 // it also contains the least significant bits for the accelerometer data
 // so we have to check each bit of byte outbuf[5]
  if ((outbuf[5] >> 0) & 1)
    {
      z_button = 1;
    }
  if ((outbuf[5] >> 1) & 1)
    {
      c_button = 1;
    }

  if ((outbuf[5] >> 2) & 1)
    {
      accel_x_axis += 2;
    }
  if ((outbuf[5] >> 3) & 1)
    {
      accel_x_axis += 1;
    }

  if ((outbuf[5] >> 4) & 1)
    {
      accel_y_axis += 2;
    }
  if ((outbuf[5] >> 5) & 1)
    {
      accel_y_axis += 1;
    }

  if ((outbuf[5] >> 6) & 1)
    {
      accel_z_axis += 2;
    }
  if ((outbuf[5] >> 7) & 1)
    {
      accel_z_axis += 1;
    }

  Serial.print (joy_x_axis, DEC);
  Serial.print ("\t");

  Serial.print (joy_y_axis, DEC);
  Serial.print ("\t");

  Serial.print (accel_x_axis, DEC);
  Serial.print ("\t");

  Serial.print (accel_y_axis, DEC);
  Serial.print ("\t");

  Serial.print (accel_z_axis, DEC);
  Serial.print ("\t");

  Serial.print (z_button, DEC);
  Serial.print ("\t");

  Serial.print (c_button, DEC);
  Serial.print ("\t");

  Serial.print ("\r\n");
}

// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
char
nunchuk_decode_byte (char x)
{
  x = (x ^ 0x17) + 0x17;
  return x;
}

16*2 LCD Pin Outs

The following table shows the pin details of the LCD.
LCD Pin Number Symbol Function
1 Vss Display power ground
2 Vdd Display power +5V
3 Vo Contrast Adjust. Altered by adjusting the voltage to this pin, grounding it sets it to maximum contrast.
4 RS Register select
5 R/W
6 E Enable strobe
7 DB0 Data Bus 0
8 DB1 Data Bus 1
9 DB2 Data Bus 2
10 DB3 Data Bus 3
11 DB4 Data Bus 4
12 DB5 Data Bus 5
13 DB6 Data Bus 6
14 DB7 Data Bus 7
15 A
LED backlight power +5V
16 K LED backlight power ground

Why Arduino Matters...

In January 1975, Popular Electronics ran a cover story about a new computer for hobbyists. The Altair 8800 came as a kit and cost $439 (the equivalent of $1,778.58 in today’s dollars). It came with no on-board memory. You programmed it by entering Intel 8080 opcodes by hand via a series of switches on the front panel. Buying 4k of memory, the ability to read in programs from paper tape, and a teletype interface would increase the price 6 fold. You had to solder the thing together by hand. By comparison with the big university and corporate mainframes it was basically useless.
But Popular Electronics was the Make Magazine of its day and engineering schools had begun to require their graduates to learn some programming, so Forest Mims and Ed Roberts, the two guys in Albuquerque who’d put the Altair together, figured they could probably sell a few hundred in the first year to this emerging group of hackers avant la lettre.
They took 1,000 orders in the first month. Six months after the release they’d sold 5,000. By October of that year their company had 90 employees.
Why was the Altair such a runaway success? After all, by comparison to the cutting edge computers of its day, it was underpowered and extremely difficult to work with. The answer is ownership. The Altair offered bourgeoning hackers their first chance at a computer that would be fully and completely theirs. They could take it home, throw it up on their work bench, take it apart, put it back together and try to get it to do totally new unimagined things. They could program their Altairs to play Fool on the Hill through a transistor radio. They could build a board to let the Altair drive a color TV in Times Square. They could starta small company to sell programming languages for it. They could get together with their fellow Altair owners to share programs and cool hacks.
This last point can’t be emphasized enough. The Altair crystallized growing local groups of DIY computer enthusiasts like the Homebrew Computer Club in Silicon Valley. It gave them an outlet for their energies and an example of what could be done. It made them believe that their incredible fantasy of having their own computers might really come true.
And after that, there was no stopping them. This new generation of hackers dedicated itself with an almost religious zeal to spreading the idea of computer ownership across the world. They invented the personalcomputer — a whole industry dedicated to the notion that computers could make life better and work easier for everyone, not just huge institutions. The Homebrew Computer club alone included the founders of Apple, Ozborne (builders of the first portable), and a raft of other industry pioneers.
Today, the world of physical computing closely resembles the personal computer industry circa 1975. We’ve been around for a few years struggling around the edges with tools and products that were designed, priced, and packaged for serious industry, but we haven’t made any money and we haven’t moved the world. That’s about to change.
Recently, our Altair arrived. It’s called the Arduino. This is 2009 so instead of being built by two engineers in Albuquerque, it was built by an open source international cabal of programmers and professors.
A lot of people complain that it’s underpowered and overpriced (even though it only costs $8.64 in 1975 dollars). But you don’t need special hardware to program it. It lets you do all the basic tasks with just a line or two of perfectly comprehensible code. And there’s a thriving community of people busily using it to do all the useless, fun, creative things they’d always dreamed of if only they could get their hands on a computer that could sense and control the world around it. They’re using it to teach houseplants to call for help if they need watering. And they’re using it to play music on glasses of water.
If the Arduino is the Altair of physical computing then what will be its VisiCalc? What will be the killer application that makes the physical computer of the future a necessity for business. If the Arduino is the Altair, what will physical computing’s Mac look like? I don’t think anyone today knows the answers to these questions.
But the answers are coming. In the next few years, physical computing has as much of a shot at changing the world as technologies ever get. And this is the time to get involved. Unlike the web, personal computer, and green energy industries, physical computing is a space where two guys in a garage can come along and invent something that will touch billions of people around the world without anyone else’s permission. That’s because what’s needed in physical computing is not advanced research, massive infrastructure investment, or huge production facilities. What’s needed is close attention to applying the existing technology to solving human-scale problems. Microcontrollers and sensors, CNC milling machines and laser cutters, GPS devices and accelerometers need to be transformed into tools that regular people can use to improve their daily lives: to make themselves more connected to the people and places around them, to entertain, educate, and distract them.
In 30 years, when people tell the story of the Physical Computing Revolution and how it changed the world, what will they say about you?

First Arduino Prototype

For those who might be wondering how the first Arduino board must have looked like, here is the snap.