Shop OBEX P1 Docs P2 Docs Learn Events
Hello, any chance of data logging through XBEE? — Parallax Forums

Hello, any chance of data logging through XBEE?

hans90hans90 Posts: 29
edited 2017-04-03 05:00 in Propeller 1
Hi there, I am recently into learning data logging through XBEE to host PC. With the help of XBEE demo and wonderful tips from prop forum masters learn.parallax.com/tutorials/projects/xbee-802154-pc-demo/xbee-and-usb-connections, I was able to incorporate the Boe Bot code to my Activity Bot (ABot) and display on data loggings PST by using XBees. However my goal is to data log Temperature, Light level and Distance into Text file on PC through XBee. (BTW I have successfully tried a project to save data loggings into SD card and then export it to Excel file on PC)

So now how can I create a Text file and data logging onto my PC in real time by using XBee?
''***************************************
''*  XBee 802.15.4 to PC Demo V1.0      *
''*  Author: Chris Savage               *
''*  Copyright (c) 2014 Parallax, Inc.  *               
''*  See end of file for terms of use.  *               
''***************************************


CON

  _clkmode = xtal1 + pll16x                             ' Standard Crystal, 16x Multiplier
  _xinfreq = 5_000_000                                  ' 5MHz Crystal
                                                         
  CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq       ' ADC124S module timming cons
  MS_001   = CLK_FREQ / 1_000
  US_001   = CLK_FREQ / 1_000_000                                                       


CON

  DEBUG      = 0                                        ' Parallax Serial Terminal Module
  A_PORT     = 1                                        ' XBee Module

 'A_RESET    = 0                                        ' To RST pin on XBee Module/Adapter (Not Used)
  A_TX       = 1                                        ' To DI pin on XBee Module/Adapter
  A_RX       = 2                                        ' To DO pin on XBee Module/Adapter
                                                        ' 
  RX1     = 31                                          ' ADS124S programming / terminal
  TX1     = 30 
  
  SDA     = 29                                          ' ADS124S eeprom / i2c
  SCL     = 28 

  BAUD       = 9600                                     ' Baud Rate 9600 bps


CON
                                                       
  ADC_CS  = 21                                          ' ADC124S021 connections
  ADC_SCL = 20 
  ADC_DO  = 19 
  ADC_DI  = 18                                                        
                                                          
                                                          
  LED_BLUE   = 5                                        ' To Blue LED (B1)
  LED_GREEN  = 4                                        ' To Green LED (G1)
  LED_RED    = 3                                         ' To Red LED (R1)
  DS1620_RST = 8                                        ' To DS1620 RST pin (3)
  DS1620_CLK = 9                                        ' To DS1620 CLK pin (2)
  DS1620_DAT = 10                                        ' To DS1620 DAT pin (1)
  RLY_PIN    = 17                                        ' To servo header pin (17)
  PING_PIN   = 0                                         ' To PING pin (0)
  SVO_PIN    = 16                                        ' To servo header pin (16)

  CR         = 13                                        ' Carriage Return
  SP         = 32                                        ' Space Character
  HOME    =  1
  GOTOXY  =  2
  CRSR_LF =  3
  CRSR_RT =  4
  CRSR_UP =  5
  CRSR_DN =  6
  BELL    =  7
  BKSP    =  8
  TAB     =  9
  LF      = 10
  CLREOL  = 11
  CLRDN   = 12
  GOTOX   = 14
  GOTOY   = 15
  CLS     = 16                                                         
                                                         


CON

  _dopin     = 22                                       ' DO pin on microSD
  _clkpin    = 23                                       ' CLK pin on microSD
  _dipin     = 24                                       ' DI pin on microSD
  _cspin     = 25                                       ' CS pin on microSD
  _cdpin     = -1                                       ' -1 if unused.
  _wppin     = -1                                       ' -1 if unused.

  _rtcres1   = -1                                       ' -1 always.
  _rtcres2   = -1                                       ' -1 always.
  _rtcres3   = -1                                       ' -1 always.

  _lpin      = 26                                       ' -1 if unused.
  _rpin      = 27                                       ' -1 if unused.

  _volume    = 3                                        ' Default volume.

  _ditherEnable = true                                  ' "true" or "false" please.
  _ditherLevel = 4                                      ' 0 = Most Dither ... 31 = Least Dither.

  
VAR

  long stack[40], spinPlayerStack[100], flasherStack[20] ' stack[40] is the 40 long of stack spaces reserved for Telemetry method

  
OBJ

  fds   : "FullDuplexSerial4port"
  dio   : "dataIO4port"
  servo : "Servo32v7"
  ping  : "Ping"
  temp  : "DS1620"
  adc   : "jm_adc124s021"    
  dac   : "WAV-Player_DACEngine.spin"


