DigiMEsh DIOs, ADCs and PWMs example for mbed XBeeLib By Digi

Dependencies:   XBeeLib mbed

Fork of XBeeZB_dio_adc by Digi International Inc.

This example shows how to handle remote XBee modules DigitalInputOutputs, ADCs and PWMs. The example configures the remote XBee module pins to the desired functionality and then operates on those pins.

See Handling remote modules DIOs ADCs and PWMs chapter for more information.

Common Setup

Make sure you have a valid Example Common Setup

Example Setup

Application

You have to configure the remote device 64-bit address by customizing the REMOTE_NODE_ADDR64_MSB and REMOTE_NODE_ADDR64_LSB defines with the remote XBee module 64-bit address.

Hardware

On the Remote XBee module, wire following peripherals to the pins specified on the table and schematics or change the application pins according to your hardware setup:

LinePinValue
DIO2/ADC218ADC (Analog Input)
DIO3/ADC317Digital Input
RSSI/DIO106PWM (Analog Output)
DIO411Digital Output

/media/uploads/hbujanda/dio_adc_schem.png

Running the example

Build and deploy the example to the mbed module.
Reset the mbed module so the example starts. You should see the example debug information through the debug interface configured in the 'Local Setup' chapter.
The application will do following operations:

  • Configure the remote XBee module pins according to the table above.
  • Do following loop every 5 seconds:
    • Read DIO3_AD3 digital value
    • Toggle LED associated to DIO4_AD4
    • Read DIO2_AD2 analog value
    • Set the led associated to PWM0 to different intensity levels
Committer:
spastor
Date:
Tue May 05 18:29:40 2015 +0200
Revision:
1:adeb9c8818ab
Parent:
0:c87d86778f27
Child:
2:10c7e99a879e
Automatic upload

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hbujanda 0:c87d86778f27 1 /**
hbujanda 0:c87d86778f27 2 * Copyright (c) 2015 Digi International Inc.,
hbujanda 0:c87d86778f27 3 * All rights not expressly granted are reserved.
hbujanda 0:c87d86778f27 4 *
hbujanda 0:c87d86778f27 5 * This Source Code Form is subject to the terms of the Mozilla Public
hbujanda 0:c87d86778f27 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
hbujanda 0:c87d86778f27 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
hbujanda 0:c87d86778f27 8 *
hbujanda 0:c87d86778f27 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
hbujanda 0:c87d86778f27 10 * =======================================================================
hbujanda 0:c87d86778f27 11 */
hbujanda 0:c87d86778f27 12
hbujanda 0:c87d86778f27 13 #include "mbed.h"
hbujanda 0:c87d86778f27 14 #include "XBeeLib.h"
hbujanda 0:c87d86778f27 15 #if defined(ENABLE_LOGGING)
hbujanda 0:c87d86778f27 16 #include "DigiLoggerMbedSerial.h"
hbujanda 0:c87d86778f27 17 using namespace DigiLog;
hbujanda 0:c87d86778f27 18 #endif
hbujanda 0:c87d86778f27 19
hbujanda 0:c87d86778f27 20 // TODO Replace with the MSB of the remote module's 64-bit address (SH parameter)
hbujanda 0:c87d86778f27 21 #define REMOTE_NODE_ADDR64_MSB ((uint32_t)0x0013A200)
hbujanda 0:c87d86778f27 22 // TODO Replace with the LSB of the remote module's 64-bit address (SL parameter)
hbujanda 0:c87d86778f27 23 #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x40D2B03E)
hbujanda 0:c87d86778f27 24
hbujanda 0:c87d86778f27 25 using namespace XBeeLib;
hbujanda 0:c87d86778f27 26
hbujanda 0:c87d86778f27 27 Serial *log_serial;
hbujanda 0:c87d86778f27 28
hbujanda 0:c87d86778f27 29 int main()
hbujanda 0:c87d86778f27 30 {
hbujanda 0:c87d86778f27 31 log_serial = new Serial(DEBUG_TX, DEBUG_RX);
hbujanda 0:c87d86778f27 32 log_serial->baud(9600);
hbujanda 0:c87d86778f27 33 log_serial->printf("Sample application to demo how to handle remote XBeeZB devices DIOs and ADCs\r\n\r\n");
hbujanda 0:c87d86778f27 34 log_serial->printf(XB_LIB_BANNER);
hbujanda 0:c87d86778f27 35
hbujanda 0:c87d86778f27 36 #if defined(ENABLE_LOGGING)
hbujanda 0:c87d86778f27 37 new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
hbujanda 0:c87d86778f27 38 #endif
hbujanda 0:c87d86778f27 39
hbujanda 0:c87d86778f27 40 XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
hbujanda 0:c87d86778f27 41
hbujanda 0:c87d86778f27 42 RadioStatus radioStatus = xbee.init();
hbujanda 0:c87d86778f27 43 MBED_ASSERT(radioStatus == Success);
hbujanda 0:c87d86778f27 44
hbujanda 0:c87d86778f27 45 /* Wait until the device has joined the network */
hbujanda 0:c87d86778f27 46 log_serial->printf("Waiting for device to join the network: ");
hbujanda 0:c87d86778f27 47 while (!xbee.is_joined()) {
hbujanda 0:c87d86778f27 48 wait_ms(1000);
hbujanda 0:c87d86778f27 49 log_serial->printf(".");
hbujanda 0:c87d86778f27 50 }
hbujanda 0:c87d86778f27 51 log_serial->printf("OK\r\n");
hbujanda 0:c87d86778f27 52
hbujanda 0:c87d86778f27 53 const RemoteXBeeZB remoteDevice = RemoteXBeeZB(Addr64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB));
hbujanda 0:c87d86778f27 54
hbujanda 0:c87d86778f27 55 radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalInput);
hbujanda 0:c87d86778f27 56 MBED_ASSERT(radioStatus == Success);
hbujanda 0:c87d86778f27 57
spastor 1:adeb9c8818ab 58 radioStatus = xbee.set_pin_pull_up(remoteDevice, XBeeZB::DIO3_AD3, true);
spastor 1:adeb9c8818ab 59 MBED_ASSERT(radioStatus == Success);
spastor 1:adeb9c8818ab 60
hbujanda 0:c87d86778f27 61 radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutHigh);
hbujanda 0:c87d86778f27 62 MBED_ASSERT(radioStatus == Success);
hbujanda 0:c87d86778f27 63
hbujanda 0:c87d86778f27 64 radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO2_AD2, Adc);
hbujanda 0:c87d86778f27 65 MBED_ASSERT(radioStatus == Success);
hbujanda 0:c87d86778f27 66
hbujanda 0:c87d86778f27 67 //#define TEST_SUPPLY_VOLTAGE
hbujanda 0:c87d86778f27 68
hbujanda 0:c87d86778f27 69 #ifdef TEST_SUPPLY_VOLTAGE
hbujanda 0:c87d86778f27 70 /* Set a high V+ value so radio sends Supply Voltage information */
hbujanda 0:c87d86778f27 71 uint16_t v_value = 0x0C00;
hbujanda 0:c87d86778f27 72 log_serial->printf("\r\nSetting remote device V+ parameter to 0x%04x:\r\n", v_value);
hbujanda 0:c87d86778f27 73 AtCmdFrame::AtCmdResp cmdresp = xbee.set_param(remoteDevice, "V+", v_value);
hbujanda 0:c87d86778f27 74
hbujanda 0:c87d86778f27 75 if (cmdresp == AtCmdFrame::AtCmdRespOk)
hbujanda 0:c87d86778f27 76 log_serial->printf("OK\r\n");
hbujanda 0:c87d86778f27 77 else
hbujanda 0:c87d86778f27 78 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 0:c87d86778f27 79 #endif
hbujanda 0:c87d86778f27 80
hbujanda 0:c87d86778f27 81 while(true) {
hbujanda 0:c87d86778f27 82 /* Read DIO3_AD3 value */
hbujanda 0:c87d86778f27 83 DioVal dio3_val;
hbujanda 0:c87d86778f27 84 radioStatus = xbee.get_dio(remoteDevice, XBeeZB::DIO3_AD3, &dio3_val);
hbujanda 0:c87d86778f27 85 MBED_ASSERT(radioStatus == Success);
hbujanda 0:c87d86778f27 86 log_serial->printf("DIO3 value = %d\r\n", dio3_val);
hbujanda 0:c87d86778f27 87
hbujanda 0:c87d86778f27 88 /* Toggle XBIB board DS4 led */
hbujanda 0:c87d86778f27 89 static bool led_on = false;
hbujanda 0:c87d86778f27 90 if (!led_on)
hbujanda 0:c87d86778f27 91 radioStatus = xbee.set_dio(remoteDevice, XBeeZB::DIO4, Low);
hbujanda 0:c87d86778f27 92 else
hbujanda 0:c87d86778f27 93 radioStatus = xbee.set_dio(remoteDevice, XBeeZB::DIO4, High);
hbujanda 0:c87d86778f27 94 MBED_ASSERT(radioStatus == Success);
hbujanda 0:c87d86778f27 95 led_on = !led_on;
hbujanda 0:c87d86778f27 96
hbujanda 0:c87d86778f27 97 /* Read DIO2_AD2 analog value */
hbujanda 0:c87d86778f27 98 uint16_t adc2_val;
hbujanda 0:c87d86778f27 99 radioStatus = xbee.get_adc(remoteDevice, XBeeZB::DIO2_AD2, &adc2_val);
hbujanda 0:c87d86778f27 100 MBED_ASSERT(radioStatus == Success);
hbujanda 0:c87d86778f27 101 log_serial->printf("ADC2 value = 0x%04x\r\n", adc2_val);
hbujanda 0:c87d86778f27 102
hbujanda 0:c87d86778f27 103 #ifdef TEST_SUPPLY_VOLTAGE
hbujanda 0:c87d86778f27 104 uint16_t voltaje_val;
hbujanda 0:c87d86778f27 105 radioStatus = xbee.get_adc(remoteDevice, XBeeZB::SUPPLY_VOLTAGE, &voltaje_val);
hbujanda 0:c87d86778f27 106 if (radioStatus == Success)
hbujanda 0:c87d86778f27 107 log_serial->printf("Remote module Supply Voltage = 0x%04x\r\n", voltaje_val);
hbujanda 0:c87d86778f27 108 #endif
hbujanda 0:c87d86778f27 109
hbujanda 0:c87d86778f27 110 log_serial->printf("\r\n");
hbujanda 0:c87d86778f27 111
hbujanda 0:c87d86778f27 112 wait(5);
hbujanda 0:c87d86778f27 113 }
hbujanda 0:c87d86778f27 114
hbujanda 0:c87d86778f27 115 delete(log_serial);
hbujanda 0:c87d86778f27 116 }