Pages: 1 [2]   Go Down
Author Topic: Data syncing  (Read 1933 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 3
Posts: 182
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a caution for those looking at using the PPS to sync remote data things, not all GPS modules or GPS shields provide PPS output so look at the docs carefully.  I am using Maestro GPS 1035 and 2035 modules about $20 and $18 from Mouser they work great and the price can't be beat.  The 1035 and 2035 are surface mount units and need to either go on a breakout board of a shield to use them with Arduinos, they skillet reflow very nicely but you will need to fab a board first.

wade
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It's even possible, however unlikely, that you are the one that made the mistake.

See post #10 in this thread.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Rx and TX pins on the XBee are 5V tolerant. Powering the XBee from 3.3V, and connecting it to 5V TX is fine.

Connecting 5V to other pins on the XBee is not, because only the RX and TX pins are 5V tolerant.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I'll bite. Show me on the documentation where it says 5V tolerant.

http://www.digi.com/products/wireless-wired-embedded-solutions/zigbee-rf-modules/point-multipoint-rfmodules/xbee-series1-module#docs

http://ftp1.digi.com/support/documentation/90000982_H.pdf
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The Rx and TX pins on the XBee are 5V tolerant. Powering the XBee from 3.3V, and connecting it to 5V TX is fine.

Connecting 5V to other pins on the XBee is not, because only the RX and TX pins are 5V tolerant.

Quote

Since you didn't answer the question, I will. The datasheets for series 1 and 2 XBee say nothing about
Din pins being 5V tolerant. These are the modules Faludi talks about in his book. Not only that, but the
very first schematic in Faludi's book, fig 1-10, is wrong. He has Rx and Tx wired backwards.

On some of the "newer" XBee modules, the Din pin is 5V tolerant. So we have a pretty poor situation
here, some are and some are not 5V tolerant. You have to be very careful what you're doing, how you're
hooking them up, and how you're mixing and matching.


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I got it.  I used some code from Principia Labs "MultiJoy" sketch to keep the wireless data organized.  He uses the term "error protection".   Anyway, if anyone cares here is the code I used:

Handheld:

Code:
//  Original code borrowed from "Blink without delay"
//  and "Multijoy" by Principia Labs



const int buttonPin = 2;     // the number of the pushbutton pin
const int LEDPin =  12;      // the number of the LED pin
int LEDButton = 9;           // LED on Pin 9 assigned to button
int LEDSync = 11;            // LED on Pin 11 assigned to button
int buttonState = 0;         // variable for reading the pushbutton status
int pinState = LOW;          // set initial state of pin
int t = 0;                   // switching variable


// Import the Arduino Servo library
#include <Servo.h>

// User input for servo and position
int userInput[3];    // raw input from serial buffer, 3 bytes
int startbyte;       // start byte, begin reading input
int servo;           // which servo to pulse?
int pos;             // servo angle 0-180
int i;               // iterator

void setup(){
 
  // Initialize outputs
  pinMode(LEDButton, OUTPUT);        //  set pin named "LEDButton" as output
  pinMode(LEDSync, OUTPUT);          
  pinMode(LEDPin, OUTPUT);      
  pinMode(buttonPin, INPUT);         //  set pin named "buttonPin" as input

buttonState = digitalRead(buttonPin);
  
    if (buttonState == HIGH) {
      if (t == 0) {
        Serial.print(char(255));        // error protection
        Serial.print(char(99));         // send command for "case 99"
        Serial.print(char(180));        // send state command
        digitalWrite(LEDPin, HIGH);
        t = 1;
      }
    }
    else {
      if (t == 1) {
        Serial.print(char(255));        // error protection
        Serial.print(char(99));         // send command for "case 99"
        Serial.print(char(0));          // send state command
        digitalWrite(LEDPin, LOW);
        t = 0;
    }
  }
}
  
  Serial.begin(9600); //set baud rate on Arduino to 9600
}

