SlideShare a Scribd company logo
Switch_lecture
FullColorLED & MPU-6050
FullColorLED
ArduinoMicro
5V
10 (PWM)
11 (PWM)
Common
9 (PWM) Red
Green
Blue
OSTA71A1D-A
Anode→
Cathode←150Ω
100Ω
100Ω
Cathode←
Cathode←
Arduino sketch
Set pin mode OUTPUT
Declare LED pins
Set LED color Red
Set LED function
0 -> HIGH
255 -> LOW
(Anode Common)
const int ledPins[] = { 9, 10, 11 };
const int nLedPins = 3;
void setup()
{
for( int i = 0; i < nLedPins; ++i )
{
pinMode( ledPins[ i ], OUTPUT );
}
setLed( 255, 0, 0 );
}
void loop()
{
}
void setLed( int _r, int _g, int _b )
{
analogWrite( ledPins[ 0 ], 255 - _r );
analogWrite( ledPins[ 1 ], 255 - _g );
analogWrite( ledPins[ 2 ], 255 - _b );
}
MPU-6050(GY-521)
( I2C Interface )
ArduinoMicro
5V
GND
3 (SCL)
2 (SDA)
VCC
GND
SCL
SDA
MPU-6050
Arduino Library
Download “i2cdevlib” from
github.com/jrowberg/i2cdevlib
into “書類 / Arduino / Libraries /”
i2cdevlib / Arduino / I2Cdev and
Copy
Paste
i2cdevlib / Arduino / MPU6050
Example
Arduino / Libraries / MPU6050 / Examples / MPU6050_raw / MPU6050_raw.ino
raw データを取得する Example
ここから不要な部分を削っていく。
Arduino sketch
MPU6050 object
Include libraries
Sensor values
Initialize
Set full scale accel range 16G
Set full scale gyro range 2000dps
Get acceleration values
Get rotation values
#include "I2Cdev.h"
#include "MPU6050.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int id = 0;
void setup()
{
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup( 400, true );
#endif
Serial1.begin( 9600 );
accelgyro.initialize();
accelgyro.setFullScaleAccelRange( MPU6050_ACCEL_FS_16 );
accelgyro.setFullScaleGyroRange( MPU6050_GYRO_FS_2000 );
}
void loop()
{
accelgyro.getAcceleration( &ax, &ay, &az );
accelgyro.getRotation( &gx, &gy, &gz );
Serial1.print( id );
Serial1.print( "," );
Serial1.print( ax );
Serial1.print( "," );
Serial1.print( gz );
Serial1.println();
delay( 60 );
}
( ArduinoMicro + XBee + MPU-6050 )
Arduino sketch
int16_t = -32768 ~ 32767
accelgyro.initialize()
accelgyro.setFullScaleAccelRange( MPU6050_ACCEL_FS_16 )
accelgyro.setFullScaleGyroRange( MPU6050_GYRO_FS_2000 )
signed 16bit
この中で
されている
setFullScaleAccelRange( MPU6050_ACCEL_FS_2 )
setFullScaleGyroRange( MPU6050_GYRO_FS_250 )
( ArduinoMicro + XBee + MPU-6050 )
250dps 2000dps
Accel
2G 16G
Gyro
Arduino sketch
( ArduinoMicro + XBee + MPU-6050 )
Address of “ax”
Memory
Address 0x00
ax
&ax
int16_t
x
int16_t*
0x01 0x02 0x03 0x04
...
“MPU6050.h”
accelgyro.getAcceleration( &ax, &ay, &az )
void MPU6050::getAcceleration( int16_t* x, int16_t* y, int16_t* z )
Pointer of “int16_t”
int16_t* x = &ax;
assign address to pointer
Memory
Address 0x00
ax
*x
x
int16_t
x
int16_t*
0x01 0x02 0x03 0x04
...
*x = -32768; ax = -32768;
in automatically
ax -32768
Read Serial
( openFrameworks )
ofApp.h ofApp.cpp
class ofApp : public ofBaseApp
{
public:
ofSerial serial;
string str;
int index, ax, gz;
};
void ofApp::setup()
{
index = ax = gz = 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() == 3 )
{
index = ofToInt( valStr.at( 0 ) );
ax = abs( ofToInt( valStr.at( 1 ) ) );
gz = ofToInt( valStr.at( 2 ) );
}
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 ) )
ax = abs( ofToInt( valStr.at( 1 ) ) )
gz = ofToInt( valStr.at( 2 ) )
Get values from string
“0,-32768,32767”
convert to int from string
index = ofToInt( valStr.at( 0 ) )
ax = abs( ofToInt( valStr.at( 1 ) ) )
gz = ofToInt( valStr.at( 2 ) )
“0” “-32768” “32767”
id
string
string
ax gz
string
int
vector< string > valStr = ofSplitString( str, "," )
-32768 ~ 32767 0 ~ 32768
Draw with sensor value
x = 0 ~ 32768
( float )x / 32768 = 0.0 ~ 1.0
( ( float )x / 32768 ) * ofGetWidth() = 0.0 ~ ofGetWidth()
( openFrameworks )
necessary to re-scale values
ofApp.cpp
void ofApp::draw()
{
ofSetColor( 0 );
ofFill();
ofRect( 0, 0, ( ( float )ax / 32768 ) * ofGetWidth(), 60 );
}

More Related Content

What's hot

LLVM Backend の紹介
LLVM Backend の紹介LLVM Backend の紹介
LLVM Backend の紹介
Akira Maruoka
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
Chris Ohk
 
Cquestions
Cquestions Cquestions
Cquestions
mohamed sikander
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
Akira Maruoka
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
Chris Ohk
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd Study
Chris Ohk
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
Chris Ohk
 
2. Базовый синтаксис Java
2. Базовый синтаксис Java2. Базовый синтаксис Java
2. Базовый синтаксис Java
DEVTYPE
 
Implementing string
Implementing stringImplementing string
Implementing string
mohamed sikander
 
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
premrings
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
Farhan Ab Rahman
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
mohamed sikander
 
Travel management
Travel managementTravel management
Travel management1Parimal2
 
Arrays
ArraysArrays
C questions
C questionsC questions
C questions
mohamed sikander
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
mohamed sikander
 
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
ESET Latinoamérica
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++vidyamittal
 
7segment scetch
7segment scetch7segment scetch
7segment scetchBang Igo
 

What's hot (20)

LLVM Backend の紹介
LLVM Backend の紹介LLVM Backend の紹介
LLVM Backend の紹介
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
Cquestions
Cquestions Cquestions
Cquestions
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd Study
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
 
2. Базовый синтаксис Java
2. Базовый синтаксис Java2. Базовый синтаксис Java
2. Базовый синтаксис Java
 
Implementing string
Implementing stringImplementing string
Implementing string
 
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
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
Travel management
Travel managementTravel management
Travel management
 
Arrays
ArraysArrays
Arrays
 
C questions
C questionsC questions
C questions
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
C++ programs
C++ programsC++ programs
C++ programs
 
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
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
 
7segment scetch
7segment scetch7segment scetch
7segment scetch
 

Similar to 第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -

The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
The IOT Academy
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
Andrey Karpov
 
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + ProcessingRoberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Demetrio Siragusa
 
Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory Overflows
Ankur Tyagi
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
Tom Paulus
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
SIGMATAX1
 
Compilation of COSMO for GPU using LLVM
Compilation of COSMO for GPU using LLVMCompilation of COSMO for GPU using LLVM
Compilation of COSMO for GPU using LLVM
Linaro
 
Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6
scuhurricane
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part ii
Jonah Marrs
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
Jeni Shah
 
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Shinya Takamaeda-Y
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321Teddy Hsiung
 
Grand centraldispatch
Grand centraldispatchGrand centraldispatch
Grand centraldispatch
Yuumi Yoshida
 
Easy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and PythonEasy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and Python
Núria Vilanova
 
Arduino for Beginners
Arduino for BeginnersArduino for Beginners
Arduino for Beginners
Sarwan Singh
 
Home automation system
Home automation system Home automation system
Home automation system Hira Shaukat
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
Dr Karthikeyan Periasamy
 

Similar to 第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 - (20)

The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + ProcessingRoberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
 
Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory Overflows
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
Compilation of COSMO for GPU using LLVM
Compilation of COSMO for GPU using LLVMCompilation of COSMO for GPU using LLVM
Compilation of COSMO for GPU using LLVM
 
Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part ii
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
 
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
 
R tist
R tistR tist
R tist
 
informatics practices practical file
informatics practices practical fileinformatics practices practical file
informatics practices practical file
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
 
Grand centraldispatch
Grand centraldispatchGrand centraldispatch
Grand centraldispatch
 
Easy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and PythonEasy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and Python
 
Struct examples
Struct examplesStruct examples
Struct examples
 
Arduino for Beginners
Arduino for BeginnersArduino for Beginners
Arduino for Beginners
 
Home automation system
Home automation system Home automation system
Home automation system
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
 

Recently uploaded

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 

第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -

  • 2. FullColorLED ArduinoMicro 5V 10 (PWM) 11 (PWM) Common 9 (PWM) Red Green Blue OSTA71A1D-A Anode→ Cathode←150Ω 100Ω 100Ω Cathode← Cathode←
  • 3. Arduino sketch Set pin mode OUTPUT Declare LED pins Set LED color Red Set LED function 0 -> HIGH 255 -> LOW (Anode Common) const int ledPins[] = { 9, 10, 11 }; const int nLedPins = 3; void setup() { for( int i = 0; i < nLedPins; ++i ) { pinMode( ledPins[ i ], OUTPUT ); } setLed( 255, 0, 0 ); } void loop() { } void setLed( int _r, int _g, int _b ) { analogWrite( ledPins[ 0 ], 255 - _r ); analogWrite( ledPins[ 1 ], 255 - _g ); analogWrite( ledPins[ 2 ], 255 - _b ); }
  • 4. MPU-6050(GY-521) ( I2C Interface ) ArduinoMicro 5V GND 3 (SCL) 2 (SDA) VCC GND SCL SDA MPU-6050
  • 5. Arduino Library Download “i2cdevlib” from github.com/jrowberg/i2cdevlib into “書類 / Arduino / Libraries /” i2cdevlib / Arduino / I2Cdev and Copy Paste i2cdevlib / Arduino / MPU6050
  • 6. Example Arduino / Libraries / MPU6050 / Examples / MPU6050_raw / MPU6050_raw.ino raw データを取得する Example ここから不要な部分を削っていく。
  • 7. Arduino sketch MPU6050 object Include libraries Sensor values Initialize Set full scale accel range 16G Set full scale gyro range 2000dps Get acceleration values Get rotation values #include "I2Cdev.h" #include "MPU6050.h" #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif MPU6050 accelgyro; int16_t ax, ay, az; int16_t gx, gy, gz; int id = 0; void setup() { #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin(); #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup( 400, true ); #endif Serial1.begin( 9600 ); accelgyro.initialize(); accelgyro.setFullScaleAccelRange( MPU6050_ACCEL_FS_16 ); accelgyro.setFullScaleGyroRange( MPU6050_GYRO_FS_2000 ); } void loop() { accelgyro.getAcceleration( &ax, &ay, &az ); accelgyro.getRotation( &gx, &gy, &gz ); Serial1.print( id ); Serial1.print( "," ); Serial1.print( ax ); Serial1.print( "," ); Serial1.print( gz ); Serial1.println(); delay( 60 ); } ( ArduinoMicro + XBee + MPU-6050 )
  • 8. Arduino sketch int16_t = -32768 ~ 32767 accelgyro.initialize() accelgyro.setFullScaleAccelRange( MPU6050_ACCEL_FS_16 ) accelgyro.setFullScaleGyroRange( MPU6050_GYRO_FS_2000 ) signed 16bit この中で されている setFullScaleAccelRange( MPU6050_ACCEL_FS_2 ) setFullScaleGyroRange( MPU6050_GYRO_FS_250 ) ( ArduinoMicro + XBee + MPU-6050 ) 250dps 2000dps Accel 2G 16G Gyro
  • 9. Arduino sketch ( ArduinoMicro + XBee + MPU-6050 ) Address of “ax” Memory Address 0x00 ax &ax int16_t x int16_t* 0x01 0x02 0x03 0x04 ... “MPU6050.h” accelgyro.getAcceleration( &ax, &ay, &az ) void MPU6050::getAcceleration( int16_t* x, int16_t* y, int16_t* z ) Pointer of “int16_t” int16_t* x = &ax; assign address to pointer Memory Address 0x00 ax *x x int16_t x int16_t* 0x01 0x02 0x03 0x04 ... *x = -32768; ax = -32768; in automatically ax -32768
  • 10. Read Serial ( openFrameworks ) ofApp.h ofApp.cpp class ofApp : public ofBaseApp { public: ofSerial serial; string str; int index, ax, gz; }; void ofApp::setup() { index = ax = gz = 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() == 3 ) { index = ofToInt( valStr.at( 0 ) ); ax = abs( ofToInt( valStr.at( 1 ) ) ); gz = ofToInt( valStr.at( 2 ) ); } str = ""; } else { str.push_back( c ); } } }
  • 11. 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 ) ) ax = abs( ofToInt( valStr.at( 1 ) ) ) gz = ofToInt( valStr.at( 2 ) )
  • 12. Get values from string “0,-32768,32767” convert to int from string index = ofToInt( valStr.at( 0 ) ) ax = abs( ofToInt( valStr.at( 1 ) ) ) gz = ofToInt( valStr.at( 2 ) ) “0” “-32768” “32767” id string string ax gz string int vector< string > valStr = ofSplitString( str, "," ) -32768 ~ 32767 0 ~ 32768
  • 13. Draw with sensor value x = 0 ~ 32768 ( float )x / 32768 = 0.0 ~ 1.0 ( ( float )x / 32768 ) * ofGetWidth() = 0.0 ~ ofGetWidth() ( openFrameworks ) necessary to re-scale values ofApp.cpp void ofApp::draw() { ofSetColor( 0 ); ofFill(); ofRect( 0, 0, ( ( float )ax / 32768 ) * ofGetWidth(), 60 ); }