Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Fio constantly resets on: November 26, 2012, 03:28:46 am
I seem to have it working.  Thanks, dc42.

Code:
// twowaytest.ino
// testing 2-way communications with the Fio

// XBee settings (use X-TCU)
// XBee 1:
// PAN ID: 1111
// DH: 0
// DL: 12
// MY: 11 (radio 17)
//
// XBee 2:
// PAN ID: 1111
// DH: 0
// DL: 11
// MY: 12 (radio 18)

int buttonPin = 2; // button with 10k to gnd
int localHbLed = 13; // LED to gnd
int remoteHbLed = 12; // LED to gnd

int index = 0;
int buttonState = 0;
int lastState = 0;

const int terminatingChar = 13; // Terminate lines with CR


// ---------------------------------------------
void setup(){

  pinMode(localHbLed,OUTPUT);   
  pinMode(remoteHbLed,OUTPUT);
  pinMode(buttonPin, INPUT); 

  Serial.begin(57600);
  Serial.print(255); 
  analogReference(EXTERNAL); // set up for 3.3v usage

  delay(2000);
  blink(3); // show we're on...
}

// ---------------------------------------------
void loop(){

  buttonState = digitalRead(buttonPin);

  if (lastState != buttonState) {
    if (buttonState == HIGH) {     
      // turn LED on:   
      digitalWrite(localHbLed, HIGH);
      sendDataToOther("pulseUp");
      lastState = HIGH;
    }

    if (buttonState == LOW) {
      // turn LED off:
      digitalWrite(localHbLed, LOW);
      sendDataToOther("pulseDn");
      lastState = LOW;
    }
  }

  getDataFromOther();
  delay(50);    //  take a break
}


// ---------------------------------------------
void sendDataToOther(String pulseVal){
  // send info to the other xbee
  if (pulseVal == "pulseUp"){
    Serial.print("pulseUp\r");
  }
  else {
    Serial.print("pulseDn\r");
  }
}


// ---------------------------------------------
void getDataFromOther() {

  char* theOtherPulse = serialReader();

  if (strcmp(theOtherPulse, "pulseUp") == 0) {
    digitalWrite(remoteHbLed,HIGH);
    Serial.println("recd... HIGH ");
  }

  if (strcmp(theOtherPulse, "pulseDn") == 0) {
    digitalWrite(remoteHbLed,LOW);
    Serial.println("recd... LOW ");
  }
}


// ---------------------------------------------
// read serial port
char* serialReader(){
  static char serialReadString[50] = "";
  index=0;
  int inByte = Serial.read();

  if (inByte > 0 && inByte != terminatingChar) {
    delay(50); //Allow serial data time to collect

    while (Serial.available() > 0 && inByte != terminatingChar && index <= 49) {
      serialReadString[index] = inByte; // Save the data in a character array
      index++; // increment position in array
      inByte = Serial.read(); // Read next byte
    }

    if (index >= 49){
      return "b"; // return this when the buffer is full...
    }

    // If we terminated properly
    if (inByte == terminatingChar) {
      serialReadString[index] = 0; //Null terminate the serialReadString (Overwrites last position char (terminating char) with 0
      return serialReadString;
    }
  }
  return "n"; // return this when nothing is received...
}


// ---------------------------------------------
// convert string to int
int stringToInt(String thisString) {
  int i, value, length;
  length = thisString.length();
  char blah[(length+1)];
  for(i=0; i<length; i++) {
    blah[i] = thisString.charAt(i);
  }
  blah[i]=0;
  value = atoi(blah);
  return value;
}

// ---------------------------------------------
// blink n times
void blink(int howManyTimes){
  digitalWrite(localHbLed, LOW);
  digitalWrite(remoteHbLed, LOW);
  delay(200);
  for (int i=0; i< howManyTimes; i++){
    digitalWrite(localHbLed, HIGH);
    digitalWrite(remoteHbLed, LOW);
    delay(200);
    digitalWrite(localHbLed, LOW);
    digitalWrite(remoteHbLed, HIGH);
    delay(200);
  }
  digitalWrite(remoteHbLed, LOW);
}

2  Using Arduino / Project Guidance / Fio constantly resets on: November 25, 2012, 03:24:54 am
I have 2 Fio boards with which I'm trying to cross communicate (for test puposes) a switch being pressed.  The intent is to press a momentary switch and see a local LED light up AND an LED on the other Fio.  The same should happen on the other Fio.  The software is identical on both.

It seems to work but quickly starts a back and forth reset of the 2 Fio boards.

I've seen notes about halting the resets on a basic arduino by putting a 120 ohm resister between reset and VCC; or a capacitor.  But I have not seen how it's done on the Fio.

Anyone have any tips about how to stop the Fio from resetting when I send a signal from Fio serial to Fio serial?

Thanks in advance,
Chris.


XBee 1
PAN ID: 1111
DH: 0
DL: 12
MY: 11 (radio 17)

XBee 2
PAN ID: 1111
DH: 0
DL: 11
MY: 12 (radio 18)

The code I'm testing.

Code:
// twowaytest.ino
// testing 2-way communications with the Fio

int buttonPin = 2; // button with 10k to gnd
int localHbLed = 13; // led to gnd
int remoteHbLed = 12; // led to gnd

int buttonState = 0;
int lastState = 0;
const int terminatingChar = 13; //Terminate lines with CR

void setup(){

  pinMode(localHbLed,OUTPUT);   
  pinMode(remoteHbLed,OUTPUT);
  pinMode(buttonPin, INPUT); 

  Serial.begin(57600);
  Serial.print(255);
  delay(2000);
 
  analogReference(EXTERNAL);
  blink(3); // show we're on...
}


void loop(){

  buttonState = digitalRead(buttonPin);

  if (lastState != buttonState) {
    if (buttonState == HIGH) {     
      // turn LED on:   
      digitalWrite(localHbLed, HIGH);
      sendDataToOther("pulseUp");
      lastState = HIGH;
    }
    else {
      // turn LED off:
      digitalWrite(localHbLed, LOW);
      sendDataToOther("pulseDn"); 
      lastState = LOW;
    }
  }

  getDataFromOther();
  delay(20);                          //  take a break
}

void sendDataToOther(String pulseVal){
  // send info to the other xbee
  if (pulseVal == "pulseUp"){
    Serial.print("pulseUp\r");
  }
  else {
    Serial.print("pulseDn\r");
  }
}

void getDataFromOther() {

  char* theOtherPulse = serialReader();
  // Serial.print("Other is: ");
  // Serial.println(theOtherPulse);

  // if (theOtherPulse == theOtherTest[0]){
  if (strstr(theOtherPulse, "PulseUp") != 0) {
    digitalWrite(remoteHbLed,HIGH);
    // Serial.print("recd... HIGH ");
    // Serial.println(theOtherPulse);
  }
  else {
    digitalWrite(remoteHbLed,LOW);
    // Serial.print("recd... LOW ");
    // Serial.println(theOtherPulse);
  }
}

// read serial port
char* serialReader(){
  int makeSerialStringPosition;
  int inByte;
  char serialReadString[50] = "";
 

  inByte = Serial.read();
  makeSerialStringPosition=0;

  if (inByte > 0 && inByte != terminatingChar) { //If we see data (inByte > 0) and that data isn't a carriage return
    delay(100); //Allow serial data time to collect (I think. All I know is it doesn't work without this.)

    while (inByte != terminatingChar && Serial.available() > 0){ // As long as EOL not found and there's more to read, keep reading
      serialReadString[makeSerialStringPosition] = inByte; // Save the data in a character array
      makeSerialStringPosition++; //Increment position in array
      //if (inByte > 0) Serial.println(inByte); // Debug line that prints the charcodes one per line for everything recieved over serial
      inByte = Serial.read(); // Read next byte
    }

    if (inByte == terminatingChar) //If we terminated properly
    {
      serialReadString[makeSerialStringPosition] = 0; //Null terminate the serialReadString (Overwrites last position char (terminating char) with 0
      // Serial.print("from method: ");
      // Serial.println(serialReadString);
      // if (strcmp(serialReadString, "LEDOn") == 0) digitalWrite(13, HIGH);
      // if (strcmp(serialReadString, "LEDOff") == 0) digitalWrite(13, LOW);

      return serialReadString;
    }
  }
  return "x"; // return this when nothing is recieved...
}

int stringToInt(String thisString) {
  int i, value, length;
  length = thisString.length();
  char blah[(length+1)];
  for(i=0; i<length; i++) {
    blah[i] = thisString.charAt(i);
  }
  blah[i]=0;
  value = atoi(blah);
  return value;
}

// blink n times
void blink(int howManyTimes){
  digitalWrite(localHbLed, LOW);
  digitalWrite(remoteHbLed, LOW);
  delay(200);
  for (int i=0; i< howManyTimes; i++){
    digitalWrite(localHbLed, HIGH);
    digitalWrite(remoteHbLed, LOW);
    delay(200);
    digitalWrite(localHbLed, LOW);
    digitalWrite(remoteHbLed, HIGH);
    delay(200);
  }
  digitalWrite(remoteHbLed, LOW);
}

3  Using Arduino / Networking, Protocols, and Devices / Re: Fio 2 way communication xbee on: November 22, 2012, 04:10:20 am
Thanks for your help, PaulS.

"Do you think the Serial Monitor can really tell when you are looking at it?"  haha, pretty funny.  Like a Schrödinger's Fio serial port.  I guess I've always used serial to send command to an arduino (and to view its receipt with the monitor) so I was concerned that viewing from the Arduino serial port might be eating the output.

Now it seems I've got it almost working, but what I am observing is that the 2 devices are constantly resetting each other.  I suppose it has something to do with the way the serial is used for loading new software.

Right now I have to remove the xbee in order to load updated code to each Fio.

The AREF pin is jumped to 3.3V because the PulseSensor I'm using needs 3.3V.

I'm using adafruit's FTDI Friend and I lifted CTS pin because that's where the AREF (3.3V) pin is on the FTDI Friend.  Perhaps I should connect the AREF directly to CTS?

Anyone have any tips on subduing the resets on the Fio?

Thanks in advance,
Chris.

Here's my simple 2 way code (buttons instead of pulse sensors)

Code:

// twowaytest.ino
// testing 2-way communications with the Fio

int buttonPin = 2; // button with 10k to gnd
int localHbLed = 13; //led to gnd
int remoteHbLed = 12; // led to gnd

int buttonState = 0;
int lastState = 0;
const int terminatingChar = 13; //Terminate lines with CR

void setup(){

  pinMode(localHbLed,OUTPUT);   
  pinMode(remoteHbLed,OUTPUT);
  pinMode(buttonPin, INPUT); 

  Serial.begin(57600);
  Serial.print(255);
  delay(2000);
 
  analogReference(EXTERNAL);
  blink(3); // show we're on...
}


void loop(){

  buttonState = digitalRead(buttonPin);

  if (lastState != buttonState) {
    if (buttonState == HIGH) {     
      // turn LED on:   
      digitalWrite(localHbLed, HIGH);
      sendDataToOther("pulseUp");
      lastState = HIGH;
    }
    else {
      // turn LED off:
      digitalWrite(localHbLed, LOW);
      sendDataToOther("pulseDn"); 
      lastState = LOW;
    }
  }

  getDataFromOther();
  delay(20);                          //  take a break
}

void sendDataToOther(String pulseVal){
  // send info to the other xbee
  if (pulseVal == "pulseUp"){
    Serial.print("pulseUp\r");
  }
  else {
    Serial.print("pulseDn\r");
  }
}

void getDataFromOther() {

  char* theOtherPulse = serialReader();
  // Serial.print("Other is: ");
  // Serial.println(theOtherPulse);

  // if (theOtherPulse == theOtherTest[0]){
  if (strstr(theOtherPulse, "PulseUp") != 0) {
    digitalWrite(remoteHbLed,HIGH);
    // Serial.print("recd... HIGH ");
    // Serial.println(theOtherPulse);
  }
  else {
    digitalWrite(remoteHbLed,LOW);
    // Serial.print("recd... LOW ");
    // Serial.println(theOtherPulse);
  }
}

// read serial port
char* serialReader(){
  int makeSerialStringPosition;
  int inByte;
  char serialReadString[50] = "";
 

  inByte = Serial.read();
  makeSerialStringPosition=0;

  if (inByte > 0 && inByte != terminatingChar) { //If we see data (inByte > 0) and that data isn't a carriage return
    delay(100); //Allow serial data time to collect (I think. All I know is it doesn't work without this.)

    while (inByte != terminatingChar && Serial.available() > 0){ // As long as EOL not found and there's more to read, keep reading
      serialReadString[makeSerialStringPosition] = inByte; // Save the data in a character array
      makeSerialStringPosition++; //Increment position in array
      //if (inByte > 0) Serial.println(inByte); // Debug line that prints the charcodes one per line for everything recieved over serial
      inByte = Serial.read(); // Read next byte
    }

    if (inByte == terminatingChar) //If we terminated properly
    {
      serialReadString[makeSerialStringPosition] = 0; //Null terminate the serialReadString (Overwrites last position char (terminating char) with 0
      // Serial.print("from method: ");
      // Serial.println(serialReadString);
      // if (strcmp(serialReadString, "LEDOn") == 0) digitalWrite(13, HIGH);
      // if (strcmp(serialReadString, "LEDOff") == 0) digitalWrite(13, LOW);

      return serialReadString;
    }
  }
  return "x"; // return this when nothing is recieved...
}

int stringToInt(String thisString) {
  int i, value, length;
  length = thisString.length();
  char blah[(length+1)];
  for(i=0; i<length; i++) {
    blah[i] = thisString.charAt(i);
  }
  blah[i]=0;
  value = atoi(blah);
  return value;
}

// blink n times
void blink(int howManyTimes){
  digitalWrite(localHbLed, LOW);
  digitalWrite(remoteHbLed, LOW);
  delay(200);
  for (int i=0; i< howManyTimes; i++){
    digitalWrite(localHbLed, HIGH);
    digitalWrite(remoteHbLed, LOW);
    delay(200);
    digitalWrite(localHbLed, LOW);
    digitalWrite(remoteHbLed, HIGH);
    delay(200);
  }
  digitalWrite(remoteHbLed, LOW);
}


4  Using Arduino / Networking, Protocols, and Devices / Fio 2 way communication xbee on: November 15, 2012, 04:59:12 am
I'm trying to do 2 way communication with 2 Fio's.  Using Series 1 Xbees.  Calling Serial.print("coded string") and trying to get an LED to respond to local pulse sensor AS WELL AS the other pulse sensor.  IOW, 2 pulse sensors each on a Fio.  Each Fio has an LED for local pulse, plus an LED for remote (other persons) pulse.

I set them up like this:
Code:
XBee 1
PAN ID: 1111
DH: 0
DL: 12
MY: 11 (radio 17)

XBee 2
PAN ID: 1111
DH: 0
DL: 11
MY: 12 (radio 18)

If I look at the serial monitor does that affect the delivery of the serial print data.  I've been wanting to track what's up by adding serial print statements but I fear they'll affect my serial read functions.

Would appreciate any references on how to set up cross communication between 2 xbee based fio boards.

Thanks in advance,
Chris.

The code I'm using for serial reader function:
Code:
// read serial port
char* serialReader(){
  int makeSerialStringPosition;
  int inByte;
  char serialReadString[50] = "";
  const int terminatingChar = 13; //Terminate lines with CR

  inByte = Serial.read();
  makeSerialStringPosition=0;

  if (inByte > 0 && inByte != terminatingChar) { //If we see data (inByte > 0) and that data isn't a carriage return
    delay(100); //Allow serial data time to collect (I think. All I know is it doesn't work without this.)

    while (inByte != terminatingChar && Serial.available() > 0){ // As long as EOL not found and there's more to read, keep reading
      serialReadString[makeSerialStringPosition] = inByte; // Save the data in a character array
      makeSerialStringPosition++; //Increment position in array
      //if (inByte > 0) Serial.println(inByte); // Debug line that prints the charcodes one per line for everything recieved over serial
      inByte = Serial.read(); // Read next byte
    }

    if (inByte == terminatingChar) //If we terminated properly
    {
      serialReadString[makeSerialStringPosition] = 0; //Null terminate the serialReadString (Overwrites last position char (terminating char) with 0
      // Serial.print("from method: ");
      // Serial.println(serialReadString);
      // if (strcmp(serialReadString, "LEDOn") == 0) digitalWrite(13, HIGH);
      // if (strcmp(serialReadString, "LEDOff") == 0) digitalWrite(13, LOW);

      return serialReadString;
    }
  }
  return "x"; // return this when nothing is recieved...
}

5  Using Arduino / Networking, Protocols, and Devices / Re: Bluetooth + Arduino - Major problem! Please help! on: May 23, 2012, 01:19:03 am
Hello,
I have to admit to not knowing much about Bluetooth...

I think it would be expected that you would lose bluetooth connectivity if the Lillypad loses power.  I'm not sure what other behavior you would expect.

Obviously, I would expect that there should be a way to regain connectivity when power was re-applied.

I know I've had some issues with arduino when I close the serial port, and then re-access it.  The arduino will auto re-boot by default; something about the way it works when you update code. There is a way to hook up a capacitor across the reset line to prevent re-boot.

Maybe these notes will help?  http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

Good luck,
Chris.
6  Forum 2005-2010 (read only) / Interfacing / Re: Automating Astronomy Dome - advice on: June 03, 2009, 01:17:37 pm
RetroLefty,
I was thinking about an ultrasonic sensor but I also was wondering how it might detect the shortest route to the opening.  I think it could be used to stop the motor when the dome opening was detected, but how might an ultrasonic detect where the opening is when the dome and telescope are off axis.  Multiple sensors pointing in different directions?

Grumpy_Mike,
I get the idea of detecting the scope's azimuth settings, but I don't understand your concept of "measuring the number of turns from the dome turning motor using an opto slit detector".  I'm including another diagram to show (kind of) how the motor is positioned to turn the dome.  The gears of the motor turn in a continuous track (something like sprockets on movie film) to rotate the dome.

I've thought of creating a continuous tape with positioning codes on the dome but a simple turn left/turn right seems so simple.  IOW, the dome should simply move to where ever the scope is pointing.

Another thought is to always start the session with the dome opening in the correct position, then detect a left or right motion of the scope and go from there.  For future "remoting" of all the astronomy functions, I'd like the dome to first find the proper position.

Thanks for your advice,
Chris.




7  Forum 2005-2010 (read only) / Interfacing / Re: Automating Astronomy Dome - advice on: June 03, 2009, 02:20:58 am
8  Forum 2005-2010 (read only) / Interfacing / Automating Astronomy Dome - advice on: June 03, 2009, 02:19:59 am
I am interested in setting up a system to control the dome over a telescope.  The dome, about 12 feet diameter at the base, covers a Meade 16" telescope.  The telescope can be automated with a laptop computer to point to locations in the sky, but then the dome needs to be rotated manually (left/right switch - turns on electric motor) to position the opening slot for a clear view.

My 1st pass at designing this goes as follows:

* Light sensor attached to the telescope detects the position of the dome by sensing:
    * no return light when shining into space through the slot
    * colors to indicate direction
* The sensor sends a signal to xBee transmitter
* xBee receiver gets the analog signal
* Arduino sets relays corresponding to left/right switch

The advise I'm looking for is about alternative sensors to detect the position of the dome.   When the system starts, we need a means of indicating the shortest way to turn the dome to position the opening in the direction of the telescope.

I was thinking that perhaps there might be large bar codes or color codes to indicate that the dome should turn left or right.  The distance from the telescope to the inner dome wall is about 6-8 feet.

Remember that low light is preferred for viewing, so a small laser would be best as the light source.

Please see the image below to see how it might hook up.
Image will be in second post, I guess.

Thanks for any advice,
Chris.






Pages: [1]