void loop(){

  // Wait for serial input (min 3 bytes in buffer)
  if (Serial.available() > 2) {
    // Read the first byte
    startbyte = Serial.read();
    // If it's really the startbyte (255) ...
    if (startbyte == 255) {
      // ... then get the next two bytes
      for (i=0;i<2;i++) {
        userInput[i] = Serial.read();
      }
      // First byte = servo to move?
      servo = userInput[0];
      // Second byte = which position?
      pos = userInput[1];
      // Packet error checking and recovery
      if (pos == 255) { servo = 255; }

      // Assign new position to appropriate servo
      switch (servo) {
      
        //  Upon receiving signal from the other units
        //  determine the case number and the condition
        //  and set the corresponding pinstate.
        
        case 98:
          if (pos == 180) {
            if (pinState == LOW)
                pinState = HIGH;
                }
            else pinState = LOW;  
            
          if (pos == 0) {
            pinState = LOW;
           }
          digitalWrite(LEDButton, pinState);
          break;
          
        case 97:
          if (pos == 180) {
            if (pinState == LOW)
                pinState = HIGH;
                }
            else pinState = LOW;  
            
          if (pos == 0) {
            pinState = LOW;
           }
          digitalWrite(LEDSync, pinState);
          break;
      }
    }
  }
  buttonState = digitalRead(buttonPin);
  
    if (buttonState == HIGH) {
      if (t == 0) {                         //  switching variable allows only one loop per state change                                            
        Serial.print(char(255));            //  error control
        Serial.print(char(99));             //  send command for "case 99"
        Serial.print(char(180));            //  send state command
        digitalWrite(LEDPin, HIGH);         //  turn the LED on
        t = 1;                              //  if buttonState HIGH and t = 0, do the above and change "t" to 1
      }
    }
    else {
      if (t == 1) {
        Serial.print(char(255));            // error protection
        Serial.print(char(99));             // send command for "case 99"
        Serial.print(char(0));              // send state command
        digitalWrite(LEDPin, LOW);          // turn the LED off
        t = 0;
    }
  }
}

The handheld transmits a signal to Logger 1 and also receives a signal from Logger 1 as confirmation that you are still in range.


« Last Edit: November 06, 2012, 11:55:15 am by tt_tony » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Transceiver Unit:

Code:
//  Original code borrowed from "Blink without delay"
//  and "Multijoy" by Principia Labs



int LEDButton = 9;              // Button LED on Pin 9 named LEDButton
const int LEDBlink =  11;       // the number of the sync LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the following variables are "long" because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 10000;          // Off time for Sync LED (milliseconds)
long interval2 = 500;           // On time for Sync LED (milliseconds)

// Import the Arduino Servo library
#include <Servo.h>

// User input for servo and position
int userInput[3];    // raw input from serial buffer, 3 bytes
int startbyte;       // start byte, begin reading input
int servo;           // which servo to pulse?
int pos;             // servo angle 0-180
int i;               // iterator


int pinState = LOW;  //Initial pinstate set

void setup()
{
   // LED on Pin 11 for digital on/off demo
  pinMode(LEDBlink, OUTPUT);

  // LED on Pin 9 for digital on/off demo
  pinMode(LEDButton, OUTPUT);

  // Open the serial connection, 9600 baud
  Serial.begin(9600);
}

