MaruduinoでXBeeを使ってみる。主にIO Sampling。 [アプリケーション]
※スケッチを書き込む時はXBeeを外すか、接続を全て外してから行ってください。
※写真の様に2個のXBeeの内、一つはADC0を温度センサーであるLM61CIZに接続しています。この時温度センサー側のMaruduino自体は単にXBeeに電源を供給しているのみで、特にプログラムが走ってはいません。あくまでも温度センサー側のXBeeはスタンドアローンで動かしています。
MaruduinoのXBeeの横にあるCN20からはXBeeの幾つかの端子と、3.3V電源出力、GND、VREFが引き出せますので、ブレッドボードなどに回路を組んで実験を行うことができます。
XBeeと温度センサーとの接続および設定に関してはこのページを参考としてください。
http://hamayan.blog.so-net.ne.jp/2010-10-17-1
例によってxbee-arduinoライブラリのサンプルを元にアプリケーションを作成していますので、以下のページもご参照ください。
http://maruduino.blog.so-net.ne.jp/2011-01-05
http://maruduino.blog.so-net.ne.jp/2011-01-04
※写真の様に2個のXBeeの内、一つはADC0を温度センサーであるLM61CIZに接続しています。この時温度センサー側のMaruduino自体は単にXBeeに電源を供給しているのみで、特にプログラムが走ってはいません。あくまでも温度センサー側のXBeeはスタンドアローンで動かしています。
MaruduinoのXBeeの横にあるCN20からはXBeeの幾つかの端子と、3.3V電源出力、GND、VREFが引き出せますので、ブレッドボードなどに回路を組んで実験を行うことができます。
XBeeと温度センサーとの接続および設定に関してはこのページを参考としてください。
http://hamayan.blog.so-net.ne.jp/2010-10-17-1
例によってxbee-arduinoライブラリのサンプルを元にアプリケーションを作成していますので、以下のページもご参照ください。
http://maruduino.blog.so-net.ne.jp/2011-01-05
http://maruduino.blog.so-net.ne.jp/2011-01-04
/* LiquidCrystal Library - Hello World Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This sketch prints "Hello World!" to the LCD and shows the time. The circuit: * LCD RS pin to digital DI2 * LCD Enable pin to digital Di3 * LCD D4 pin to digital DI4 * LCD D5 pin to digital DI5 * LCD D6 pin to digital DI6 * LCD D7 pin to digital DI7 * LCD R/W pin to ground * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 by Tom Igoe modified 22 Nov 2010 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/LiquidCrystal */ /** * Copyright (c) 2009 Andrew Rapp. All rights reserved. * * This file is part of XBee-Arduino. * * XBee-Arduino is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * XBee-Arduino is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with XBee-Arduino. If not, see <http://www.gnu.org/licenses/>. */ // include the library code: #include <LiquidCrystal.h> #include <XBee.h> #include <stdlib.h> #include <string.h> /*************************************************************************/ /* defines */ /*************************************************************************/ #if 0 #define DI13 2 #define DI12 3 #define DI11 4 #define DI10 5 #define DI9 6 #define DI8 7 #define DI7 8 #define DI6 9 #define DI5 10 #define DI4 11 #define DI3 12 #define DI2 13 #define DI1 #define DI0 #else #define DI13 13 #define DI12 12 #define DI11 11 #define DI10 10 #define DI9 9 #define DI8 8 #define DI7 7 #define DI6 6 #define DI5 5 #define DI4 4 #define DI3 3 #define DI2 2 #define DI1 1 #define DI0 0 #endif // initialize the library with the numbers of the interface pins LiquidCrystal lcd(DI2, DI3, DI4, DI5, DI6, DI7); XBee xbee = XBee(); Rx16IoSampleResponse ioSample = Rx16IoSampleResponse(); void setup() { lcd.begin(16, 2); lcd.print("Xbee Test!"); xbee.begin(9600); } void loop() { xbee.readPacket(); if (xbee.getResponse().isAvailable()) { // got something if(xbee.getResponse().getApiId() == RX_16_IO_RESPONSE) { xbee.getResponse().getRx16IoSampleResponse(ioSample); lcd.clear(); lcd.print("src="); lcd.print(ioSample.getRemoteAddress16(), HEX); lcd.print(" size="); lcd.print(ioSample.getSampleSize(), DEC); unsigned long adc = 0; for(int i = 0; i < ioSample.getSampleSize(); i++) { adc += ioSample.getAnalog(0,i); } adc /= ioSample.getSampleSize(); lcd.setCursor(0, 1); float temper = ((adc * 3.3 / 1024) - 0.6) / 0.01; lcd.print("TEMP="); lcd.print(temper); } else { lcd.clear(); lcd.print("Expected I/O Sample,"); lcd.setCursor(0, 1); lcd.print("but got "); lcd.print(xbee.getResponse().getApiId(), HEX); } } else if(xbee.getResponse().isError()) { lcd.clear(); lcd.print("Error reading packet."); lcd.setCursor(0, 1); lcd.print("Error code:"); lcd.print(xbee.getResponse().getErrorCode(),HEX); } }
トランジスタ技術 (Transistor Gijutsu) 2010年 11月号 [雑誌]
- 作者:
- 出版社/メーカー: CQ出版
- 発売日: 2010/10/09
- メディア: 雑誌
2011-01-05 12:31
nice!(0)
コメント(0)
トラックバック(0)
コメント 0