Monday, September 17, 2012

Monday, July 16, 2012

Working with SAM-3

Here's the routine to pass cmd at repeatedly to the SAM-3.



/*
 SAM motor player

 This sketch shows how to use the serial transmit pin (pin 1) to send SAM motor data.


 */
char inByte = 0;         // incoming serial byte
char firstSensor = 0;    // first analog sensor
char secondSensor = 0;   // second analog sensor
char i =0;

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(115200);

}

void loop() {
    if (i >= 200) i = 0;
    CmdOn(0x00, 0x20+i);
    delay(100);
    CmdOn(0x1E, 0x20+i);
    i=i+20;
        Serial.print("i=");            
        Serial.println(i,DEC);            

    delay(100);
  if (Serial.available() > 0) {
    // get incoming byte:
    inByte = Serial.read();
    // read first analog input:
    firstSensor = analogRead(A0);
    // read second analog input:
    secondSensor = analogRead(A1);
    // send sensor values:
    Serial.print(0xFF & firstSensor);
    Serial.print(",");
    Serial.println(0xFF & secondSensor);            
    delay(500);
  }
}

void CmdOn(int data1, int data2) {
  Serial.write(0xFF);
  Serial.write(data1);
  Serial.write(data2);
  Serial.write((data1^data2)&0x7F);  //compute checksum on the fly
}

Sunday, July 15, 2012

Using Arduino Firmata with Processing

Attempted to use the Standard Firmata on the Arduino Uno R2 to control 2 servos on pin 9 & 10 however it didsn't work.   It was replaced by the Analog Firmata and only the following Processing program worked.


import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int servoPinX = 10;
int servoPinY = 9;
int sensorPin = 0;
float sensorValue = 0;
int posX=0, posY=0; //servo position in degrees (0..180)

void setup()
{
 size(360, 360);

 arduino = new Arduino(this, Arduino.list()[1], 57600); //your offset may vary
 arduino.pinMode(servoPinX,4);
 arduino.pinMode(servoPinY,4);
 arduino.pinMode(sensorPin,0);
}

void draw()
{
 sensorValue = arduino.analogRead(0);
 println(sensorValue);

// read mouseX coordinate
 int newPosX = constrain(mouseX/2,40,140); // update bg & servo position if mouseX changed
// read mouseY coordinate
 int newPosY = constrain(mouseY/2,40,140); // update bg & servo position if mouseX changed

 if(newPosX != posX ||newPosY != posY)
 {
   background(newPosX);
      arduino.analogWrite(servoPinX, newPosX);
      arduino.analogWrite(servoPinY, newPosY);
   println (" newPos = " + newPosX );
   posX=newPosX; //update servo position storage variable
   posY=newPosY; //update servo position storage variable
 
 }
}

Tuesday, June 5, 2012

Understanding Processing

Great! I just started to learn about the origin of "Processing". I understand how powerful is Processing as a learning environment programming tool.
(Reference to: Processing: A Programming Handbook for Visual Designers and Artists by Casey Reas & Ben Fry)
.pde = Processing Development Environment

Processing also can create both the applet and Java application. Cool...
Just downloaded and installed the jdk-7u3-windows-i586.exe. (trying the Android in Processing he he he...)
Ok. done with jdk installation and proceeding to install the android-sdk-r16-windows.exe (installer version).
Hmm.. several addon.xml cites (mainly the mobile phone) are refusing connection...


Wednesday, April 4, 2012

Ethernet Pro

Tested the Ethernet Pro shield yesterday. Found that the MAC address can be changed by user. Tested the sample programs for the static and dynamic IP addresses. The DHCP in following can compiled under the Arduino 0.23 and not 1.0 (some renaming the header files are needed - haven't try this).

http://blog.jordanterrell.com/post/Arduino-DHCP-Library-Version-04.aspx

Wednesday, January 25, 2012

Understanding opto-mechanical mouse encoder

Ok, the opto-mechanical mouse is obsolete however the working of the encoder is worth studying.

I have just dismembered a MS mouse and viola... there was the encoder wheel sandwiched between the dual optotransistor and the IR LED. I simply connected a 3V battery to the Vcc of the optotransistor (OT) and the IR LED, with each of the emitters in the OT connected in series with a LED and then to ground. Whenever the wheel is rotated, the LEDs took turns to light on and then gone off. So, I'm going to mod it for use in my little mobile robot...he he

http://www.lightbestled.com/lightbestled/ProductView.asp?ID=421