void loop() {
  // Wait for serial input (min 3 bytes in buffer)
  if (Serial.available() > 2) {
    // Read the first byte
    startbyte = Serial.read();
    // If it's really the startbyte (255) ...
    if (startbyte == 255) {
      // ... then get the next two bytes
      for (i=0;i<2;i++) {
        userInput[i] = Serial.read();
      }
      // First byte = LED to control?
      servo = userInput[0];
      // Second byte = On or off?
      pos = userInput[1];
      // Packet error checking and recovery
      if (pos == 255) { servo = 255; }

      // Assign new position to appropriate servo (LED)
      switch (servo) {
       
        // LED on Pin 9 for digital on/off demo
        case 99:
          if (pos == 180) {     
            if (pinState == LOW)
                pinState = HIGH;
                Serial.print(char(255));        // error protection
                Serial.print(char(98));         // send command for "case 98"
                Serial.print(char(180));        // send state command
                }
            else {
              pinState = LOW;   
              Serial.print(char(255));        // error protection
              Serial.print(char(98));         // send command for "case 98"
              Serial.print(char(0));          // send state command
              }
          if (pos == 0) {
            pinState = LOW;
            Serial.print(char(255));        // error protection
            Serial.print(char(98));         // send command for "case 98"
            Serial.print(char(0));          // send state command
          }
          digitalWrite(LEDButton, pinState);
          break;
      }
    }
  } 
  unsigned long currentMillis = millis();    // "millis" is an internal timer that
                                             //  starts running on power up
 
  if(currentMillis - previousMillis > interval) {   
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW){
      ledState = HIGH;
      Serial.print(char(255));        // error protection
      Serial.print(char(97));         // send command for "case 97"
      Serial.print(char(180));        // send state command
    }   
    else {
      ledState = LOW;
      Serial.print(char(255));        // error protection
      Serial.print(char(97));         // send command for "case 97"
      Serial.print(char(0));          // send state command
    }
    // set the LED with the ledState of the variable:
    digitalWrite(LEDBlink, ledState);
   
  }
    else if(currentMillis - previousMillis > interval2) {
    // save the last time you blinked the LED
    if (ledState == HIGH){
      ledState = LOW;
      Serial.print(char(255));        // error protection
      Serial.print(char(97));         // send command for "case 97"
      Serial.print(char(0));          // send state command
    digitalWrite(LEDBlink, ledState);
    previousMillis = currentMillis;  }   
  }
}



This code receives the signal from the handheld and relays it to Transceiver 2.  It also sends a signal to the handheld as confirmation.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



Receiving Unit:

Code:
//  Original code borrowed from "Blink without delay"
//  and "Multijoy" by Principia Labs

// Import the Arduino Servo library
#include <Servo.h>

// User input for servo and position
int userInput[3];    // raw input from serial buffer, 3 bytes
int startbyte;       // start byte, begin reading input
int servo;           // which servo to pulse?
int pos;             // servo angle 0-180
int i;               // iterator

// LED on Pin 51 assigned to button
int LEDButton = 9;
int LEDSync = 11;
int pinState = LOW;

void setup()
{
  // LED on Pin 53 for digital on/off demo
  pinMode(LEDButton, OUTPUT);
  pinMode(LEDSync, OUTPUT);
  // Open the serial connection, 9600 baud
  Serial.begin(9600);
}

void loop() { // loop program
  // Wait for serial input (min 3 bytes in buffer)
  if (Serial.available() > 2) {
    // Read the first byte
    startbyte = Serial.read();
    // If it's really the startbyte (255) ...
    if (startbyte == 255) {
      // ... then get the next two bytes
      for (i=0;i<2;i++) {
        userInput[i] = Serial.read();
      }
      // First byte = servo to move?
      servo = userInput[0];
      // Second byte = which position?
      pos = userInput[1];
      // Packet error checking and recovery
      if (pos == 255) { servo = 255; }

      // Assign new position to appropriate servo
      switch (servo) {
       
        // LED on Pin 9 for digital on/off demo
        case 98:
          if (pos == 180) {
            if (pinState == LOW)
                pinState = HIGH;
                }
            else pinState = LOW;   
             
          if (pos == 0) {
            pinState = LOW;
           }
          digitalWrite(LEDButton, pinState);
          break;
         
        case 97:
          if (pos == 180) {
            if (pinState == LOW)
                pinState = HIGH;
                }
            else pinState = LOW;   
             
          if (pos == 0) {
            pinState = LOW;
           }
          digitalWrite(LEDSync, pinState);
          break;
      }
    }
  }
}

This code allows the second unit to receive the relayed signal from the first unit.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How do you have the 3 XBees configured? All in broadcast mode?
Logged

Pages: 1 [2]   Go Up
Jump to: