M32W

From Wiki for Dragino Project
Revision as of 19:34, 30 April 2014 by Edwin1123 (Talk | contribs) (RDM8800 -------- 13.56MHz NFC RFID Reader)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

Wireless Internet of Things Module - M32W

Life was like a box of chocolates. You never know what you're gonna get. -- (Forrest Gump)


M32W wireless Internet of Things module is designed for the easy of programming and installation for IoT projects where wireless protocol (zigbee, bluetooth, 433Mhz etc) is required. It is a plug-in module for MS14 and powered by an ATMEL ATmega32u4 micro-controller.

The M32W has a standard XBEE Socket and RFM12B footprint to implement different wireless protocol modules. It also has a breadboard area for easy prototyping.

M32W is Arduino Yun compatible. It can be programmed and debug by the Arduino IDE(ver 1.5.4 or later) via WiFi.

With the combination of MS14, M32W and Arduino Yun software, user can install / prototype Internet of Things projects in an easy / rapidly way.

Features

  • Bridge various wireless protocols such as zigbee, bluetooth, NFC into WiFi IP network.
  • Internet of Things Gateway module to connect sensor network to internet.
  • Log sensor data and upload to remote server.
  • Control switch/relay from Internet.
  • Arduino IDE compatible, can be programmed /debug by Arduino IDE
  • Program/update/ debug via WiFi network.



Specification

Microcontroller ATmega32u4
Operating Voltage 3.3V
I/O voltage 3.3V
SRAM 2.5KB
Flash Memory 32KB(of which 4KB used by bootloader)
EEPROM 1KB
Clock Speed 16Mhz
Digital I/O pins 15
Analog input channels 6
PWM channels 4
BEE Socket 1
ESD-protection IEC 61000-4-2
Over Voltage Protect

Operation Voltage

M32W gets 3.3v power from MS14. All the I/O's of M32W is 3.3v level.

XBee Socket

Standard XBee Socket

M32W has a standard XBee Socket. any module compatible with this socket can be used directly in M32W.

RFM12B Footprint

RFM12B Footprint and i-pex socket

RFM12B footprint for HopeRF RFM12B module or RFM69CW/HCW 433/868/915 Radio module.

Prototype Area

Prototype Area

A on board prototype area with power and Arduino Pin out for easy prototyping.

Customized Screw Terminal

Screw Terminal feature is defined by user

While M32W is used with MS14-S, user can define the screw terminal feature by using the prototype area as shown above. Which gives more flexible/ possibility for prototyping.

USB Connector

USB Port of M32W, used for debug or program

M32W has a micro USB connector and can act as standard USB COM device. This USB connection can be used to upgrade sketch or debug the software via serial monitor on Arduino IDE.

Program / Upload sketch to M32W

Program via WiFi

M32W is running a sketch (program) inside which define how to communicate other wireless module or process the sensor data or send command to the actuator.

User can upload the sketch via Arudino IDE (use the version support Arduino Yun) to M32W ( installed in MS14).

Make sure your laptop and ms14 are in the same network. The ms14 will broadcast data in the network and the Arduino IDE will receive this data and show the ms14 in Tools --> Port.

Arduino Detect ms14 in the same network

Then choose the correct board type Arduino Yun for M32W IoT module.

M32W board type is Arduino Yun

After we have correctly configured board info as above, we can use the Arduino IDE to compile and upload the sketch to M32.

During upload, Arduino IDE will ask for a password. This is the password we have configured in the ms14 Web GUI, default password is arduino.

Compile and Upload sketch to M32W

Program via USB

M32W has a USB port which can be used for upload as well. Connect this port to PC and the M32W will be shown in Arduino IDE as a COM port in Tools --> Port. Select this COM port and user can program and upload sketch to M32W.



Playground

RDM6300 -------- 125Khz EM4100 RF Card Reader

Introduction

The M32W has a small prototype area can be used to quick prototype a RFID solution. This example shows how to use this prototype area to connect to the RDM6300 RFID card reader.

MS14 with RFID card reader



Wiring

The RDM6300 to M32W connection is as below:

RDM6300 M32W
+5V +5V
GND GND
RX D9
TX D10

Since the ANT pins is in the bottom side, we also lead it to the top via a 1x3 header. the finished photo likes below:

Wiring between M32W and RDM6300



Test RFID Reader: Echo Test Example Get Source

This sketch will use the Bridge Library of Arduino and require to set up the UART mode to Sensor --> Operation Mode to Arduino-Bridge. Then can programm m32w with below code and instructions to finish a simple card read test:

//This sketch shows how to use RFM6300 to read a EM4100 RFID card
//This test requires: 
// 1) ms14+m32w+ 125Khz EM4100 RF Reader (RDM6300)
// 
//How to test?
//1/ Connect the wires between m32w and RDM6300 according to (http://wiki.dragino.com/index.php?title=M32W#RDM6300_--------_125Khz_RF_Card_Reader) 
//2/ Upload this sketch to MS14 and open Serial Monitor
//3/ Then put a card close to the coil. The card ID will be read and shown in the Arduino Serial Monitor via WiFi.  
//
//2014-04-16 Dragino Technology Co., Limited 
 
#include <Console.h>
 
#include <SoftwareSerial.h>
#define rxPin 10  // RX Pin to RF reader socket
#define txPin 9   // TX Pin to RF reader
SoftwareSerial RF_Reader =  SoftwareSerial(rxPin, txPin);
int data = 0;
 
void setup(){
  //Initialize Console and wait for port to open:
  Bridge.begin();
  Console.begin(); 
  RF_Reader.begin(9600);
 
  while (!Console) {
    ; // wait for Console port to connect.
  } 
 
  // prints title with ending line break 
  Console.println("Waiting for RF Reader data");   
}
 
 
void loop(){
  if (RF_Reader.available() > 0){
   // read the incoming number on serial RX
    delay(100);  // Needed to allow time for the data to come in from the serial buffer.
    for (int z=0; z<14; z++) // read the rest of the tag
    {
      data=RF_Reader.read();
      Console.print(data,DEC); // print the data on Arduino Serial Monito
    }
    RF_Reader.flush(); // stops multiple reads  
    Console.println();
  }
}
Read RFID and shown in Arduino Serial Monitor



RDM8800 -------- 13.56MHz NFC RFID Reader

Introduction

The M32W has a small prototype area can be used to quick prototype a NFC RFID solution. This example shows how to use this prototype area to connect to the RDM8800 NFC RFID card reader.

MS14 with NFC RFID card reader



Wiring

The RDM8800 to M32W connection is as below:

RDM8800 M32W
+5V +5V
GND GND
RX D9
TX D10



Test RFID Reader: Echo Test Example Get Source

This sketch will use the Bridge Library of Arduino and require to set up the UART mode to Sensor --> Operation Mode to Arduino-Bridge. Then can programm m32w with the code and instructions to finish a simple card read test.

Read RFID and shown in Arduino Serial Monitor



RFM12B -------- 433/868/915 MHz Radio

Introduction

The M32W has RFM12B footprint at the bottom side of PCB. User can solder a RFM12B module to support 433/868/915 Mhz protocol. The RFM12B module is connected to mega32U4 via hardware SPI interface. The library used for the RFM12B is the Jeelabs RFM12B Library.

There are two antenna options for RFM12B module: 1) solder a wire to the ant hole on M32W or 2) solder the I-PEX/U.FL connector to use an external Antenna.

Install a RFM12B module


Pin Define

When use the Jeelabs RFM12B Library with RFM12B, modify the pin define for mega32u4 in arduino\libraries\jeelib\RF12.cpp to below define, the RF.

#elif defined(__AVR_ATmega32U4__) //Arduino Leonardo 

#define RFM_IRQ     3	    // PD0, INT0, Digital3
#define SS_DDR      DDRB
#define SS_PORT     PORTB
#define SS_BIT      0	    // PB0, pin 8, Digital17

#define SPI_SS      17    // PB0, pin 8, Digital17
#define SPI_MISO    14    // PB3, pin 11, Digital14
#define SPI_MOSI    16    // PB2, pin 10, Digital16
#define SPI_SCK     15    // PB1, pin 9, Digital15


Example: PingPong Demo Code Source Code

//This sketch is a PingPong test for the ms14+m32w+rfm12b (with Yun software)
//In this sketch, MS14 will keep sending data to 433Mhz network, 
//It will also receive data from 433Mhz wireless network sent by other devices, if the incoming data are in the same group, 
//it show be shown to the Arduino IDE serial monitor
//2014-02-21 Dragino Technology Co., Limited
 
// Demo of a sketch which sends and receives packets
// 2010-05-17 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php
// $Id: pingPong.pde 7763 2011-12-11 01:28:16Z jcw $
 
// with thanks to Peter G for creating a test sketch and pointing out the issue
// see http://news.jeelabs.org/2010/05/20/a-subtle-rf12-detail/
 
#include <Console.h>
#include <RF12.h> // Protocol library for RFM12B, include in Jeelibs library
#include <Ports.h> // Library to use MilliTimer, include in Jeelibs library
 
MilliTimer sendTimer;
 
