Energia MSP-430!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1

Similar documents
The Arduino IDE and coding in C (part 1)

Fubar Labs Arduino Tutorial

ROS Interface with Low Level Control - Arduino

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

Arduino Uno Microcontroller Overview

Chapter 2 The Basic Functions

E11 Lecture 4: More C!!! Profs. David Money Harris & Sarah Harris Fall 2011

Arduino Prof. Dr. Magdy M. Abdelhameed

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Arduino provides a standard form factor that breaks the functions of the micro-controller into a more accessible package.

More Arduino Programming

Lab 01 Arduino 程式設計實驗. Essential Arduino Programming and Digital Signal Process

Adapted from a lab originally written by Simon Hastings and Bill Ashmanskas

Arduino Part 2. Introductory Medical Device Prototyping

TANGIBLE MEDIA & PHYSICAL COMPUTING INTRODUCTION TO ARDUINO

Introduction to Arduino. Wilson Wingston Sharon

FUNCTIONS USED IN CODING pinmode()

ARDUINO. By Kiran Tiwari BCT 2072 CoTS.

Arduino 101 AN INTRODUCTION TO ARDUINO BY WOMEN IN ENGINEERING FT T I NA A ND AW E S O ME ME NTO R S

EXPERIMENT 7 Please visit to learn all features of arduino before you start the experiments

POP-BOT XT : The Arduino Compatible Mobile Robot kit 51

Introduction to Arduino

This tutorial will show you how to take temperature readings using the Freetronics temperature sensor and an Arduino Uno.

4Serial SIK BINDER //77

Arduino Part 3. Introductory Medical Device Prototyping

Robotics/Electronics Review for the Final Exam

Why embedded systems?

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Arduino

COMPUTAÇÃO UBÍQUA E MÓVEL: ARDUINO

analogwrite(); The analogwrite function writes an analog value (PWM wave) to a PWM-enabled pin.

E11 Lecture 4: More C!!! Profs. David Money Harris & Sarah Harris Fall 2011

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

DEPARTMENT OF MATHS, MJ COLLEGE

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

BASIC ARDUINO WORKSHOP. Mr. Aldwin and Mr. Bernardo

Quick Reference Guide

UNIT- 3 Introduction to C++

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Arduino notes IDE. Serial commands. Arduino C language. Program structure. Arduino web site:

Java Basic Programming Constructs

Station Automation --W3SZ

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

CSC 1214: Object-Oriented Programming

Course Outline Introduction to C-Programming

Procedure: Determine the polarity of the LED. Use the following image to help:

Variables and literals

ARDUINO WORKSHOP A HANDS-ON I N T R O D U C T I O N W I T H 65 PROJECTS JOHN BOXALL

A flow chart is a graphical or symbolic representation of a process.

FUNCTIONS For controlling the Arduino board and performing computations.

Quick Reference Guide

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

The Arduino Briefing. The Arduino Briefing

MEDIS Module 2. Microcontroller based systems for controlling industrial processes. Chapter 4: Timer and interrupts. M. Seyfarth, Version 0.

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

TABLE OF CONTENTS INTRODUCTION LESSONS PROJECTS

Arduino Programming Part 4: Flow Control

Computers Programming Course 6. Iulian Năstac

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental of Programming (C)

CTEC 1802 Embedded Programming Labs

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

Introduction to Microcontrollers Using Arduino. PhilRobotics

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.

Computer Programming : C++

EEG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

CS313D: ADVANCED PROGRAMMING LANGUAGE

Embedded Systems. Introduction. The C Language. Introduction. Why C instead ASM. Introduction to C Embedded Programming language

Data Types and Variables in C language

C: How to Program. Week /Mar/05

Arduino Programming. Arduino UNO & Innoesys Educational Shield

WALT: definition and decomposition of complex problems in terms of functional and non-functional requirements

EL6483: Brief Overview of C Programming Language

Designed & Developed By: Ms. Jasleen Kaur, PhD Scholar, CSE. Computer Science & Engineering Department

The Big Idea: Background: About Serial

Goal: Understand how to write programs for the Mudduino

A file containing the text of all sketches used in this document can be downloaded at

BASIC ELEMENTS OF A COMPUTER PROGRAM

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Lab 4 - Asynchronous Serial Communications

Chapter 2 - Introduction to C Programming

Microcontrollers and Interfacing week 8 exercises

Earthshine Design Arduino Starters Kit Manual - A Complete Beginners Guide to the Arduino. Project 13. Serial Temperature Sensor

EMBEDDED SYSTEMS PROGRAMMING Language Basics

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

Informatics Ingeniería en Electrónica y Automática Industrial

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

CARTOOINO Projects Book

DAQ-1000 Data Acquisition and Control System Application

Goal: Strengthen our understanding of C and program our Mudduino boards

Transcription:

Energia MSP-430 1

3 Energia 4 4 4 6 8 9 Energia 11 18 2

IIB Energia MSP-430 IIB C C++ 3

Energia Energia MSP-430 Windows Mac OS Linux MSP-430, http://www.energia.nu, Max OS X, windows Linux Mac OS X, energia- 0101E0010-macosx.dmg 4

dmg, :,Energia Application, control 1 Energia Application control, MSP430LPCD,,msp430,,, : http://energia.nu/guide MacOSX.html : 1 Energia Apple, control 5

MSP430 LED Energia, Tools - Serial Port (, ), (board) MSP-EXP430G2, LaunchPad w/ msp430g2553 : // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinmode(red_led, OUTPUT); // the loop routine runs over and over again forever: void loop() { digitalwrite(red_led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalwrite(red_led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second : (loop) 1., (setup) 2., LED 6

3., digitalwrite(red_led,high) LED, delay 1000, LED 1 digitalwrite(red LED,LOW) LED, LED 1000 Verify, upload :, LED, LED LED, 7

Energia Tools - Serial Monitor LED char incomingbyte = 'a'; // for incoming serial data void setup() { Serial.begin(9600); pinmode(red_led,output); pinmode(green_led,output); // opens serial port, sets data rate to 9600 bps establishcontact(); // send a byte to establish contact until receiver responds void loop() { // send data only when you receive data: if (Serial.available() > 0) { // read the incoming byte: incomingbyte = Serial.read(); if (incomingbyte == 'a') { digitalwrite(red_led, HIGH); else if (incomingbyte == 'b'){ digitalwrite(red_led,low); else if (incomingbyte == 'c'){ digitalwrite(green_led,high); else if (incomingbyte == 'd'){ digitalwrite(green_led,low); 8

setup Serial.begin(9600) 9600bps LED_RED LED_GREEN Serial.available() 1 0 Serial.read() Tool - Serial Monitor a b c d Serial.println(string str) Serial.println( Hello World ) A char 8 int float 2 Energia File - Examples - 6.Strings - StringToInt String instring = ""; // string to hold input void setup() { // Initialize serial communications: Serial.begin(9600); 9

void loop() { // Read serial input: while (Serial.available() > 0) { int inchar = Serial.read(); if (isdigit(inchar)) { // convert the incoming byte to a char // and add it to the string: instring += (char)inchar; // if you get a newline, print the string, // then the string's value: if (inchar == '\n') { Serial.print("Value:"); Serial.println(inString.toInt()); Serial.print("String: "); Serial.println(inString); // clear the string for new input: instring = ""; String String toint int 0~9 isdigit char a a Energia 10

Energia 1. PWM 50Hz duty cycle 7.5% 3 Energia delaymicroseconds(int a) delay int a 1/1000 000 a 16383 a a 16383 16383 delaymicroseconds(int a) delay(int a) 1/1000 50Hz 20ms 1.5ms delaymicroseconds void steer(){ int tmp = duty; for (int i=0; i<cyc; i++) { digitalwrite(steer,low); delaymicroseconds(tmp); digitalwrite(steer,high); delaymicroseconds(10000-tmp); delaymicroseconds(6550); STEER duty 11

duty duty duty 1230 delay Energia A 2. Energia analogwrite 490Hz A 3. USB Sketch - import Library SoftwareSerial 4. #define LEFT_AHEAD 10 #define LEFT_BACK 9 #define RIGHT_AHEAD 13 #define RIGHT_BACK 12 #define STEER 14 int duty = 1230; String instring=""; float RunInit = 3.0; float RUN_LEFT = 3.0; 12

float RUN_RIGHT = 3.0; int TURN = 60; int RUN1 = 255; int CYC = 5; float calibratenum = 0; void stopback(); void turnleft(); void turnright(); void goahead(); void park(); void goback(); void setup(){ Serial.begin(9600); pinmode(left_ahead,output); pinmode(left_back, OUTPUT); pinmode(right_ahead, OUTPUT); pinmode(right_back, OUTPUT); digitalwrite(left_ahead, LOW); digitalwrite(left_back, LOW); digitalwrite(right_ahead, LOW); digitalwrite(right_back, LOW);; pinmode(steer, OUTPUT); digitalwrite(steer, LOW); for (int i=0; i<100; i++) { digitalwrite(steer,low); delaymicroseconds(duty); digitalwrite(steer,high); delaymicroseconds(10000-duty); delaymicroseconds(6550); char incomingbyte = ' '; 13

void loop(){ if (Serial.available() > 0) { // read the incoming byte: incomingbyte = Serial.read(); if (incomingbyte == 'L') { Serial.println("TURN LEFT"); turnleft(); Serial.read(); else if (incomingbyte == 'R'){ Serial.println("TURN RIGHT"); turnright(); Serial.read(); else if (incomingbyte == 'A'){ Serial.println("GO AHEAD"); goahead(); Serial.read(); else if (incomingbyte == 'B'){ Serial.println("GO BACK"); goback(); Serial.read(); else if (incomingbyte == 'P'){ Serial.println("PARK"); park(); Serial.read(); else if (incomingbyte == 'C'){ calib(); else if (incomingbyte == 'K'){ changep(); else if (incomingbyte == 'S'){ changes(); else if (incomingbyte == 'D'){ changed(); void steer(float x){ int tmp = x*duty; 14

for (int i=0; i<cyc; i++) { digitalwrite(steer,low); delaymicroseconds(tmp); digitalwrite(steer,high); delaymicroseconds(10000-tmp); delaymicroseconds(6550); // digitalwrite(steer,low); void goahead(){ stopback(); analogwrite(left_ahead,run1); analogwrite(right_ahead,run1); steer(1.0); void turnleft(){ stopback(); analogwrite(right_ahead,run1); analogwrite(left_ahead,turn); steer(1.1); void turnright(){ stopback(); analogwrite(left_ahead,run1); analogwrite(right_ahead,turn); steer(0.88); void park(){ stopback(); digitalwrite(left_ahead, LOW); digitalwrite(right_ahead, LOW); steer(1); 15

void goback(){ // stopback(); digitalwrite(left_ahead,low); digitalwrite(right_ahead,low); analogwrite(left_back,run1); analogwrite(right_back,run1); steer(1); void stopback(){ digitalwrite(left_back, LOW); digitalwrite(right_back, LOW); int readint(){ int x; int flag=1; while(flag){ while (Serial.available() > 0) { int inchar = Serial.read(); if (isdigit(inchar)) { // convert the incoming byte to a char // and add it to the string: instring += (char)inchar; // if you get a newline, print the string, // then the string's value: if (inchar == '\n') { x=instring.toint(); flag=0; // clear the string for new input: instring = ""; return x; void calib(){ TURN = readint(); 16

Serial.println("calibrate:"); Serial.println(TURN,DEC); void changep(){ CYC = readint(); Serial.println("DELAY(ms):"); Serial.println(CYC*2,DEC); void changes(){ RUN1 = readint(); Serial.println("new spead:"); Serial.println(RUN1,DEC); void changed(){ duty = readint(); Serial.println("new duty:"); Serial.println(duty,DEC); 17

1. http://energia.nu/reference_index.html Energia Reference 2013.11 2. http://blog.csdn.net/liangwei88624/article/details/6885803 int float 2013.11 3. http://wenku.baidu.com/view/01762668a98271fe910ef978.html 2013.11 18

Energia Reference - Reference 13-12-2 6:24 Home Download Getting Started Reference Getting Help FAQ Projects Using Energia Contact Us Language Reference Energia programs can be divided in three main parts: structure, values (variables and constants), and functions. Structure Variables Functions setup() loop() Control Structures if if...else for switch case while do... while break continue return goto Further Syntax ; (semicolon) { (curly braces) // (single line comment) /* */ (multi-line comment) #define #include Constants HIGH LOW INPUT OUTPUT INPUT_PULLUP INPUT_PULLDOWN true false integer constants floating point constants Data Types void boolean char unsigned char byte int unsigned int word long unsigned long float double string - char array Digital I/O pinmode() digitalwrite() digitalread() Analog I/O analogreference() analogread() analogwrite() - PWM Advanced I/O tone() notone() shiftout() shiftin() pulsein() Time millis() micros() http://energia.nu/reference_index.html 1 3

Energia Reference - Reference 13-12-2 6:24 Arithmetic Operators = (assignment operator) + (addition) - (subtraction) * (multiplication) / (division) % (modulo) Comparison Operators == (equal to) = (not equal to) < (less than) > (greater than) <= (less than or equal to) >= (greater than or equal to) Boolean Operators && (and) (or) (not) Pointer Access Operators * dereference operator & reference operator Bitwise Operators & (bitwise and) (bitwise or) ^ (bitwise xor) ~ (bitwise not) << (bitshift left) >> (bitshift right) Compound Operators ++ (increment) -- (decrement) += (compound addition) -= (compound subtraction) *= (compound multiplication) /= (compound division) &= (compound bitwise and) = (compound bitwise or) String - object array Conversion char() byte() int() word() long() float() Variable Scope & Qualifiers variable scope static volatile const Utilities sizeof() delay() delaymicroseconds() Math min() max() abs() constrain() map() pow() sqrt() Trigonometry sin() cos() tan() Random Numbers randomseed() random() Bits and Bytes lowbyte() highbyte() bitread() bitwrite() bitset() bitclear() bit() External Interrupts attachinterrupt() detachinterrupt() Interrupts interrupts() nointerrupts() Communication Serial Stream http://energia.nu/reference_index.html 2 3

Energia Reference - Reference 13-12-2 6:24 Looking for something else? See the libraries page for interfacing with particular types of hardware. Try the list of community-contributed code on the Forum. The Energia language is based on C/C++ and uses the MSPGCC compiler. Reference Home Corrections, suggestions, and new documentation should be posted to the Forum. The text of the Energia Reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Energia reference is based on Arduino reference. Code samples in the reference are released into the public domain. Energia http://energia.nu/reference_index.html 3 3