SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
Switch_lecture
ArduinoMicro + XBee + SerialCommunication
とりあえず加速度。
ArduinoMicro
5V
GND
A0
A1
A2
1: Vdd
2: PSD
3: GND
5: SelfTest
6: Out X
7: Out Y
8: Out Z
KXM52-1050
Arduino sketch
BAUD_RATE : 9600
Device ID
Read analog values
Print to serial
“id,x,y,z” + ‘n’
int id = 0;
void setup()
{
Serial.begin( 9600 );
}
void loop()
{
int x = analogRead( A0 );
int y = analogRead( A1 );
int z = analogRead( A2 );
Serial.print( id );
Serial.print( "," );
Serial.print( x );
Serial.print( "," );
Serial.print( y );
Serial.print( "," );
Serial.print( z );
Serial.println();
delay( 100 );
}
Baud Rate
ボーレート
ボー
baud = 変調回数
9600bps = 1200Bps
9600bps = 1200 Character per sec
1Byte = 8bit = 1character( ASCII )
厳密には = bps ではない
AT Command
ATID : Network ID
ATCH : Channel
ATMY : My Address
ATDL : Send Address
ATBD : Baud Rate
ATWR : Write Settings
える
Communication
1 x 1
MY: 1
DL: 0
MY: 2
DL: 0
MY: 0
DL: -
MY: 1
DL: 0
Sender Receiver
MY: 0
DL: -
→
→
2~ x 1
→
Sender Receiver
Add XBee
ArduinoMicro
3V
RX
TX
GND
3.3V
DOUT
DIN
GND
XBee
Transmit→
書き込み時は外す
Receive←
→
←
Arduino sketch
( ArduinoMicro + XBee )
Serial → Serial1
Serial → Serial1
int id = 0;
void setup()
{
Serial1.begin( 9600 );
}
void loop()
{
int x = analogRead( A0 );
int y = analogRead( A1 );
int z = analogRead( A2 );
Serial1.print( id );
Serial1.print( "," );
Serial1.print( x );
Serial1.print( "," );
Serial1.print( y );
Serial1.print( "," );
Serial1.print( z );
Serial1.println();
delay( 100 );
}
Read Serial
( openFrameworks )
ofApp.h ofApp.cpp
class ofApp : public ofBaseApp
{
public:
ofSerial serial;
string str;
int index, x, y, z;
};
void ofApp::setup()
{
index = x = y = z = 0;
str = "";
serial.listDevices();
serial.setup( 0, 9600 );
ofBackground( 255 );
}
void ofApp::update()
{
while( true )
{
int c = serial.readByte();
if( c == OF_SERIAL_NO_DATA || c == OF_SERIAL_ERROR || c == 0 )
{
break;
}
if( c == ‘n’ )
{
vector< string > valStr = ofSplitString( str, "," );
if( valStr.size() == 4 )
{
index = ofToInt( valStr.at( 0 ) );
x = ofToInt( valStr.at( 1 ) );
y = ofToInt( valStr.at( 2 ) );
z = ofToInt( valStr.at( 3 ) );
}
str = "";
}
else
{
str.push_back( c );
}
}
}
Flow Chart
false
read 1 character
false
true
true
int c = serial.readByte()
c == OF_SERIAL_NO_DATA
or
c == OF_SERIAL_ERROR
or
c == 0
while( true )
break str.push_back( c )
c == ‘n’
ofSplitString( str, "," )
str = ""
index = ofToInt( valStr.at( 0 ) )
x = ofToInt( valStr.at( 1 ) )
y = ofToInt( valStr.at( 2 ) )
z = ofToInt( valStr.at( 3 ) )
Get values from string
“0,524,535,751”
convert to int from string
index = ofToInt( valStr.at( 0 ) )
x = ofToInt( valStr.at( 1 ) )
y = ofToInt( valStr.at( 2 ) )
z = ofToInt( valStr.at( 3 ) )
“0” “524” “535” “751”
id
string
string
x y z
string
int
vector< string > valStr = ofSplitString( str, "," )
Draw with sensor value
x = 0 ~ 1023
( float )x / 1023 = 0.0 ~ 1.0
( ( float )x / 1023 ) * ofGetWidth() = 0.0 ~ ofGetWidth()
( openFrameworks )
necessary to re-scale values
ofApp.cpp
void ofApp::draw()
{
ofSetColor( 0 );
ofFill();
ofRect( 0, 0, ( ( float )x / 1023 ) * ofGetWidth(), 60 );
}

Contenu connexe

Tendances

2. Базовый синтаксис Java
2. Базовый синтаксис Java2. Базовый синтаксис Java
2. Базовый синтаксис JavaDEVTYPE
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programsAmit Kapoor
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd StudyChris Ohk
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd StudyChris Ohk
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたAkira Maruoka
 
LLVM Backend の紹介
LLVM Backend の紹介LLVM Backend の紹介
LLVM Backend の紹介Akira Maruoka
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st StudyChris Ohk
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd StudyChris Ohk
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101premrings
 
Travel management
Travel managementTravel management
Travel management1Parimal2
 
Flashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas MacFlashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas MacESET Latinoamérica
 

Tendances (20)

2. Базовый синтаксис Java
2. Базовый синтаксис Java2. Базовый синтаксис Java
2. Базовый синтаксис Java
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
 
Implementing string
Implementing stringImplementing string
Implementing string
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
LLVM Backend の紹介
LLVM Backend の紹介LLVM Backend の紹介
LLVM Backend の紹介
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd Study
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Arrays
ArraysArrays
Arrays
 
Travel management
Travel managementTravel management
Travel management
 
Vcs23
Vcs23Vcs23
Vcs23
 
C questions
C questionsC questions
C questions
 
Myraytracer
MyraytracerMyraytracer
Myraytracer
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Flashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas MacFlashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas Mac
 

Similaire à 第一回 冬のスイッチ大勉強会 - XBee編 -

Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming LanguageArkadeep Dey
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노Chiwon Song
 
Documento de acrobat2
Documento de acrobat2Documento de acrobat2
Documento de acrobat2fraytuck
 
Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6scuhurricane
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
Write a Matlab code (a computerized program) for calculating plane st.docx
 Write a Matlab code (a computerized program) for calculating plane st.docx Write a Matlab code (a computerized program) for calculating plane st.docx
Write a Matlab code (a computerized program) for calculating plane st.docxajoy21
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryDatabricks
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryDatabricks
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
DConf 2016 std.database (a proposed interface & implementation)
DConf 2016 std.database (a proposed interface & implementation)DConf 2016 std.database (a proposed interface & implementation)
DConf 2016 std.database (a proposed interface & implementation)cruisercoder
 
LDAP Synchronization Connector (LSC)
LDAP Synchronization Connector (LSC)LDAP Synchronization Connector (LSC)
LDAP Synchronization Connector (LSC)Jonathan Clarke
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsSunil Yadav
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 

Similaire à 第一回 冬のスイッチ大勉強会 - XBee編 - (20)

C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Graphics point clipping c program
Graphics point clipping c programGraphics point clipping c program
Graphics point clipping c program
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
Struct examples
Struct examplesStruct examples
Struct examples
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노
 
Documento de acrobat2
Documento de acrobat2Documento de acrobat2
Documento de acrobat2
 
Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Write a Matlab code (a computerized program) for calculating plane st.docx
 Write a Matlab code (a computerized program) for calculating plane st.docx Write a Matlab code (a computerized program) for calculating plane st.docx
Write a Matlab code (a computerized program) for calculating plane st.docx
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
D3.js workshop
D3.js workshopD3.js workshop
D3.js workshop
 
DConf 2016 std.database (a proposed interface & implementation)
DConf 2016 std.database (a proposed interface & implementation)DConf 2016 std.database (a proposed interface & implementation)
DConf 2016 std.database (a proposed interface & implementation)
 
LDAP Synchronization Connector (LSC)
LDAP Synchronization Connector (LSC)LDAP Synchronization Connector (LSC)
LDAP Synchronization Connector (LSC)
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 