//Payload going to be sent in 433Mhz network
char payload[] = "Hello!";
byte needToSend;
int led=13;  
 
static void sendLed (byte on) {
    digitalWrite(led,on);
}
 
static void receiveLed (byte on) {
    digitalWrite(led,on); 
}
 
void setup () {
 
  //Initialize Console and wait for port to open:
    Bridge.begin();
    Console.begin(); 
    pinMode(led,OUTPUT);
 
//RFM12B works only after Arduino IDE use serial monitor to connect to MS14-S.
//Comment the while loop if want the RFM12B works after MS14-S boot.
  while (!Console) {
    ; // wait for Console port to connect.
  }
   Console.println("Send and Receive");
 
//Initiate RFM12B module 
    rf12_initialize(1, RF12_433MHZ, 33);
}
 
void loop () {
// See if anydata receive, it yes, print in the console
  if (rf12_recvDone() && rf12_crc == 0) {
        receiveLed(1);
        Console.print("OK,We Received:   ");
        for (byte i = 0; i < rf12_len; ++i)
            Console.write(rf12_data[i]);
        Console.println();
        delay(100); // otherwise led blinking isn't visible
        receiveLed(0);
    }
 
    if (sendTimer.poll(3000))
        needToSend = 1;
 
// Send data to 433Mhz wireless network.         
    if (needToSend && rf12_canSend()) {
        needToSend = 0;
 
        sendLed(1);
        rf12_sendStart(0, payload, sizeof payload);
        delay(100); // otherwise led blinking isn't visible
        sendLed(0);
    }
}




XBee -------- 2.4G Zigbee Radio

Introduction

M32W with a XBee Pro Bee

The M32W has a standard XBee socket. User can plug in a XBEE module to communicate with 2.4G zigbee network

Configure XBee

User can program the Xbee from computer by X-CTU or by the MS14 itself by minicom.

To configure XBee module from MS14, we should do below things. Below first three settings can be done by select the Sensor --> Operation Mode to BEE Console and reboot the ms14.

  • Disable UART console
  • Disconnect UART to mega32U4 by setting GPIO24 to Low
  • Connect UART to XBee by setting GPIO27 to HIGH
  • make sure mega32u4's pin9 , pin10 are not in output mode. This can be done by put mega32u4 into reset state (GPIO20 to HIGH).


Then we can use minicom to configure the XBee. in SSH access, run minicom and configure minicom as:

  • Serial Device: /dev/ttyATH0
  • Bps/Par/Bits  : 9600 8N1
  • Hardware Flow Control : No
  • Software Flow Control : No
  • Add linefeed : ON
  • local Echo on/off : ON