PUB Main | value, index, char, t, ch, counts, volts

  dira[LED_BLUE..LED_RED]~~                             ' Set LED pins to output
  dira[RLY_PIN]~~                                       ' Set Relay pin to output

  fds.Init
  fds.AddPort(A_PORT, A_RX, A_TX, -1, -1, 0, %000000, BAUD) ' XBee Module defined to transmit to PC
  fds.AddPort(DEBUG, 31, 30, -1, -1, 0, %000000, BAUD)  ' Debug Module defined to serial terminal PST, NOT USED HERE!
  fds.Start                                             ' Start the XBee and Debug ports

  servo.Start                                           ' Start Servo object

  Pause(100)                                            ' UART startup delay

  servo.Set(SVO_PIN, 1375)                              ' Pre-set servo position (center)

  dac.FATEngineStart(_dopin, _clkpin, _dipin, _cspin, _wppin, _cdpin, _rtcres1, _rtcres2, _rtcres3)
  dac.DACEngineStart(constant(_lpin | (not(not(_ditherEnable)))), constant(_rpin | (not(not(_ditherEnable)))), _volume)

  ' Above Never fail - no need to check return value.    
  
  if(_ditherEnable)
    dac.DACDitherEngineStart(_lpin, _rpin, _ditherLevel)' Never fails - no need to check return value.
  
  cognew(Telemetry, @stack)                             ' launch a NEW COG to run telemetry method with reserved stack[40] space for telemetry

  repeat
    char := fds.rx(A_PORT)                              ' Get command
    if char == "!"                                      ' Parse the preamble character, get first symbol command header
      char := fds.rx(A_PORT)
      if char == "c"                                    ' get first char: c, s, i
        char := fds.rx(A_PORT)
        if char == "l"
          char := fds.rx(A_PORT)
          if char == "r"
            clr                                         ' Clear the terminal screen
      if char == "s"                                    ' get second char: c, s, i
        char := fds.rx(A_PORT)
        if char == "v"
          char := fds.rx(A_PORT)
          if char == "o"
            char := fds.rx(A_PORT)
            if char == "1"
              servo.Set(SVO_PIN, 500)                   ' Position servo 90 degrees right
            if char == "2"
              servo.Set(SVO_PIN, 1375)                  ' Position servo center
            if char == "3"
              servo.Set(SVO_PIN, 2250)                  ' Position servo 90 degrees left
        if char == "n"
          char := fds.rx(A_PORT)
          if char == "d"
            char := fds.rx(A_PORT)
            if char == "1"
              dac.playWAVFile(string("1.wav"))          ' Play WAV file
            if char == "2"
              dac.playWAVFile(string("2.wav"))
            if char == "3"
              dac.playWAVFile(string("3.wav"))
            if char == "4"
              dac.playWAVFile(string("4.wav"))
            if char == "5"
              dac.playWAVFile(string("5.wav"))
            if char == "6"
              dac.playWAVFile(string("6.wav"))
            if char == "7"
              dac.playWAVFile(string("7.wav"))
            if char == "8"
              dac.playWAVFile(string("8.wav"))
            if char == "9"
              dac.playWAVFile(string("9.wav"))
            if char == "0"
              dac.playWAVFile(string("0.wav"))
      if char == "i"                                    ' get second char: c, s, i
        char := fds.rx(A_PORT)
        if char == "n"
          char := fds.rx(A_PORT)
          if char == "r"
            char := fds.rx(A_PORT)
            if char == "0"                              ' Red LED off
              outa[LED_RED]~
            if char == "1"                              ' Red LED on
              outa[LED_RED]~~
          if char == "g"
            char := fds.rx(A_PORT)
            if char == "0"                              ' Green LED off
              outa[LED_GREEN]~
            if char == "1"                              ' Green LED on
              outa[LED_GREEN]~~
          if char == "b"
            char := fds.rx(A_PORT)
            if char == "0"                              ' Blue LED off
              outa[LED_BLUE]~
            if char == "1"                              ' Blue LED on
              outa[LED_BLUE]~~


PUB clr

  fds.tx(A_PORT, 0)                                     ' Clear Screen
  
  
PUB Telemetry | tF, value, range, t, ch, counts, volts

  temp.start(DS1620_DAT, DS1620_CLK, DS1620_RST)        ' Start DS1620 object                                                       
  adc.start(ADC_CS, ADC_SCL, ADC_DI, ADC_DO)            ' Start ADC124S object                                                                                                                                                                                                                       
  t := cnt
  ch := 0                                               ' channel A/D 0 is selected                                                      

  repeat
    tF := temp.gettempf                                 ' Get F Temp from DS1620
    fds.tx(A_PORT, 1)                                   ' Clear Screen HOME
    fds.str(A_PORT, string("Temperature ="))            ' print (Temp in °F)
    dio.decf(A_PORT, tf / 10, 3)                        ' Whole number portion
    fds.tx(A_PORT, ".")                                 ' Decimal Point
    dio.dec(A_PORT, tf // 10)                           ' Tenths of Degrees
    fds.str(A_PORT, string("° F  "))                    ' print °F
    fds.tx(A_PORT, 13)                                  ' Carriage Return
                                                         
    counts := adc.read(ch)                              ' read counts from ADC124         
    fds.str(A_PORT, string("Light Level = "))           ' Label (Light Level)  
    dio.dec(A_PORT, counts)                             ' Display raw value
    fds.str(A_PORT, string("/4095  ", 13))                                                     

    range := ping.Inches(PING_PIN)                      ' Get Inches from PING))) sensor
    fds.str(A_PORT, string("Distance    = "))           ' Label (Distance)
    dio.dec(A_PORT, range)                              ' Display Range in Inches
    fds.str(A_PORT, string(" Inches  "))
    fds.tx(A_PORT, 13)                                  ' Carriage Return

    Pause(1000)                                         ' One second (1000 mS) delay
                                                                                                          

PRI Pause(ms)

  waitcnt(clkfreq / 1000 * ms + cnt)                    ' Convert to mS


DAT
     {<end of object code>}
     
{{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                   TERMS OF USE: MIT License                                                  │                                                            
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    │ 
│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    │
│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
│is furnished to do so, subject to the following conditions:                                                                   │
│                                                                                                                              │
│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
│                                                                                                                              │
│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          │
│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         │
│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   │
│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
}}
Sign In or Register to comment.