arduinoで磁気センサー

こちらの記事を参考に

http://d.hatena.ne.jp/ohguma/20111110

こちらを読む

https://www.loveelectronics.co.uk/Tutorials/8/hmc5883l-tutorial-and-arduino-library

ライブラリを以下からダウンロード。

Arduino Library for HMC5883L

https://www.loveelectronics.co.uk/Download/Arduino%20Library%20for%20HMC5883L/aHR0cDovL2M0ODc1My5yNTMuY2YzLnJhY2tjZG4uY29tL0xvdmVFbGVjdHJvbmljc19ITUM1ODgzTF9BcmR1aW5vTGlicmFyeS56aXA%3d#

ArduinoにEthernetシールドをつけて動かしてみる。

f:id:garyo:20130518235612j:plain

 

以下のソースでgoogleに接続できた。

>>

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>

byte mac = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
byte ip
= {192,168,11,10};
byte server = {74,125,235,216};

EthernetClient client;

void setup(){
  Ethernet.begin(mac,ip);
  Serial.begin(9600);
 
  delay(1000);
 
  Serial.println("Connecting...");
 
  if(client.connect(server,80)){
    Serial.println("connected");
    client.println("Get /serch?q=arduino HTTP/1.0");
    client.println();
  }else{
    Serial.println("connection failed");
  }
}

void loop(){
  if(client.available()){
    char c = client.read();
    Serial.print(c);
  }
  if(!client.connected()){
    Serial.println();
    Serial.println("disconnected");
    client.stop();
    for(;;)
      ;
  }

<<

 

以下シリアルの出力結果

f:id:garyo:20130518235653j:plain

>>

Connecting...
connected
HTTP/1.0 405 Method Not Allowed
Content-Type: text/html; charset=UTF-8
Content-Length: 963
Date: Sat, 18 May 2013 14:47:36 GMT
Server: GFE/2.0

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 405 (Method Not Allowed)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
  </style>
  <a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
  <p><b>405.</b> <ins>Thatâs an error.</ins>
  <p>The request method <code>Get</code> is inappropriate for the URL <code>/serch</code>.  <ins>Thatâs all we know.</ins>

disconnected
<<

 

 

 

サーバー機能も動かしてみた。問題なく動いた。

>>

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetServer.h>


byte mac = {0xDE,0xAD,0xBE,0xEF,0xED};
byte ip = {192,168,11,10};
byte gateway
= {192,168,1,1};
byte subnet[] = {255,255,255,0};

EthernetServer server = EthernetServer(23);

void setup(){
  Ethernet.begin(mac,ip,gateway,subnet);
  server.begin();
}

void loop(){
  EthernetClient client = server.available();
  if(client == true){
    server.write(toupper(client.read()));
  }
}

<<

AVRISP mkII とAVR StudioでATMEGA328P-PUにArduinoのブートローダーを書き込んでみる。

手順はこちらを参考にした。

http://30roses.blog.so-net.ne.jp/2013-01-18

書き込みケーブルの接続の向きは以下の動画を参照した。

http://www.youtube.com/watch?v=e2C5apH2mhc

 

 

書き込むファイルはこちら

>>

Arduinoの開発環境を展開したフォルダの
「\bootloaders\optiboot\optiboot_atmega328.hex」を指定してProgramします。

<<

フューズの設定は以下

>>

具体的には、Fuse RegisterのEXTENDEDを「0xFD」、HIGHを「0xD6」、LOWを「0xFF」とし、Programします。

<<

以下注意事項

>>

□Reset Disabled[RSTDISBL]
リセットピンを禁止して I/Oポートとして使う。これを設定すると ISPが実行できなくなる。
□Serial program Downloading (SPI) enabled [SPIEN=0]
ISP書き込みを禁止する。AVRISP mkIIでは通常は設定不可能になっている。
□Ext. 〜
外部クロック入力や水晶やセラミック発振子等を使う。実際の回路と異なっている場合は AVRが動作しなくなるので ISP書き込みもできなくなる。

<<

 

以下、フューズの設定

http://digilife.bz/wiki/index.php?Arduino%2FArduino%20UNO%E3%81%A8AVRISPmkII%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6ATmega328P-PU%E3%81%AB%E3%83%96%E3%83%BC%E3%83%88%E3%83%AD%E3%83%BC%E3%83%80%E3%82%92%E6%9B%B8%E3%81%8D%E8%BE%BC%E3%82%80

>>

ヒューズビットをArduino UNOに最初から付属していたATmega328Pに書きこまれていた「0xFD 0xD6 0xFF」に変更します。

<<

 

スケッチが書き込めました。

 

arduinoでサーボ モーターを動かしてみる

サーボモータの配線は以下を参照した。

http://tsuduki.com/rc_begin/colm/tasya.html

>>

JRのコネクターは線の色が独特です。茶色線が「-」赤色線が「+」オレンジ色の線が信号線になっています。
逆接続防止用のツメがありませんが、画像下側のオスコネクターはフタバコネクターの差し込み口にそのまま差すことができます。

<<

手持ちのサーボはJRコネクタータイプらしい。

配線とソースはこちらを参考にした。

http://kousaku-kousaku.blogspot.jp/2008/06/arduino.html

 

>>

#include <Servo.h>

const int SENSOR = 0;
int val = 0;

Servo servo;//サーボのインスタンス
void setup()
{
  Serial.begin(9600);
  servo.attach(3);
}

void loop()
{
  //センサの読み取り値
  int val=analogRead(0);
  //map()を使って0~1023のセンサ読取り値を0~180の角度に変換
  int deg=map(val,0,1023,0,180);
  //サーボ出力
  servo.write(deg);//0~180まで
}

<<

Arduino

Arduinoを自作するなら秋月の基板買って作るのが安そうです。

http://www.geocities.jp/arduino_diecimila/make/ae-atmega/

 基板ならこれが一番安いかな

http://eleshop.jp/shop/g/gD2P368/

 

 1500円のキット。ユニバーサルの部分付き。USBシリアル変換は別途用意。

http://eleshop.jp/shop/g/gD4D361/

 

sprintf使えるのか。便利だ。

http://garretlab.web.fc2.com/arduino/reverse_lookup/index.html

 

マイコンとクロック等追加すれば動きそうだ。

http://tyk-systems.com/ATmega328/ATmega328.html

Atmega328はBOOT書き込み済みのを用意すればいい。

http://eleshop.jp/shop/g/gBC511B/  

 

Arduinoのボードがあれば書き込めるみたいだけど。

http://arms22.blog91.fc2.com/blog-entry-286.html

 

Arduino Unoを単体で動かす回路の回路図

http://digilife.bz/wiki/index.php?Arduino%2FArduino%20UNO%E3%81%8B%E3%82%89ATmega328P-PU%E3%82%92%E5%A4%96%E3%81%97%E3%81%A6%E5%8D%98%E4%BD%93%E5%88%A9%E7%94%A8%E3%81%99%E3%82%8B