Dernier

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Dernier (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

第一回 冬のスイッチ大勉強会 - XBee編 -

  • 1. Switch_lecture ArduinoMicro + XBee + SerialCommunication
  • 2. とりあえず加速度。 ArduinoMicro 5V GND A0 A1 A2 1: Vdd 2: PSD 3: GND 5: SelfTest 6: Out X 7: Out Y 8: Out Z KXM52-1050
  • 3. Arduino sketch BAUD_RATE : 9600 Device ID Read analog values Print to serial “id,x,y,z” + ‘n’ int id = 0; void setup() { Serial.begin( 9600 ); } void loop() { int x = analogRead( A0 ); int y = analogRead( A1 ); int z = analogRead( A2 ); Serial.print( id ); Serial.print( "," ); Serial.print( x ); Serial.print( "," ); Serial.print( y ); Serial.print( "," ); Serial.print( z ); Serial.println(); delay( 100 ); }
  • 4. Baud Rate ボーレート ボー baud = 変調回数 9600bps = 1200Bps 9600bps = 1200 Character per sec 1Byte = 8bit = 1character( ASCII ) 厳密には = bps ではない
  • 5. AT Command ATID : Network ID ATCH : Channel ATMY : My Address ATDL : Send Address ATBD : Baud Rate ATWR : Write Settings える
  • 6. Communication 1 x 1 MY: 1 DL: 0 MY: 2 DL: 0 MY: 0 DL: - MY: 1 DL: 0 Sender Receiver MY: 0 DL: - → → 2~ x 1 → Sender Receiver
  • 8. Arduino sketch ( ArduinoMicro + XBee ) Serial → Serial1 Serial → Serial1 int id = 0; void setup() { Serial1.begin( 9600 ); } void loop() { int x = analogRead( A0 ); int y = analogRead( A1 ); int z = analogRead( A2 ); Serial1.print( id ); Serial1.print( "," ); Serial1.print( x ); Serial1.print( "," ); Serial1.print( y ); Serial1.print( "," ); Serial1.print( z ); Serial1.println(); delay( 100 ); }
  • 9. Read Serial ( openFrameworks ) ofApp.h ofApp.cpp class ofApp : public ofBaseApp { public: ofSerial serial; string str; int index, x, y, z; }; void ofApp::setup() { index = x = y = z = 0; str = ""; serial.listDevices(); serial.setup( 0, 9600 ); ofBackground( 255 ); } void ofApp::update() { while( true ) { int c = serial.readByte(); if( c == OF_SERIAL_NO_DATA || c == OF_SERIAL_ERROR || c == 0 ) { break; } if( c == ‘n’ ) { vector< string > valStr = ofSplitString( str, "," ); if( valStr.size() == 4 ) { index = ofToInt( valStr.at( 0 ) ); x = ofToInt( valStr.at( 1 ) ); y = ofToInt( valStr.at( 2 ) ); z = ofToInt( valStr.at( 3 ) ); } str = ""; } else { str.push_back( c ); } } }
  • 10. Flow Chart false read 1 character false true true int c = serial.readByte() c == OF_SERIAL_NO_DATA or c == OF_SERIAL_ERROR or c == 0 while( true ) break str.push_back( c ) c == ‘n’ ofSplitString( str, "," ) str = "" index = ofToInt( valStr.at( 0 ) ) x = ofToInt( valStr.at( 1 ) ) y = ofToInt( valStr.at( 2 ) ) z = ofToInt( valStr.at( 3 ) )
  • 11. Get values from string “0,524,535,751” convert to int from string index = ofToInt( valStr.at( 0 ) ) x = ofToInt( valStr.at( 1 ) ) y = ofToInt( valStr.at( 2 ) ) z = ofToInt( valStr.at( 3 ) ) “0” “524” “535” “751” id string string x y z string int vector< string > valStr = ofSplitString( str, "," )
  • 12. Draw with sensor value x = 0 ~ 1023 ( float )x / 1023 = 0.0 ~ 1.0 ( ( float )x / 1023 ) * ofGetWidth() = 0.0 ~ ofGetWidth() ( openFrameworks ) necessary to re-scale values ofApp.cpp void ofApp::draw() { ofSetColor( 0 ); ofFill(); ofRect( 0, 0, ( ( float )x / 1023 ) * ofGetWidth(), 60 ); }