In minicom, type +++ to enter XBee configure mode( don't press ENTER after type +++ ). Then the xbee module return OK and you can type the commands as decribed in XBee Commands. Below is a screen shot to show how to set the XBee ID. NOTE: XBee will exit configure mode if there is no input for several seconds.

Use minicom to configure XBee module


Reset XBee

Several methods to reset XBee, this will discard the current change after a ATWR command.

  • Push the BEE_RESET button
  • Set GPIO26 to HIGH
  • Reboot Device.



Test XBee: Echo Test Example Get Source

To use XBee with mega32U4, we first have to set up the UART mode to Sensor --> Operation Mode to Arduino-Bridge. Then can programm the XBee with below code and instructions to finish a simple echo test:

//This sketch is an echo test for the ms14+m32w+XBee
//This test use two XBee module, XBee-A is connected to PC and control by X-CTU tool. XBee-B is loaded in the m32w. 
//Both XBee are pre-configure to work at the same network. 
//User can put chareters in X-CTU so the chars will be sent from XBee-A to XBee-B then to m32w, m32w will return the same to XBee-A so to finished
//a simple echo test. 
//2014-03-13 Dragino Technology Co., Limited 
 
#include <SoftwareSerial.h>
#define rxPin 10  // RX Pin on the Xbee socket
#define txPin 9   // TX Pin on the Xbee socket
SoftwareSerial xbee =  SoftwareSerial(rxPin, txPin);
 
void setup(){
  xbee.begin(9600);
}
 
 
void loop(){
  if (xbee.available() > 0){
   xbee.write(xbee.read());
}
Echo Test Result shown in X-CTU




Bluetooth Bee -------- 2.4G Bluetooth V2.0

Introduction

M32W and a Bluetooth Bee

The M32W has a standard XBee socket. User can plug in the Bluetooth Bee HC-05/HC-06 to communicate with other bluetooth device

Configure Bluetooth Bee

User can program the Bluetooth Bee from computer or by the MS14 itself by minicom.

To configure Bluetooth Bee module from MS14, we should do below things: Below first three settings can be done by select the Sensor --> Operation Mode to Bee Console and reboot the ms14.

  • Disable UART console
  • Disconnect UART to mega32U4 by setting GPIO24 to Low
  • Connect UART to XBee by setting GPIO27 to HIGH
  • make sure mega32u4's pin9 , pin10 are not in output mode. This can be done by put mega32u4 into reset state (GPIO20 to HIGH).


Then we can use minicom to configure the XBee. in SSH access, run minicom and configure minicom as:

  • Serial Device: /dev/ttyATH0
  • Bps/Par/Bits  : 9600 8N1
  • Hardware Flow Control : No
  • Software Flow Control : No
  • local Echo on/off : ON

The AT Command Set of Bluetooth Bee HC-05 and HC-06 can be found from this link AT Command set

Below are the configure example from minicom. It sets the bluetooth name to Dragino and Password to 8888.

NOTICE: The bluetooth module require short interval (1s) between characters. So better use copy/paste method to send commands instead of typing manually.

Use Minicom to Configure Bluetooth Bee




Test Bluetooth Bee: Echo Test Example Get Source

To use Bluetooth Bee with mega32U4, we first have to set up the UART mode to Sensor --> Operation Mode to Arduino-Bridge. Then can programm the m32w with below code and instructions to finish a simple echo test:

//This sketch is an echo test for the ms14+m32w+ Bluetooth Bee HC-06
//This test also requires: 
// 1) ms14+m32w+ Bluetooth Bee HC-06
// 2) Android Phone with BlueTerm App installed (https://play.google.com/store/apps/details?id=es.pymasde.blueterm)
// 
//How to test?
//1/ Open BlueTerm in your Android phone and pair it with HC-06. 
//2/ Upload this sketch to MS14 and open Serial Monitor
//3/ In the BlueTerm console type a character and you will see the character is shown in the Arduino Serial Monitor. 
//The Android phone will get a "OK" string from HC-06 and shown in the console. 
//
//2014-04-16 Dragino Technology Co., Limited 
 
#include <Console.h>
 
#include <SoftwareSerial.h>
#define rxPin 10  // RX Pin on the Xbee socket
#define txPin 9   // TX Pin on the Xbee socket
SoftwareSerial bluetoothbee =  SoftwareSerial(rxPin, txPin);
 
void setup(){
  //Initialize Console and wait for port to open:
  Bridge.begin();
  Console.begin(); 
  bluetoothbee.begin(9600);
 
  while (!Console) {
    ; // wait for Console port to connect.
  } 
 
  // prints title with ending line break 
  Console.println("Waiting for bluetooth data");   
}
 
 
void loop(){
  if (bluetoothbee.available() > 0){
   char c = bluetoothbee.read();  // Get the Android data
   bluetoothbee.println("OK"); //Send back an OK to Android
   Console.println(c);  // Print this char to the Serial Monitor
  }
  delay(100);
}
Echo Test Example



nRF24L01+ -------- 2.4GHz RF ISM

Introduction

The M32W has a small prototype area which can be used to quick prototype a nRF24L01 to Internet gateway solution for IoT project. This example shows how to use this prototype area to connect to the nRF24L01+ module

MS14 with nRF24L01+



Wiring

The nRF24L01+ to M32W connection is as below:

nRF24L01+ M32W
VCC 3.3V
GND GND
CE D9
CSN D10
SCK SCK
MOSI MOSI
MISO MISO
Wire the nRF24L01+ to m32w



Ping Pong Test Example with nRF24L01+ Get Source

/**
* Example for Getting Started with nRF24L01+ radios. 
*
* This is an example of how to use the RF24 class.  Write this sketch to two 
* different nodes.  Put one of the nodes into 'transmit' mode by connecting 
* with the serial monitor and sending a 'T'.  The ping node sends the current 
* time to the pong node, which responds by sending the value back.  The ping 
* node can then see how long the whole cycle took.
*/

to run the example, user has to install the RF24 library to Arduino IDE first.

nRF24L01+ PingPong Test Example



Debug MCU code

M32W has two easy way to debug the MCU code.

Debug via Console Class(WiFi cnnnection)

The console class can be used to print out debug info to the Arduino IDE serial monitor. An example for how to use console class is under Arduino IDE --> Files --> Examples --> Bridge --> ConsoleAsciiTable.

Debug via Serial Class(USB Connection)

If M32W USB port is connected to PC. User can use serial class to debug the code as well. A example of how to use can see Arduino IDE --> Files --> Examples --> Bridge --> WiFiStatus

Source

Hardware Source V1.0

Datasheet