Energia: Difference between revisions

From air
Jump to navigation Jump to search
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[File:Energia-MSP430.png|200px|thumb|right|Energia IDE]]
''Energia is a fork of Arduino’s Processing IDE for TI’s MSP430 microcontrollers.''
Energia supports LaunchPad with msp430g2231, msp430g2452 and msp430g2553


Energia is a fork of [[Arduino]]’s Processing IDE for TI’s [[MSP430]] microcontrollers.


Pin mapping : https://github.com/energia/Energia/wiki/Hardware#wiki-LaunchPad_MSP430G2452


==Examples==
===Potentiometer===
[[File:Msp430analogread.jpg|200px|thumb|right|Analog Read (A0 or P1_0)]]
[[Image:StellarPad.jpg|thumb|200px|right|StellarPad running a Energia sketch]]

<pre>
const int analogInPin = A0; // or P1_0 with Launchpad P1.0 Analog input pin that the potentiometer is attached to
// or PB5 with StellarPad PB5 Analog input pin that the potentiometer is attached to


int sensorValue = 0; // value read from the pot

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600); // 4800 with msp430g2231
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);

// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.println();

// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}

</pre>



===3 Buttons Pad===
[[File:Plotjoueurs.jpg|200px|thumb|right|3 Buttons Pad]]

<pre>
/*
Tree buttons pad
*/

// set pin numbers:
const int button1Pin = P1_3; // the number of the pushbutton pin
const int button2Pin = P1_4; // the number of the pushbutton pin
const int button3Pin = P1_5; // the number of the pushbutton pin
const int ledPin = GREEN_LED; // the number of the LED pin

// variables will change:
boolean ledState = false; // variable for reading the pushbutton status
int buttonsStates = 0; // variable for reading the pushbutton status

void setup() {
Serial.begin(9600); // starts the serial monitor
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
buttonsStates=readButtonsStates();
Serial.println(buttonsStates);
}

int readButtonsStates(){
int _buttonsStates=0;
if (digitalRead(button1Pin) == LOW) {
_buttonsStates |= B1;
}
if (digitalRead(button2Pin) == LOW) {
_buttonsStates |= B10;
}
if (digitalRead(button3Pin) == LOW) {
_buttonsStates |= B100;
}
return _buttonsStates;
}

void toogle(){
if (ledState) {
// turn LED off:
digitalWrite(ledPin, LOW);
} else {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
ledState=!ledState;
}

void loop(){

int _buttonsStates=readButtonsStates();
// send changes only
if(buttonsStates != _buttonsStates) {
buttonsStates = _buttonsStates;
Serial.print(buttonsStates);
toogle(); // for debug
}
delay(50);
}

</pre>


===Récupération de la sortie avec [[Node.js]]===
<pre>
// launchpad.js <port>
var port = process.argv[2];
var serialport = require('serialport');
var sp = new serialport.SerialPort(port, {
baudrate: 9600,
parser: serialport.parsers.readline('\r\n')});

sp.on('data', function(line) {
console.log(line);
});
</pre>

<pre>
npm install serialport
node launchpad.js /dev/tty.uart-XYZ
</pre>

==Supported Boards==
* [[TI' MSP430 Launchpad|LaunchPad with msp430g2231]],
* [[TI' MSP430 Launchpad|LaunchPad with msp430g2452]],
* [[TI' MSP430 Launchpad|LaunchPad with msp430g2553]],
* FraunchPad with msp430fr5739
* [[Stellaris Launchpad]].


==Pin mapping==
https://github.com/energia/Energia/wiki/Hardware#wiki-LaunchPad_MSP430G2452

==Links==
* https://github.com/energia/Energia/wiki
* https://github.com/energia/Energia/wiki
* Forum http://forum.43oh.com/forum/28-energia/
* Forum http://forum.43oh.com/forum/28-energia/

Latest revision as of 19:55, 7 March 2013

Energia IDE

Energia is a fork of Arduino’s Processing IDE for TI’s MSP430 microcontrollers.


Examples

Potentiometer

Analog Read (A0 or P1_0)
StellarPad running a Energia sketch
const int analogInPin = A0;  // or P1_0 with Launchpad P1.0 Analog input pin that the potentiometer is attached to
                             // or PB5  with StellarPad PB5 Analog input pin that the potentiometer is attached to


int sensorValue = 0;        // value read from the pot

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); // 4800 with msp430g2231
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);            

  // print the results to the serial monitor:
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);      
  Serial.println();   

  // wait 10 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(10);                     
}


3 Buttons Pad

3 Buttons Pad
/*
Tree buttons pad
 */

// set pin numbers:
const int button1Pin = P1_3;     // the number of the pushbutton pin
const int button2Pin = P1_4;     // the number of the pushbutton pin
const int button3Pin = P1_5;     // the number of the pushbutton pin
const int ledPin =  GREEN_LED;      // the number of the LED pin

// variables will change:
boolean ledState = false;      // variable for reading the pushbutton status
int buttonsStates = 0;         // variable for reading the pushbutton status

void setup() {
  Serial.begin(9600);          // starts the serial monitor
  
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(button1Pin, INPUT_PULLUP);     
  pinMode(button2Pin, INPUT_PULLUP);     
  pinMode(button3Pin, INPUT_PULLUP);
  
  buttonsStates=readButtonsStates();
  Serial.println(buttonsStates);
}

int readButtonsStates(){
  int _buttonsStates=0;
  
  if (digitalRead(button1Pin) == LOW) { 
    _buttonsStates |= B1; 
  }
  if (digitalRead(button2Pin) == LOW) { 
    _buttonsStates |= B10; 
  }
  if (digitalRead(button3Pin) == LOW) { 
    _buttonsStates |= B100; 
  }
  return _buttonsStates;
} 

void toogle(){
  if (ledState) {     
    // turn LED off:    
    digitalWrite(ledPin, LOW);  
  } else {
    // turn LED on:
    digitalWrite(ledPin, HIGH); 
  }
  ledState=!ledState;
}

void loop(){

  int _buttonsStates=readButtonsStates();
  
  // send changes only
  if(buttonsStates != _buttonsStates)  {
    buttonsStates = _buttonsStates;
    Serial.print(buttonsStates);
    toogle(); // for debug
  }
  
  delay(50);
}


Récupération de la sortie avec Node.js

// launchpad.js <port>
var port = process.argv[2];
var serialport = require('serialport');
var sp = new serialport.SerialPort(port, {
                baudrate: 9600,
                parser: serialport.parsers.readline('\r\n')});

sp.on('data', function(line) {
    console.log(line);
});
npm install serialport
node launchpad.js /dev/tty.uart-XYZ

Supported Boards


Pin mapping

https://github.com/energia/Energia/wiki/Hardware#wiki-LaunchPad_MSP430G2452

Links