MSP430 SERIAL COMMUNICATION USING ENERGIA AND PROCESSING -2

on Thursday, July 3, 2014









HI every one . here i achieve serial communication of msp430 launchpad using energia software. here i read the analog value of light intensity from ldr voltage divider circuit. convert the analog value into 10 bit digital value. and print the value in serial port. and finally read the serially printed value for show the value variation graph form using processing software.

to download energia software:
http://energia.nu/download/

to download processing software:
https://www.processing.org/download/?processing


CIRCUIT:




ENERGIA CODING:

void setup() {
  // initialize the serial communication:
  Serial.begin(4800);
}

void loop() {
  // send the value of analog input 3:
  int data = analogRead(A3);
  Serial.println(data);
// serially print the analog value

}











PROCESSING CODE:

import processing.serial.*;

Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph

void setup () {
  // set the window size:
  size(400, 300);
 myPort = new Serial(this, "COM13", 4800);   // select the com port in which port launchpad  
                                                                           //connected in your computer.
  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');
  // set inital background:
  background(0);
}
void draw () {
  // everything happens in the serialEvent()
}

void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // convert to an int and map to the screen height:
    float inByte = float(inString);
    inByte = map(inByte, 0, 1023, 0, height);

    // draw the line:
    stroke(127,34,255);
    line(xPos, height, xPos, height - inByte);

    // at the edge of the screen, go back to the beginning:
    if (xPos >= width) {
      xPos = 0;
      background(0);
    }
    else {
      // increment the horizontal position:
      xPos++;
    }
  }
}


                                                 Thank you for watching

1 comments:

Mayur Bille said...
This comment has been removed by the author.

Post a Comment