0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AQM0802AをソフトウェアI2C(SoftWire.h)で遊ぶ(Arduino UNO)

Last updated at Posted at 2024-05-01

目的
ソフトウェアI2Cで遊ぶ。

結果

o_coq076.jpg

o_coq077.jpg

o_coq078.jpg

プログラム




//Soft_I2C_AQM0802A_DEMO1_UNO


#include <SoftWire.h>
#include <AsyncDelay.h>

#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL)
int sdaPin = PIN_WIRE_SDA;
int sclPin = PIN_WIRE_SCL;

#else
int sdaPin = SDA;
int sclPin = SCL;
#endif

SoftWire sw(sdaPin, sclPin);

// I2C address of AQM0802A
const uint8_t I2C_ADDRESS = 0x3E;

//i2cバッファー
char data_read[4];

//初期レジスター
char INIT_com[] = {
  0x0, 0x38, //1
  0x0, 0x39, //2
  0x0, 0x4,  //3
  0x0, 0x14, //4
  0x0, 0x70, //5
  0x0, 0x56, //6
  0x0, 0x6C, //7
  0x0, 0x38, //8
  0x0, 0xC   //9
};

//画面のクリアレジスター
char INIT_cls[] = {0x0, 0x1};


//i2c書き込みルーチン
void i2c_lcd_w(char *buff1) {

  // Ensure register address is valid
  sw.beginTransmission(I2C_ADDRESS);
  sw.write((uint8_t)buff1[0] ); // Access the first register
  sw.write((uint8_t)buff1[1] ); // Access the first register
  sw.endTransmission();
  delay(2);
  
}//i2c_lcd_w


void ns_putc(char ch)
{

  data_read[0] = '@';
  data_read[1] = ch;

  //I2Cに送信
  i2c_lcd_w(data_read);

}//ns_putc


void ns_puts(const char *str1)
{

  //文字の中身がゼロか
  while (*str1) {

    //一文字出力
    ns_putc(*str1 ++);

  }//while

}//ns_puts


//カーソルの移動
void setCursor(int col, int rows)
{

  data_read[0] = 0x0;
  data_read[1] = 0x80 +  (rows * 0x40) + col ; //カーソルを移動

  //I2Cに送信
  i2c_lcd_w(data_read);

}//setCursor


char swTxBuffer[16];
char swRxBuffer[16];

//初期化関数
void setup()
{

  //I2Cの初期化
  Serial.begin(115200);
  Serial.print("    SDA pin: ");
  Serial.println(int(sdaPin));
  Serial.print("    SCL pin: ");
  Serial.println(int(sclPin));
  Serial.print("    I2C address: ");
  Serial.println(int(I2C_ADDRESS), HEX);
  sw.setTxBuffer(swTxBuffer, sizeof(swTxBuffer));
  sw.setRxBuffer(swRxBuffer, sizeof(swRxBuffer));
  sw.setDelay_us(5);
  sw.setTimeout(1000);
  sw.begin();

  //液晶の初期化
  for (int ii = 0; ii < 9; ii++) {
    i2c_lcd_w(&INIT_com[ii << 1]);  // ii << 1 = ii * 2
  }//for

  //画面のクリア
  i2c_lcd_w(INIT_cls);

  //表示
  setCursor(0, 0); ns_puts("HELLO");
  setCursor(0, 1); ns_puts("WORLD");

}//setup


//メインループ
void loop()
{}//loop



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?