ArduinoUNOとMCP9701で温度を128x32 OLEDに出力 (Arduino)
9172 ワード
x あまり正確では、ない
x たまにOLEDのリセットに失敗する 全体の電源を数回入れ直す
x U8glibとU8g2があるから各自、確認の事
目的
秋月で売っている安価なMCP9701(約25円)を使って温度を出力する。
構成
MCP9701-E/TO I-03199
AL12832AWWB-H-U02 P-14686
説明
説明すると長くなるので「めんどい」ので各自勝手に調べて
ヒント MCP9701 AL12832AWWB
配線は、間違っているかもしれないので各自データシートで確認して
ヒント リセットは、10kΩ介して3.3V
ArduinoUNOと温度センサーMCP9701で温度をシリアル出力 (Arduino)
ARDUINO UNOとOLED、AL12832AWWB-H-U02でHello Worldを表示(U8g2lib)
#include <Arduino.h>
#include <U8x8lib.h>
//#ifdef U8X8_HAVE_HW_SPI
//#include <SPI.h>
//#endif
U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED
int cursor1; //カーソルの位置
char data_read[8]; //i2cバッファー
void i2c_oled_w(char *s)
{
//文字の表示
u8x8.drawString(
((cursor1-0) & 0x07 )*2, // x
(cursor1>>3)*2, // y
s);
while(s[0] != 0) {
s++;
cursor1++;
}
//cursor1=cursor1 + 3;
} //i2c_oled_w
//初期化
void setup(void) {
delay(2000); //oledのリセット時間
u8x8.begin();
u8x8.setFont(u8x8_font_px437wyse700a_2x2_r);
//スタートロゴ
cursor1 = 0;
i2c_oled_w("START");
delay(500);
//画面の初期化
u8x8.drawString( 0,0," ");
u8x8.drawString( 0,2," ");
cursor1 = 0;
} //setup
int s; //ADCの値
int n0; //温度 小数点以上
int nt[] = {0,2,5,7}; //温度
void loop(void) {
// //画面の初期化
// u8x8.drawString( 0,0," ");
// u8x8.drawString( 0,2," ");
//カーソルのクリア
cursor1 = 0;
//センサーの値を読み込む
s = analogRead(A0); // UNO
//s = (40<<2)+2; //debug
//小数点以上と小数点以下を分ける
n0 = (s >> 2) - 20; // 小数点以上
s = nt[s & 0x3]; // 小数点以下
//n0=20; //debug
//s = 3; //debug
//画面に表示
i2c_oled_w("TMP=");
data_read[0] = '0' + n0/10;;
data_read[1] = '0' + ( n0-( (n0/10) *10) );
data_read[2] = '.';
data_read[3] = '0' + s;
data_read[4] = 0;
i2c_oled_w(data_read);
//1秒待つ
delay(1000);
} //loop
Author And Source
この問題について(ArduinoUNOとMCP9701で温度を128x32 OLEDに出力 (Arduino)), 我々は、より多くの情報をここで見つけました https://qiita.com/caa45040/items/c17eb94921878edc47e8著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .