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?

More than 3 years have passed since last update.

DigisparkでAnalogRead~GP2Y0A21YKを使う2~P5を使う

Posted at

DigisparkでAnalogRead~GP2Y0A21YKを使う~の続きです。
https://qiita.com/usashirou/items/70ff2f869901fc159df6

互換DigiparkのP5はリセットになっている

互換DigiparkのP5ピンはリセットに割り当てられているため、入力で使用するとリセットされてしまうのでP5ピンを使えるようにしましょう。

Amazon で売ってる Digispark クローンの 5 ピンめを使えるようにしたメモ

https://qiita.com/illness072/items/3f5787c2ac4263283cbb
を参考に設定します。
まずは、ArduinoISPが使えるボードを用意します。

必要なもの

・ArduinoUnoなどのIPSが使えるボード
・ジャンパワイヤー6本

AVRdudeをインストールする

次に、PCのセッティングをします。
私は、Windows環境で行いました。
AVRdudeはWinAVRに入っているようです。
https://ja.osdn.net/projects/sfnet_winavr/releases/
image.png
image.png
image.png
image.png
image.png
image.png
20-7.jpg

動作確認

コマンドプロンプトでavrdudeと入力し以下の返答があればインストール完了です。
21-2.jpg

設定

Arduinoと以下の通り接続します。(もちろん電源も)
Arduino⇒Digispark
D10⇒P5
D11⇒P0
D12⇒P1
D13⇒P2
次に、コマンドプロンプトを立ち上げます。
**私はCOM26につながっています。

C:\Users\user>avrdude -P COM26 -b 19200 -c avrisp -p attiny85 -n
C:\Users\user>avrdude -P COM26 -b 19200 -p attiny85 -c avrisp  -U hfuse:w:0x5F:m

コマンドプロンプトの様子
22-2.jpg

2入力用プログラム

P2,P5のアナログ入力のプログラムを以下に示します。

# include <DigiUSB.h>

int adc1;
int adc2;
float dis1;
float dis2;

void setup()
{
  pinMode(2, INPUT);
  pinMode(5, INPUT);
  DigiUSB.begin();
}

void loop()
{
  adc1 = analogRead(1); //Read P2
  adc2 = analogRead(0); //Read P5
  dis1 = 6787.0/((float)adc1-3.0)-4.0;
  dis2 = 6787.0/((float)adc2-3.0)-4.0;

  DigiUSB.print("{\"Distance1\":");
  DigiUSB.print(dis1);
  DigiUSB.print("\"Distance2\":");
  DigiUSB.print(dis2);
  DigiUSB.println("}");
  DigiUSB.delay(1000);
}

問題なく、動作しました。
23-1.jpg

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?