DUE
概要 I2C接続の、温湿度センサ と大気圧センサ 、有機ELキャラクタディスプレイ を利用して、温度と湿度、大気圧を有機ELディスプレイに表示しました。事前に行った実験はそれぞれのページを参照してください。
作るもの 温度・湿度・大気圧を表示します。
用意するもの 以下のものを用意します。
Arduino Due
温湿度センサ(HDC1000利用温湿度センサモジュール)
大気圧センサ(LPS25H利用大気圧センサモジュール)
有機ELキャラクタディスプレイ(SO2002AWYB-UC-WB-U)
(PC)
(USBケーブル)
(ブレッドボード)
(ジャンプワイヤ)
大気圧センサと有機ELキャラクタディスプレイは5Vをかけると壊れる可能性が高いので注意してください(Arduino Dueは3.3Vで動作します)。
基本的な考え方 センサから値を取得して、キャラクタディスプレイに表示します。
状況把握 温度と湿度 HDC1000を利用して、1秒ごとに温度と湿度を計測します。
大気圧 LPS25Hを利用して、大気圧を計測します。このセンサは、温度も取得できますが、温度はHDC1000の値を利用しました。
処理決定 1秒ごとに温度と湿度、大気圧を取得して、10秒間の平均値を求めました。処理をさぼったので、最初の10秒間は低い値が出力されます。
機器操作 取得した値を、キャラクタディスプレイに表示します。
設計 ハードウェアの設計 今回利用するデバイスはすべてI2C接続のデバイスなので、基本的には、SCLとSDAを接続するだけです。今回利用した温湿度センサモジュールにはプルアップ抵抗が内蔵されているので、外部に抵抗を接続する必要もありません。
わかりづらいですが、接続イメージを以下に示します。I2C接続のデバイスばかりなので、Arduinoへの接続はデバイスの数と比べてとても少なくなっています。
プログラムの設計 それぞれのデバイスの実験をしたときに作成したプログラムをクラス化して、呼び出す形式としました。詳細は実験のページを参照してください。
あまり細かく設計していないので、気温がマイナスになったときとかは、表示が少しずれると思います。
動作している様子 上段に気温(T)と湿度(H)、下段に大気圧(P)を表示しています。
スケッチ デバイスクラスの中には、今回利用していないAPIも入っています。
thp.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "HDC1000Class.h"
#include "LPS25HClass.h"
#include "SO2002A_I2C.h"
#include "Wire.h"
#define HDC1000_RDY_PIN 19 /* Data Ready Pin */
#define LPS25H_ADDRESS 0x5c /* SA0 -> GND */
#define SO2002A_ADDRESS 0x3c /* SA0 -> GND */
#define SAMPLING_NUMBER 10
HDC1000Class hdc1000 ( HDC1000_RDY_PIN );
LPS25HClass lps25h ( LPS25H_ADDRESS );
SO2002A_I2C oled ( SO2002A_ADDRESS );
void setup () {
// put your setup code here, to run once:
Serial . begin ( 9600 );
hdc1000 . begin ();
lps25h . begin ();
oled . begin ( 20 , 2 );
}
void loop () {
// put your main code here, to run repeatedly:
char s [ 20 ];
int c = 0xdf ;
float temperature , humidity , pressure ;
float tAverage = 0 , hAverage = 0 , pAverage = 0 ;
static int num = 0 ;
static float tSample [ SAMPLING_NUMBER ], hSample [ SAMPLING_NUMBER ], pSample [ SAMPLING_NUMBER ];
hdc1000 . getTemeratureAndHumidity ( & temperature , & humidity );
pressure = lps25h . getPressure ();
tSample [ num ] = temperature ;
hSample [ num ] = humidity ;
pSample [ num ] = pressure ;
num ++ ;
if ( num == SAMPLING_NUMBER ) {
num = 0 ;
}
for ( int i = 0 ; i < SAMPLING_NUMBER ; i ++ ) {
tAverage += tSample [ i ];
hAverage += hSample [ i ];
pAverage += pSample [ i ];
}
tAverage /= SAMPLING_NUMBER ;
hAverage /= SAMPLING_NUMBER ;
pAverage /= SAMPLING_NUMBER ;
// First line
sprintf ( s , "T: %3.1f%cC, H: %2.1f%%" , tAverage , c , hAverage );
oled . setCursor ( 0 , 0 );
oled . print ( s );
// Second line
sprintf ( s , "P: %4.0fhPa" , pAverage );
oled . setCursor ( 0 , 1 );
oled . print ( s );
delay ( 1000 );
}
HDC1000Class.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef HDC1000_CLASS_H
#define HDC1000_CLASS_H
#define HDC1000_ADDRESS 0x40 /* or 0b1000000 */
#define HDC1000_TEMPERATURE_POINTER 0x00
#define HDC1000_HUMIDITY_POINTER 0x01
#define HDC1000_CONFIGURATION_POINTER 0x02
#define HDC1000_SERIAL_ID1_POINTER 0xfb
#define HDC1000_SERIAL_ID2_POINTER 0xfc
#define HDC1000_SERIAL_ID3_POINTER 0xfd
#define HDC1000_MANUFACTURER_ID_POINTER 0xfe
#define HDC1000_CONFIGURE_MSB 0x10 /* Get both temperature and humidity */
#define HDC1000_CONFIGURE_LSB 0x00 /* 14 bit resolution */
class HDC1000Class {
public :
HDC1000Class ( int rdyPin );
void begin ();
int getManufacturerId ();
void getTemeratureAndHumidity ( float * temperature , float * humidity );
private :
int useRdyPin ;
int rdyPin ;
};
#endif /* HDC1000_CLASS_H */
HDC1000Class.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "HDC1000Class.h"
#include "Arduino.h"
#include "Wire.h"
HDC1000Class :: HDC1000Class ( int rdyPin ) {
delay ( 15 );
if ( rdyPin < 0 ) {
useRdyPin = false ;
} else {
useRdyPin = true ;
this -> rdyPin = rdyPin ;
pinMode ( rdyPin , INPUT );
}
}
void HDC1000Class :: begin () {
Wire . begin ();
Wire . beginTransmission ( HDC1000_ADDRESS );
Wire . write ( HDC1000_CONFIGURATION_POINTER );
Wire . write ( HDC1000_CONFIGURE_MSB );
Wire . write ( HDC1000_CONFIGURE_LSB );
Wire . endTransmission ();
}
int HDC1000Class :: getManufacturerId () {
int manufacturerId ;
Wire . beginTransmission ( HDC1000_ADDRESS );
Wire . write ( HDC1000_MANUFACTURER_ID_POINTER );
Wire . endTransmission ();
Wire . requestFrom ( HDC1000_ADDRESS , 2 );
while ( Wire . available () < 2 ) {
;
}
manufacturerId = Wire . read () << 8 ;
manufacturerId |= Wire . read ();
return manufacturerId ;
}
void HDC1000Class :: getTemeratureAndHumidity ( float * temperature , float * humidity ) {
int tData , hData ;
Wire . beginTransmission ( HDC1000_ADDRESS );
Wire . write ( HDC1000_TEMPERATURE_POINTER );
Wire . endTransmission ();
if ( useRdyPin ) {
while ( digitalRead ( rdyPin ) == HIGH ) {
;
}
} else {
delay ( 15 );
}
Wire . requestFrom ( HDC1000_ADDRESS , 4 );
while ( Wire . available () < 4 ) {
;
}
tData = Wire . read () << 8 ;
tData |= Wire . read ();
hData = Wire . read () << 8 ;
hData |= Wire . read ();
* temperature = tData / 65536.0 * 165.0 - 40.0 ;
* humidity = hData / 65536.0 * 100.0 ;
}
LHS25HClass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef LPS25H_CLASS_H
#define LPS25H_CLASS_H
#define LPS25H_ADDRESS 0x5c /* SA0 -> GND */
#define LPS25H_WHO_AM_I 0x0f
#define LPS25H_CTRL_REG1 0x20
#define LPS25H_PRESS_OUT_XL 0x28
#define LPS25H_PRESS_OUT_L 0x29
#define LPS25H_PRESS_OUT_H 0x2a
#define LPS25H_TEMP_OUT_L 0x2b
#define LPS25H_TEMP_OUT_H 0x2c
class LPS25HClass {
public :
LPS25HClass ( int i2cAddress );
void begin ();
int whoAmI ();
float getPressure ();
float getTemperature ();
private :
int i2cAddress ;
};
#endif /* LPS25H_CLASS_H */
LHS25HClass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "LPS25HClass.h"
#include "Wire.h"
LPS25HClass :: LPS25HClass ( int i2cAddress ) {
this -> i2cAddress = i2cAddress ;
}
void LPS25HClass :: begin () {
Wire . begin ();
Wire . beginTransmission ( i2cAddress );
Wire . write ( LPS25H_CTRL_REG1 );
Wire . write ( 0x90 );
Wire . endTransmission ();
}
float LPS25HClass :: getPressure () {
long pData = 0 ;
for ( int i = 0 ; i < 3 ; i ++ ) {
Wire . beginTransmission ( i2cAddress );
Wire . write ( LPS25H_PRESS_OUT_XL + i );
Wire . endTransmission ();
Wire . requestFrom ( i2cAddress , 1 );
while ( Wire . available () < 1 ) {
;
}
pData |= Wire . read () << ( 8 * i );
}
return pData / 4096.0 ;
}
float LPS25HClass :: getTemperature () {
short tData = 0 ;
for ( int i = 0 ; i < 2 ; i ++ ) {
Wire . beginTransmission ( i2cAddress );
Wire . write ( LPS25H_TEMP_OUT_L + i );
Wire . endTransmission ();
Wire . requestFrom ( i2cAddress , 1 );
while ( Wire . available () < 1 ) {
;
}
tData |= Wire . read () << ( 8 * i );
}
return 42.5 + tData / 480.0 ;
}
SO2002A_I2C.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef SO2002A_I2C_H
#define SO2002A_I2C_H
#ifndef __SAM3X8E__
#error "Not Arduino Due"
#error "Remove this with care"
#endif
#include "Print.h"
/*
* Macros for users
*/
#define SO2002A_I2C_CHARACTER_ROM_A 0x00
#define SO2002A_I2C_CHARACTER_ROM_B 0x04
#define SO2002A_I2C_CHARACTER_ROM_C 0x08
#define SO2002A_I2C_DISABLE_FADE_OUT_AND_BLINKING 0b00000000
#define SO2002A_I2C_ENABLE_FADE_OUT_MODE 0b00100000
#define SO2002A_I2C_ENABLE_BLINKING_MODE 0b00110000
/*
* Macros for internal Use
*/
#define SO2002A_I2C_COMMAND_CLEAR_DISPLAY 0b00000001
#define SO2002A_I2C_COMMAND_RETURN_HOME 0b00000010
#define SO2002A_I2C_COMMAND_ENTRY_MODE_SET 0b00000100
#define SO2002A_I2C_COMMAND_DISPLAY_ON_OFF 0b00001000
#define SO2002A_I2C_COMMAND_CURSOR_OR_DISPLAY_SHIFT 0b00010000
#define SO2002A_I2C_COMMAND_FUNCTION_SET 0b00100000
#define SO2002A_I2C_COMMAND_SET_CGRAM_ADDRESS 0b01000000
#define SO2002A_I2C_COMMAND_SET_DDRAM_ADDRESS 0b10000000
#define SO2002A_I2C_COMMAND_SET_SCROLL_QUANTITY 0b10000000
#define SO2002A_I2C_COMMAND_SET_CONTRAST_CONTROL 0b10000001
#define SO2002A_I2C_COMMAND_SET_FADE_OUT_AND_BLINKING 0b00100011
#define SO2002A_I2C_COMMAND_FUNCTION_SELECTION_B 0b01110010
#define SO2002A_I2C_COMMAND_OLED_ENABLE_SD 0b01111001
#define SO2002A_I2C_COMMAND_OLED_DISABLE_SD 0b01111000
#define SO2002A_I2C_ENTRY_MODE_SHIFT_ON (~SO2002A_I2C_ENTRY_MODE_SHIFT_OFF)
#define SO2002A_I2C_ENTRY_MODE_SHIFT_OFF 0b00000001
#define SO2002A_I2C_ENTRY_MODE_DIRECTION_LEFT_TO_RIGHT 0b00000010
#define SO2002A_I2C_ENTRY_MODE_DIRECTION_RIGHT_TO_LEFT (~SO2002A_I2C_ENTRY_MODE_DIRECTION_LEFT_TO_RIGHT)
#define SO2002A_I2C_DISPLAY_MODE_BLINK_ON 0b00000001
#define SO2002A_I2C_DISPLAY_MODE_BLINK_OFF (~SO2002A_I2C_DISPLAY_MODE_BLINK_ON)
#define SO2002A_I2C_DISPLAY_CURSOR_ON 0b00000010
#define SO2002A_I2C_DISPLAY_CURSOR_OFF (~SO2002A_I2C_DISPLAY_CURSOR_ON)
#define SO2002A_I2C_DISPLAY_MODE_DISPLAY_ON 0b00000100
#define SO2002A_I2C_DISPLAY_MODE_DISPLAY_OFF (~SO2002A_I2C_DISPLAY_MODE_DISPLAY_ON)
#define SO2002A_I2C_FUNCTION_EXT_IS_ON 0b00000001
#define SO2002A_I2C_FUNCTION_EXT_IS_OFF (~SO2002A_I2C_FUNCTION_EXT_IS_ON)
#define SO2002A_I2C_FUNCTION_EXT_RE_ON 0b00000010
#define SO2002A_I2C_FUNCTION_EXT_RE_OFF (~SO2002A_I2C_FUNCTION_EXT_RE_ON)
#define SO2002A_I2C_FUNCTION_DOUBLE_HEIGHT_ON 0b00000100
#define SO2002A_I2C_FUNCTION_DOUBLE_HEIGHT_OFF (~SO2002A_I2C_FUNCTION_DOUBLE_HEIGHT_ON)
#define SO2002A_I2C_FUNCTION_2LINE_MODE_ON 0b00001000
#define SO2002A_I2C_FUNCTION_2LINE_MODE_OFF (~SO2002A_I2C_FUNCTION_2LINE_MODE_ON)
#define SO2002A_I2C_SCROLLQUANTITY_MASK 0b00111111
#define SO2002A_I2C_FADE_OUT_INTERVAL_MASK 0b00001111
#define SO2002A_I2C_SHIFT_CONTROL_ON 0b00001000
#define SO2002A_I2C_SHIFT_RIGHT 0b00000100
#define SO2002A_I2C_SHIFT_LEFT (~SO2002A_I2C_SHIFT_RIGHT)
#define SO2002A_I2C_COMMAND 0x00
#define SO2002A_I2C_DATA 0x40
class SO2002A_I2C : public Print {
public :
SO2002A_I2C ( uint8_t i2cAddress );
void begin ( uint8_t columns , uint8_t rows );
void clear ();
void home ();
void setCursor ( uint8_t x , uint8_t y );
void cursor ();
void noCursor ();
void blink ();
void noBlink ();
void display ();
void noDisplay ();
void scrollDisplayLeft ();
void scrollDisplayRight ();
void autoscroll ();
void noAutoscroll ();
void leftToRight ();
void rightToLeft ();
void createChar ( uint8_t location , uint8_t charmap []);
void singleHeightFont ();
void doubleHeightFont ();
void setScrollQuantity ( uint8_t dot );
void selectCharacterRom ( uint8_t font );
void setContrastControl ( uint8_t contrast );
void setFadeOutAndBlinking ( uint8_t mode , uint8_t interval );
virtual size_t write ( uint8_t );
using Print :: write ;
private :
uint8_t columns ; // width
uint8_t rows ; // height
uint8_t i2cAddress ; // I2C address
uint8_t entryMode ;
uint8_t displayMode ;
uint8_t functionMode ;
void setEntryMode ();
void setDisplayMode ();
void setFunctionMode ();
void setFunctionMode ( uint8_t mode );
void oledEnableSd ();
void oledDisableSd ();
void setCgramAddress ( uint8_t address );
void setDdramAddress ( uint8_t address );
uint8_t writeCommand ( uint8_t rs , uint8_t data );
};
#endif /* SO2002A_I2C_H */
SO2002A_I2C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include "SO2002A_I2C.h"
#include "Arduino.h"
#include "Wire.h"
SO2002A_I2C :: SO2002A_I2C ( uint8_t i2cAddress ) {
this -> i2cAddress = i2cAddress ;
}
// LiquidCrystal compatible functions
void SO2002A_I2C :: begin ( uint8_t columns , uint8_t rows ) {
this -> columns = columns ;
this -> rows = rows ;
entryMode = 0 b00000010 ;
displayMode = 0 b00000000 ;
functionMode = 0 b00000000 ;
Wire . begin ();
noDisplay ();
clear ();
display ();
setDisplayMode ();
setFunctionMode ();
}
void SO2002A_I2C :: clear () {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_CLEAR_DISPLAY );
delayMicroseconds ( 1520 );
}
void SO2002A_I2C :: home () {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_RETURN_HOME );
delayMicroseconds ( 1520 );
}
void SO2002A_I2C :: setCursor ( uint8_t col , uint8_t row ) {
int row_begin [] = { 0 , 32 };
setDdramAddress ( col + row_begin [ row ] );
}
void SO2002A_I2C :: cursor () {
displayMode |= SO2002A_I2C_DISPLAY_CURSOR_ON ;
setDisplayMode ();
}
void SO2002A_I2C :: noCursor () {
displayMode &= SO2002A_I2C_DISPLAY_CURSOR_OFF ;
setDisplayMode ();
}
void SO2002A_I2C :: blink () {
displayMode |= SO2002A_I2C_DISPLAY_MODE_BLINK_ON ;
setDisplayMode ();
}
void SO2002A_I2C :: noBlink () {
displayMode &= SO2002A_I2C_DISPLAY_MODE_BLINK_OFF ;
setDisplayMode ();
}
void SO2002A_I2C :: display () {
displayMode |= SO2002A_I2C_DISPLAY_MODE_DISPLAY_ON ;
setDisplayMode ();
}
void SO2002A_I2C :: noDisplay () {
displayMode &= SO2002A_I2C_DISPLAY_MODE_DISPLAY_OFF ;
setDisplayMode ();
}
void SO2002A_I2C :: scrollDisplayLeft () {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_CURSOR_OR_DISPLAY_SHIFT | SO2002A_I2C_SHIFT_CONTROL_ON & SO2002A_I2C_SHIFT_LEFT );
delayMicroseconds ( 37 );
}
void SO2002A_I2C :: scrollDisplayRight () {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_CURSOR_OR_DISPLAY_SHIFT | SO2002A_I2C_SHIFT_CONTROL_ON | SO2002A_I2C_SHIFT_RIGHT );
delayMicroseconds ( 37 );
}
void SO2002A_I2C :: autoscroll () {
entryMode |= SO2002A_I2C_ENTRY_MODE_SHIFT_OFF ;
setEntryMode ();
}
void SO2002A_I2C :: noAutoscroll () {
entryMode &= SO2002A_I2C_ENTRY_MODE_SHIFT_ON ;
setEntryMode ();
}
void SO2002A_I2C :: leftToRight () {
entryMode |= SO2002A_I2C_ENTRY_MODE_DIRECTION_LEFT_TO_RIGHT ;
setEntryMode ();
}
void SO2002A_I2C :: rightToLeft () {
entryMode &= SO2002A_I2C_ENTRY_MODE_DIRECTION_RIGHT_TO_LEFT ;
setEntryMode ();
}
void SO2002A_I2C :: createChar ( uint8_t location , uint8_t charmap []) {
location &= 0x7 ;
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_SET_CGRAM_ADDRESS | ( location << 3 ));
delayMicroseconds ( 37 );
for ( int i = 0 ; i < 8 ; i ++ ) {
writeCommand ( SO2002A_I2C_DATA , charmap [ i ]);
delayMicroseconds ( 37 );
}
}
// OLED original functions
void SO2002A_I2C :: singleHeightFont () {
functionMode &= SO2002A_I2C_FUNCTION_DOUBLE_HEIGHT_OFF ;
setFunctionMode ();
}
void SO2002A_I2C :: doubleHeightFont () {
functionMode |= SO2002A_I2C_FUNCTION_DOUBLE_HEIGHT_ON ;
setFunctionMode ();
}
void SO2002A_I2C :: setScrollQuantity ( uint8_t dot ) {
setFunctionMode ( functionMode | SO2002A_I2C_FUNCTION_EXT_RE_ON );
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_SET_SCROLL_QUANTITY | ( dot & SO2002A_I2C_SCROLLQUANTITY_MASK ));
delayMicroseconds ( 37 );
setFunctionMode ( functionMode & SO2002A_I2C_FUNCTION_EXT_RE_OFF );
}
void SO2002A_I2C :: selectCharacterRom ( uint8_t font ) {
setFunctionMode ( functionMode | SO2002A_I2C_FUNCTION_EXT_RE_ON );
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_FUNCTION_SELECTION_B );
writeCommand ( SO2002A_I2C_DATA , font );
delayMicroseconds ( 37 );
setFunctionMode ( functionMode & SO2002A_I2C_FUNCTION_EXT_RE_OFF );
clear ();
}
void SO2002A_I2C :: setContrastControl ( uint8_t contrast ) {
setFunctionMode ( functionMode | SO2002A_I2C_FUNCTION_EXT_RE_ON );
oledEnableSd ();
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_SET_CONTRAST_CONTROL );
writeCommand ( SO2002A_I2C_COMMAND , contrast );
delayMicroseconds ( 37 );
oledDisableSd ();
setFunctionMode ( functionMode & SO2002A_I2C_FUNCTION_EXT_RE_OFF );
}
void SO2002A_I2C :: setFadeOutAndBlinking ( uint8_t mode , uint8_t interval ) {
setFunctionMode ( functionMode | SO2002A_I2C_FUNCTION_EXT_RE_ON );
oledEnableSd ();
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_SET_FADE_OUT_AND_BLINKING );
writeCommand ( SO2002A_I2C_COMMAND , mode | ( interval & SO2002A_I2C_FADE_OUT_INTERVAL_MASK ));
delayMicroseconds ( 37 );
oledDisableSd ();
setFunctionMode ( functionMode & SO2002A_I2C_FUNCTION_EXT_RE_OFF );
}
size_t SO2002A_I2C :: write ( uint8_t value ) {
writeCommand ( SO2002A_I2C_DATA , value );
delayMicroseconds ( 37 );
return 1 ;
}
void SO2002A_I2C :: setEntryMode () {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_ENTRY_MODE_SET | entryMode );
delayMicroseconds ( 37 );
}
void SO2002A_I2C :: setDisplayMode () {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_DISPLAY_ON_OFF | displayMode );
delayMicroseconds ( 37 );
}
void SO2002A_I2C :: setFunctionMode () {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_FUNCTION_SET | functionMode );
delayMicroseconds ( 37 );
}
void SO2002A_I2C :: setFunctionMode ( uint8_t mode ) {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_FUNCTION_SET | mode );
delayMicroseconds ( 37 );
}
void SO2002A_I2C :: oledEnableSd () {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_OLED_ENABLE_SD );
}
void SO2002A_I2C :: oledDisableSd () {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_OLED_DISABLE_SD );
}
void SO2002A_I2C :: setCgramAddress ( uint8_t address ) {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_SET_CGRAM_ADDRESS | address );
delayMicroseconds ( 37 );
}
void SO2002A_I2C :: setDdramAddress ( uint8_t address ) {
writeCommand ( SO2002A_I2C_COMMAND , SO2002A_I2C_COMMAND_SET_DDRAM_ADDRESS | address );
delayMicroseconds ( 37 );
}
/*
* Low Level Control
*/
uint8_t SO2002A_I2C :: writeCommand ( uint8_t rs , uint8_t data ) {
Wire . beginTransmission ( i2cAddress );
Wire . write ( rs );
Wire . write ( data );
return Wire . endTransmission ();
}
バージョン
Hardware: Arduino Due Software: Arduino 1.6.0
最終更新日
January 23, 2021