Skip to content

Fujix1/longan_nano_i2c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Longan Nano 用 Wire ライブラリもどき(I2C 送信専用)

Longan Nano 用の Arduino Wire 風 I2C 送信専用ライブラリです。本家のように高機能ではないですが、「今すぐ I2C 機器を設定したい!」というようなときにどうぞ(いずれ読み込みも追加したい)。

なお、基本のコードは GD32VF103 Firmware Libraryを参考にしました。

This is a quasi Wire library to support I2C (send only) for Longan Nano.

使い方 USAGE

Arduino と同じです。Wire.h#include して、以下のように使用します。PB6 が SCL、PB7 が SDA です。

Same as Arduino, just include Wire.h and use as below. BE SURE TO CONNECT A PULLUP RESISTOR!

Wire.begin(); // 初期化
Wire.beginTransmission( 0x2F ); // 送信処理開始 引数 I2C アドレス(7ビット)
Wire.write(cnt); // データ送信キュー追加
Wire.endTransmission(); // 送信完了

注意: Arduino と違い、プルアップ抵抗が必要です。

サンプルファイルの説明

VSCode の PlatformIO 用のコード src/Blick.cpp では、I2C で設定を行う可変抵抗器 MCP4018T (秋月電子のページ)を制御しています。

92e5825ff9a8ca4d4d6d019f12e2cdcf

  • I2C アドレスは 0101111 固定
  • Vdd は 3.3V でも 5V でも動作
  • Vss は GND
  • I2C で 0 を送ると 2 - 5 ピン間が 0Ω、127 を送ると 10kΩ の 128 段階に設定

左上 LED の明るさが可変抵抗によって変わります。

IMG_6171

ロジアナで I2C の信号を確認したところ。

107867410_934892293589253_8121548138348444461_n

About

Limited I2C library for Longan Nano based on Wire.h

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages