Show Posts
Pages: 1 2 [3] 4 5 ... 9
31  Using Arduino / Programming Questions / Re: Adafruit Wave shield button press song on: January 29, 2013, 11:39:04 am

So I tried your suggestion as this being the only chunk in the main loop with the buttonstate added. nothing plays.


Code:
wave.play();                       // make some noise!
       
uint8_t n = 0;
while (wave.isplaying)
  {// playing occurs in interrupts, so we print dots in realtime
 buttonState = digitalRead(buttonPin);

 putstring(".");
  if (!(++n % 32) && buttonState==HIGH){//Serial.println();
    //delay(100);
  wave.pause();
  }
  else{
    wave.resume();


}   

}
32  Using Arduino / Programming Questions / Re: Adafruit Wave shield button press song on: January 29, 2013, 11:01:20 am
Thanks for the suggestion. I am not quite clear on what you mean. could you show me with a code example?
33  Using Arduino / Programming Questions / Re: Adafruit Wave shield button press song on: January 29, 2013, 10:47:46 am
thanks for the suggestion, PaulS.

I have revised my loop as follows:

Code:
void loop() {
 
   buttonState = digitalRead(buttonPin);
 
 

 // play(root);

root.rewind();
  play(root);

while(wave.isplaying){
  buttonState = digitalRead(buttonPin);
   if(buttonState==HIGH){
  wave.pause();
   digitalWrite(ledPin, HIGH); 
Serial.println("HIGH");
  }
   else{
    wave.resume();
      digitalWrite(ledPin, LOW); 
Serial.println("LOW");
    }
  }

}

It seems the while loop is never gone into. The serial messages are never printed.
34  Using Arduino / Programming Questions / Re: Adafruit Wave shield button press song on: January 29, 2013, 10:27:03 am
Thanks guys. the wave pause has been uncommented, moved, and adjusted every which way and I can't find a working solution.


Quote
Where do you read the switch state? Where do you care about the switch state?

am I not doing this with,    "buttonState = digitalRead(buttonPin);" ?
35  Using Arduino / Programming Questions / Adafruit Wave shield button press song on: January 29, 2013, 03:46:42 am
So I purchased the wave shield. I have a simple (well...conceptually simple) action I want and that is:

if a button is on HIGH, pause playback of audio file. if its low, continue playing.

I have the shield playing back a song in a loop fine. I also interfaced a button to the wave shield and tested a basic button sketch which works fine and this concludes their are not any hardware issues.

My problem is nothing happens when I use my code of a basic modified sketch. it compiles, and just continuously plays back an audio file without any  regard for the switch. (made sure pin was correct in code). I have a testor LED that just very dimmly flickers on, and does nothing. As I said, I tested the button with a simple button state sketch and it works fine.

help. my code below:

Code:
/*
 * This example plays every .WAV file it finds on the SD card in a loop
 */
#include <WaveHC.h>
#include <WaveUtil.h>

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the volumes root directory
WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

uint8_t dirLevel; // indent level for file/dir names    (for prettyprinting)
dir_t dirBuf;     // buffer for directory reads


/*
 * Define macro to put error messages in flash memory
 */
#define error(msg) error_P(PSTR(msg))

const int buttonPin = 8;
const int ledPin =  13;

int buttonState = 0;

// Function definitions (we define them here, but the code is below)
void play(FatReader &dir);

//////////////////////////////////// SETUP
void setup() {
 // Serial.begin(9600);
  // set up Serial library at 9600 bps for debugging
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
 
 
  putstring_nl("\nWave test!");  // say we woke up!
 
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
 // Serial.println(FreeRam());

  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!) 
    error("Card init. failed!");  // Something went wrong, lets print out why
  }
 
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {   // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;                           // we found one, lets bail
  }
  if (part == 5) {                     // if we ended up not finding one  :(
    error("No valid FAT partition!");  // Something went wrong, lets print out why
  }
 
  // Lets tell the user about what we found
  putstring("Using partition ");
 // Serial.print(part, DEC);
  putstring(", type is FAT");
  //Serial.println(vol.fatType(), DEC);     // FAT16 or FAT32?
 
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    error("Can't open root dir!");      // Something went wrong,
  }
 
  // Whew! We got past the tough parts.
  putstring_nl("Files found (* = fragmented):");

  // Print out all of the files in all the directories.
  root.ls(LS_R | LS_FLAG_FRAGMENTED);
}

//////////////////////////////////// LOOP
void loop() {
 
   buttonState = digitalRead(buttonPin);
 
 
  root.rewind();
  play(root);

while(wave.isplaying){
   if(buttonState==HIGH){
  // wave.pause();
   digitalWrite(ledPin, HIGH); 
//   //Serial.println("HIGH");
  }
   else{
      //wave.resume();
      digitalWrite(ledPin, LOW); 
//    // Serial.println("LOW");
    }
  }
 
//while(wave.isplaying){
 
 
   
   

     

//}

/////////////////////////////////// HELPERS
/*
 * print error message and halt
 */
}




void error_P(const char *str) {
  PgmPrint("Error: ");
  SerialPrint_P(str);
  sdErrorCheck();
  while(1);
}
/*
 * print error message and halt if SD I/O error, great for debugging!
 */
void sdErrorCheck(void) {
  if (!card.errorCode()) return;
  PgmPrint("\r\nSD I/O error: ");
  //Serial.print(card.errorCode(), HEX);
  PgmPrint(", ");
  //Serial.println(card.errorData(), HEX);
  while(1);
}
/*
 * play recursively - possible stack overflow if subdirectories too nested
 */
void play(FatReader &dir) {
  FatReader file;
  while (dir.readDir(dirBuf) > 0) {    // Read every file in the directory one at a time
 
    // Skip it if not a subdirectory and not a .WAV file
    if (!DIR_IS_SUBDIR(dirBuf)
         && strncmp_P((char *)&dirBuf.name[8], PSTR("WAV"), 3)) {
      continue;
    }

   // Serial.println();            // clear out a new line
   
    for (uint8_t i = 0; i < dirLevel; i++) {
      // Serial.write(' ');       // this is for prettyprinting, put spaces in front
    }
    if (!file.open(vol, dirBuf)) {        // open the file in the directory
      error("file.open failed");          // something went wrong
    }
   
    if (file.isDir()) {                   // check if we opened a new directory
      putstring("Subdir: ");
      printEntryName(dirBuf);
     // Serial.println();
      dirLevel += 2;                      // add more spaces
      // play files in subdirectory
      play(file);                         // recursive!
      dirLevel -= 2;   
    }
    else {
      // Aha! we found a file that isnt a directory
      putstring("Playing ");
      printEntryName(dirBuf);              // print it out
      if (!wave.create(file)) {            // Figure out, is it a WAV proper?
        putstring(" Not a valid WAV");     // ok skip it
      } else {
       // Serial.println();                  // Hooray it IS a WAV proper!
        wave.play();                       // make some noise!
       
        uint8_t n = 0;
        while (wave.isplaying) {// playing occurs in interrupts, so we print dots in realtime
          putstring(".");
          if (!(++n % 32))//Serial.println();
          delay(100);
        }       
        sdErrorCheck();                    // everything OK?
        // if (wave.errors)Serial.println(wave.errors);     // wave decoding errors
      }
    }
  }
}
36  Using Arduino / Programming Questions / Re: State Machines on: January 19, 2013, 10:11:16 am
Thanks for the clarification, guys.
37  Using Arduino / Programming Questions / Re: State Machines on: January 19, 2013, 12:22:48 am
Hey PaulS,

I was going to transition to each case depending on specific arguments. What exactly do you mean by,
Quote
Well, now, it's quite clear what each of those states means. Not.
.

Was just curious.
38  Using Arduino / Programming Questions / Re: State Machines on: December 10, 2012, 12:13:40 am
EEk well I feel ridiculous. This question was actually intended for the Processing forum. I posted it there, but the problem lies in implementing this in Processing.
39  Using Arduino / Programming Questions / State Machines on: December 10, 2012, 12:04:03 am
So I am trying to put together a state machine, and am running into some difficultly.

I have formatted my program like so:


Code:
public enum states { STATE_1, STATE_2, STATE_3, STATE_4, STATE_5, STATE_6, MAX_STATES };

states state = new states;


switch (state){

case STATE_1 :
// if this does that, do something
}
state = STATE_2;
break;

case STATE_2:
// if this does that, do something
}
state = STATE_3;
break;
//etc etc

but I am receiving an error saying "cannot find anything named "state". What am I missing?

Cheers!
40  Using Arduino / Networking, Protocols, and Devices / Delimiters of two incoming series 1 Xbees on: November 15, 2012, 12:35:26 pm
I have a total of 3 series 1 xbees communicating in transparent mode through serial. Two of them are sending incoming reads and one of them is receiving.  I wanted to separate the incoming values with delimiters to know what value is coming from where.I've gotten up to this point with success.  Problem now is I dont know how to label this incoming values through the receiving Arduino. I simply just want to add something like, "Serial.print("this is the first sensor = "); and so fourth for second sensor. I am just not sure where it is appropriate within the code. here is the code below:

Emitter : (code is the same for both )

Code:
// Example of sending numbers by Serial
// Author: Nick Gammon
// Date: 31 March 2012

const char startOfNumberDelimiter = '<';
const char endOfNumberDelimiter   = '>';
const int rssi_pin = 9; //RSSI Pin of the XBee Module
 int rssiDur;
 
 
void setup ()
  {
  //srand (42);
  Serial.begin (38400);
  } // end of setup
  
void loop ()
  {
    
     rssiDur = pulseIn(rssi_pin, LOW, 200); //sending this val
    

  for (int i = 0; i < 10; i++)
    {
    Serial.print (startOfNumberDelimiter);    
    Serial.print (rssiDur);    // send the number
    Serial.print (endOfNumberDelimiter);  
    Serial.println ();
    }  // end of for

  delay (300);
  }  // end of loop



....and the receiver


Code:
// Example of receiving numbers by Serial
// Author: Nick Gammon
// Date: 31 March 2012

const char startOfNumberDelimiter = '<';
const char endOfNumberDelimiter   = '>';

void setup ()
  {
  Serial.begin (38400);
  //Serial.println ("Starting ...");
  } // end of setup
  
void processNumber (const long n)
  {
    Serial.print("bike 2 = ");
  Serial.println (n);
  }  // end of processNumber
  
void processInput ()
  {
  static long receivedNumber = 0;
  static boolean negative = false;
  
  byte c = Serial.read ();
  
  switch (c)
    {
      
    case endOfNumberDelimiter:  
      if (negative)
        processNumber (- receivedNumber);
      else
        processNumber (receivedNumber);

    // fall through to start a new number
    case startOfNumberDelimiter:
      receivedNumber = 0;
      negative = false;
      break;
      
    case '0' ... '9':
      receivedNumber *= 10;
      receivedNumber += c - '0';
      break;
      
    case '-':
      negative = true;
      break;
      
    } // end of switch  
    
  }  // end of processInput
  
void loop ()
  {
  
  if (Serial.available ())
    processInput ();
    
  // do other stuff here
  } // end of loop
41  Using Arduino / Networking, Protocols, and Devices / the XBee blues; problem reading RSSI series 1 XBee pin on: November 12, 2012, 05:03:51 pm
So i've got two sketches (big thanks to Jack Christensen for help with the code) that are suppose to send the RSSI value of one emitter xbee to a receiver.

The only parameters i've changed on the xbees through AT commands are the ID's and the baud rate. serial communication is happening (I printed out a random number intentionally from the emitter to the receiver with success) but for some reason its not grabbing the incoming values from the RSSI pin. wiring is correct, commands match, etc.


 ** to note jack had tried this code on series 2 xbees with success. not sure what I am missing.


heres the code:

emitter :

Code:
// Daniel Jay Bertner - Bike communication modules
// Modified by Jack Christensen 10Nov2012

//Transmitter modules. These are the bike units intended to show signal strength indication in correlation to a central networked hub

//x bees have been configured with personal ID's to avoid interference with other networks (encryption).
//encryption is not about interference, just use a unique PAN ID (ATID) ... jc
//optimal xbee use is outdoors, no wall interference/metal(close contact). range is 300ft at optimal conditions.
//

#define EMITTER_NBR 1                      //emitter number, set to 1 or 2
#define XBEE_BAUD_RATE 38400
#define XMIT_DELAY 200
#define RSSI_PIN 9                         //connect to the XBee RSSI pin (Daniel's wiring)
//#define RSSI_PIN 2                         //connect to the XBee RSSI pin (Jack's wiring)
const byte ledPins[] = { 3, 4, 5, 6, 7, 8, 10, 11, 12, 13 };    //Daniel's wiring
//const byte ledPins[] = { 12, 13, 6, 7, 8, 3, 4, 5, 9, 10};        //Jack's wiring
#define NBR_LEDS sizeof(ledPins) / sizeof(ledPins[0])

///Averager Variables///////////////////////////////
//this is intended to place first 10 read incoming RSSI values in an array and average. smoother readings

#define NBR_READINGS 10                    //number of readings to average
unsigned long pulseWidth;                  //the XBee RSSI pulse width reading from pulseIn
unsigned long readings[NBR_READINGS];      //RSSI readings
int index;                                 //index to current reading
unsigned long total;                       //total of the readings
unsigned long average;                     //average of the readings
boolean first = true;                      //first time flag to initialize readings array and total

///////////////////////////////////////////////////

void setup()
{
    Serial.begin(XBEE_BAUD_RATE);                  

    for (byte i=0; i<NBR_LEDS; i++)
        pinMode(ledPins[i], OUTPUT);
}

void loop()
{
    Serial.print('<');
    Serial.print(EMITTER_NBR, DEC);
    Serial.print('>');
    Serial.print(average, DEC);
    delay(50);        //allow time for transmission
    pulseWidth = pulseIn(RSSI_PIN, LOW, XMIT_DELAY/2);
    if (first) {
        first = false;
        total = pulseWidth * NBR_READINGS;
        for (int i=0; i<NBR_READINGS; i++)
            readings[i] = pulseWidth;
    }
    else {
        if (++index >= NBR_READINGS) index = 0;
        total = total - readings[index] + pulseWidth;
        readings[index] = pulseWidth;
    }
    average = total / NBR_READINGS;        
    runDisplay();
    delay(XMIT_DELAY - 50);
}
    
//run the bargraph display
void runDisplay(void)
{
    if (average < 10)
        light(10);
    else if (average < 20)
        light(9);
    else if (average < 30)
        light(8);
    else if (average < 40)
        light(7);
    else if (average < 50)
        light(6);
    else if (average < 60)
        light(5);
    else if (average < 70)
        light(4);
    else if (average < 80)
        light(3);
    else if (average < 90)
        light(2);
    else
        light(1);
}

//light the number of LEDs given by nbrOn
void light(int nbrOn)
{
    for (byte i=0; i<nbrOn; i++)
        digitalWrite(ledPins[i], HIGH);
        
    for (byte i=nbrOn; i<NBR_LEDS; i++)
        digitalWrite(ledPins[i], LOW);
}

...and the receiver code:

Code:
// Daniel Jay Bertner - Bike communication modules
// Modified by Jack Christensen 11Nov2012

#include <LiquidCrystal.h>

#define START_DELIM '<'
#define RECV_TIMEOUT 10                     //consider a node "not available" after this many seconds with no message
#define MAX_RSSI_LEN 6                      //maximum RSSI value length to be accepted from transmitter nodes
//#define LCD_BACKLIGHT 9                     //for Jack's LCD

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);      //Daniel's wiring
//LiquidCrystal lcd(2, 3, 4, 5, 6, 7);        //Jack's wiring
unsigned long ms;                           //current sketch time
unsigned long lastRecv1;                    //time of last message from node 1
unsigned long lastRecv2;                    //time of last message from node 2

void setup()
{
    pinMode(LED_BUILTIN, OUTPUT);           //pin 13 LED
//    pinMode(LCD_BACKLIGHT, OUTPUT);         //for Jack's LCD
//    digitalWrite(LCD_BACKLIGHT, HIGH);      //for Jack's LCD
    Serial.begin(38400);
    lcd.begin(16, 2);
    lcd.clear();
}

enum STATES { WAIT, NODE, SKIP, RSSI };
uint8_t STATE;

//incoming message format from the XBees is: <n>sss where n is the node number (1 or 2) and sss is signal strength
void loop()
{
    int c;                  //input character
    static byte rssiLen;    //length of the signal strength number (to guard against unreasonable input)
    static boolean ledState;

    ms = millis();
    checkNodes();
    if ( Serial.available() > 0 ) {    //process the next character when it arrives
        c = Serial.read();
        switch (STATE) {
            
            case WAIT:    //wait for start delimiter (first time)
                if (c == START_DELIM) ++STATE;
                break;
                
            case NODE:    //determine which node the message is from
                digitalWrite(LED_BUILTIN, ledState = !ledState);    //toggle the LED for every msg received
                if (c == '1') {
                    lastRecv1 = ms;
                    lcd.setCursor(0, 0);
                    lcd.print("Bike1=      ");    //blank out previous value
                    lcd.setCursor(6, 0);
                    ++STATE;
                }
                else if (c == '2') {
                    lastRecv2 = ms;
                    lcd.setCursor(0, 1);
                    lcd.print("Bike2=      ");    //blank out previous value
                    lcd.setCursor(6, 1);
                    ++STATE;
                }
                else
                    STATE = WAIT;                 //something we weren't expecting
                break;
                
            case SKIP:    //skip the '>'
                rssiLen = 0;
                ++STATE;
                break;
                
            case RSSI:    //copy the RSSI value to the LCD
                if (c == START_DELIM)                        //has a new message started?
                   STATE = NODE;
                else if (++rssiLen > MAX_RSSI_LEN)
                    STATE = WAIT;                    //something is wrong, abandon this message
                else
                    lcd.write(c);
                break;                
        }
    }
}

//check the time of the last message from each node, mark them "N/A" if RECV_TIMEOUT is exceeded
void checkNodes(void)
{
    static unsigned long lastCheck;
    
    if (ms - lastCheck >= 1000) {    //no point in over doing it
        lastCheck = ms;
        if (lastRecv1 == 0 || ms - lastRecv1 >= RECV_TIMEOUT * 1000) {
            lcd.setCursor(0, 0);
            lcd.print("Bike1=N/A    ");
       }
        
        if (lastRecv2 == 0 || ms - lastRecv2 >= RECV_TIMEOUT * 1000) {
            lcd.setCursor(0, 1);
            lcd.print("Bike2=N/A    ");
        }
    }
}
42  Using Arduino / Networking, Protocols, and Devices / Re: A story of three xbees; two emitters and one hub on: November 09, 2012, 07:20:51 pm
No go. I tried and also rearranged the emitter code as shown below :

Code:
const int rssi_pin = 9; //RSSI Pin of the XBee Module
 int rssiDur; //variable to read pin
byte inches_val;

//LED pins//////////////////////////
const int led3 = 3;
const int led4 = 4;
const int led5 = 5;
const int led6 = 6;
const int led7= 7;
const int led8= 8;
const int led10= 10;
const int led11= 11;
const int led12= 12;
const int led13= 13;
/////////////////////////////////////

///Averager Variables///////////////////////////////

//this is intended to place first 10 read incoming RSSI values in an array and average. smoother readings

const int numReadings = 10;

int readings[numReadings];      // the readings from the RSSI
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
byte average = 0;                // the average


///////////////////////////////////////////////////
const byte nodeID = 2;
    int myData2;


void setup(){
 
   for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;

pinMode (led3, OUTPUT);
pinMode (led4, OUTPUT);
pinMode (led5, OUTPUT);
pinMode (led6, OUTPUT);
pinMode (led7, OUTPUT);
pinMode (led8, OUTPUT);
pinMode (led10, OUTPUT);
pinMode (led11, OUTPUT);
pinMode (led12, OUTPUT);
pinMode (led13, OUTPUT);
 
 
  Serial.begin(38400); //Xbee communicating at this baud
}

void loop(){


 rssiDur = pulseIn(rssi_pin, LOW, 200); //this is set to 200ms with ATRP @ 2
//inches_val = rssiDur + 24; // this is 24inches / 2 feet
//min(inches_val, 18);
total= total - readings[index];         
  // read from the sensor: 
  readings[index] = rssiDur;
  // add the reading to the total:
  total= total + readings[index];       
  // advance to the next position in the array: 
  index = index + 1;                   

  // if we're at the end of the array...
  if (index >= numReadings)             
    // ...wrap around to the beginning:
    index = 0;                           

  // calculate the average:
  average = total / numReadings;         
 


if (average > 24 && average < 124){ //1-5 meters
 // Serial.write(1);
   digitalWrite(led3, HIGH);
       digitalWrite(led4, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        digitalWrite(led7, HIGH);
        digitalWrite(led8, HIGH);
        digitalWrite(led10, HIGH);
        digitalWrite(led11, HIGH);
        digitalWrite(led12, HIGH);
        digitalWrite(led13, HIGH);
       
}
  if (average > 124 && average < 224){ //5-10 meters
  //Serial.write(2);
   digitalWrite(led3, HIGH);
       digitalWrite(led4, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        digitalWrite(led7, HIGH);
         digitalWrite(led8, HIGH);
        digitalWrite(led10, HIGH);
        digitalWrite(led11, HIGH);
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);
       
  }
  if (average > 224 && average < 324){ //10- 15 meters
  //Serial.write(3); //this is 10 meters. write to reciever
   digitalWrite(led3, HIGH);
       digitalWrite(led4, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        digitalWrite(led7, HIGH);
         digitalWrite(led8, HIGH);
         digitalWrite(led10, LOW);
        digitalWrite(led11, LOW);
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);
       
  }
  if (average > 324 && average < 424){ //15-20 meters
  //Serial.write(4);
    digitalWrite(led3, HIGH);
       digitalWrite(led4, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        digitalWrite(led7, LOW);
           digitalWrite(led8, LOW);
        digitalWrite(led10, LOW);
        digitalWrite(led11, LOW);
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);
       
  }
  if (average > 424 ){ //20-30 meters
 // Serial.write(5);
   digitalWrite(led3, HIGH);
       digitalWrite(led4, HIGH);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        digitalWrite(led7, LOW);
         digitalWrite(led8, LOW);
        digitalWrite(led10, LOW);
        digitalWrite(led11, LOW);
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);
     
    }
   
    //isolated instances below
   
  if (average == 24 ){ //if their is no signal
 // Serial.write(5);
   digitalWrite(led3, LOW);
       digitalWrite(led4, LOW);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        digitalWrite(led7, LOW);
         digitalWrite(led8, LOW);
        digitalWrite(led10, LOW);
        digitalWrite(led11, LOW);
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);
}

 Serial.write('*');            //message start delimiter
    Serial.write(nodeID);
    Serial.write(average >> 8);    //most significant byte
    Serial.write(average & 0xFF);  //least significant byte
delay(200);
}
 
43  Using Arduino / Networking, Protocols, and Devices / Re: A story of three xbees; two emitters and one hub on: November 09, 2012, 03:53:22 pm
eh, not having much luck. the LCD prints out a -257 and nothing changes.

here the code:


Emitter:

Code:
//Transmitter modules. These are the bike units intended to show signal strength indication in correlation to a central networked hub.
//x bees have been configured with personal ID's to avoid interference with other networks (encryption).
//optimal xbee use is outdoors, no wall interference/metal(close contact). range is 300ft at optimal conditions.
//





const int rssi_pin = 9; //RSSI Pin of the XBee Module
 int rssiDur; //variable to read pin
byte inches_val;

//LED pins//////////////////////////
const int led3 = 3;
const int led4 = 4;
const int led5 = 5;
const int led6 = 6;
const int led7= 7;
const int led8= 8;
const int led10= 10;
const int led11= 11;
const int led12= 12;
const int led13= 13;
/////////////////////////////////////

///Averager Variables///////////////////////////////

//this is intended to place first 10 read incoming RSSI values in an array and average. smoother readings

const int numReadings = 10;

int readings[numReadings];      // the readings from the RSSI
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
byte average = 0;                // the average


///////////////////////////////////////////////////
const byte nodeID = 1;
    int myData;


void setup(){
  
   for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;

pinMode (led3, OUTPUT);
pinMode (led4, OUTPUT);
pinMode (led5, OUTPUT);
pinMode (led6, OUTPUT);
pinMode (led7, OUTPUT);
pinMode (led8, OUTPUT);
pinMode (led10, OUTPUT);
pinMode (led11, OUTPUT);
pinMode (led12, OUTPUT);
pinMode (led13, OUTPUT);
  
   //Serial1.begin(38400);
  Serial.begin(38400); //Xbee communicating at this baud
}




void loop(){


 rssiDur = pulseIn(rssi_pin, LOW, 200); //this is set to 200ms with ATRP @ 2
inches_val = rssiDur; // XBee times out 10-12 inches apart, so added 11
inches_val = rssiDur + 24; // XBee times out 10-12 inches apart, so added 11
min(inches_val, 1);
//min(inches_val, 18);
total= total - readings[index];        
  // read from the sensor:  
  readings[index] = inches_val;
  // add the reading to the total:
  total= total + readings[index];      
  // advance to the next position in the array:  
  index = index + 1;                    

  // if we're at the end of the array...
  if (index >= numReadings)              
    // ...wrap around to the beginning:
    index = 0;                          

  // calculate the average:
  average = total / numReadings;        
  


    Serial.write('*');            //message start delimiter
    Serial.write(nodeID);
    Serial.write(average >> 8);    //most significant byte
    Serial.write(average & 0xFF);  //least significant byte
delay(100);
// value 10 = 1 meter
if (average > 24 && average < 124){ //1-5 meters
 // Serial.write(1);
   digitalWrite(led3, HIGH);
       digitalWrite(led4, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        digitalWrite(led7, HIGH);
        digitalWrite(led8, HIGH);
        digitalWrite(led10, HIGH);
        digitalWrite(led11, HIGH);
        digitalWrite(led12, HIGH);
        digitalWrite(led13, HIGH);
        
}
  if (average > 124 && average < 224){ //5-10 meters
  //Serial.write(2);
   digitalWrite(led3, HIGH);
       digitalWrite(led4, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        digitalWrite(led7, HIGH);
         digitalWrite(led8, HIGH);
        digitalWrite(led10, HIGH);
        digitalWrite(led11, HIGH);
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);
        
  }
  if (average > 224 && average < 324){ //10- 15 meters
  //Serial.write(3); //this is 10 meters. write to reciever
   digitalWrite(led3, HIGH);
       digitalWrite(led4, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        digitalWrite(led7, HIGH);
         digitalWrite(led8, HIGH);
         digitalWrite(led10, LOW);
        digitalWrite(led11, LOW);
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);
        
  }
  if (average > 324 && average < 424){ //15-20 meters
  //Serial.write(4);
    digitalWrite(led3, HIGH);
       digitalWrite(led4, HIGH);
        digitalWrite(led5, HIGH);
        digitalWrite(led6, HIGH);
        digitalWrite(led7, LOW);
           digitalWrite(led8, LOW);
        digitalWrite(led10, LOW);
        digitalWrite(led11, LOW);
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);
        
  }
  if (average > 424 ){ //20-30 meters
 // Serial.write(5);
   digitalWrite(led3, HIGH);
       digitalWrite(led4, HIGH);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        digitalWrite(led7, LOW);
         digitalWrite(led8, LOW);
        digitalWrite(led10, LOW);
        digitalWrite(led11, LOW);
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);
      
    }
    
    //isolated instances below
  
  if (average == 24 ){ //if their is no signal
  Serial.write(9);
   digitalWrite(led3, LOW);
       digitalWrite(led4, LOW);
        digitalWrite(led5, LOW);
        digitalWrite(led6, LOW);
        digitalWrite(led7, LOW);
         digitalWrite(led8, LOW);
        digitalWrite(led10, LOW);
        digitalWrite(led11, LOW);
        digitalWrite(led12, LOW);
        digitalWrite(led13, LOW);
}

}

reciever :

Code:
#include <LiquidCrystal.h>

const int ledPin = 13;
//const int signalStrengthPin = 9;

//byte incomingByte, val_read;
byte val_read;

int emitter2;


    byte nodeID;
 
    int average;
//int RSSIpin = 9;
//unsigned long rssiDur;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  Serial.begin(38400);
 lcd.begin(16,2);
lcd.noAutoscroll();
    
  pinMode(ledPin, OUTPUT);
 // pinMode(signalStrengthPin, INPUT);
}

void loop()
{


 //rssiDur = pulseIn(RSSIpin, LOW, 200);
  // print signal strength
  //Serial.println(rssiDur);
 
  if (Serial.available()>0)
  {
   // if ((int(val_read) == 'B'))
    
val_read = Serial.read();
 if (val_read == '*') {                     //wait for start delimiter
        nodeID = Serial.read();
        average = Serial.read() << 8;    //msb
        average += Serial.read();        //lsb
        
   while (val_read == '*' && nodeID == 1)    //message received and decoded, continue processing it...
    lcd.noAutoscroll();
    lcd.setCursor(0,0);
lcd.print("Bike1 = ");
lcd.print(average);

 }
 
  while (val_read == 'A' && nodeID ==2) {                     //wait for start delimiter
        
lcd.noAutoscroll();
      lcd.setCursor(0,1);
lcd.print("Bike2 = ");
lcd.print(average);
  }
}

  }
44  Using Arduino / Networking, Protocols, and Devices / Re: A story of three xbees; two emitters and one hub on: November 09, 2012, 12:55:02 pm
Great! When I get home I'm going to test this out and let you know. And start delimiter ? You mean some kinda delay for emitters? Unclear what you mean by that
45  Using Arduino / Networking, Protocols, and Devices / Re: A story of three xbees; two emitters and one hub on: November 09, 2012, 12:17:48 pm
And can you give me a example in code ? Having hard time understanding that with syntax
Pages: 1 2 [3] 4 5 ... 9