Show Posts
Pages: [1] 2 3 ... 7
1  Using Arduino / Programming Questions / Re: Sending Sensor Data Via Xbee Series 2 on: January 31, 2014, 11:53:18 pm
Hi Paul,
If it was so straight forward, I wouldn't have asked for any advice.  That's the reason Im asking for help as I'm not sure if, or how the Rx code could be written.  It may seem straight forward to you as you have more experience than I have, hence the idea behind this forum.....to teach and to learn.  Please if you have no intention of being a mentor, I would ask you not to reply.

Thank You
Dave

2  Using Arduino / Programming Questions / Sending Sensor Data Via Xbee Series 2 on: January 31, 2014, 11:35:26 am
good day folks,
I'm using the following sketch from the arduino xbee series2_Tx example as well as the DHT 22 examlpe  to read humidity and temperature, then transmits it using a ZigBee RF module.  Could anyone offer any advice on how to modify the current xbee series2_Rx example to receive the packets from the xbee series2_Tx sketch I have below and display the humidity and temperature values on the serial window?

Code:
#include "XBee.h"
#include "DHT.h"
 
#define DHTPIN 2     // data pin of the DHT sensor
 
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
 
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
 
DHT dht(DHTPIN, DHTTYPE);
 
/*
This example is for Series 2 XBee
 Sends a ZB TX request with the value of analogRead(pin5) and checks the status response for success
*/
 
// create the XBee object
XBee xbee = XBee();
 
// we are going to send two floats of 4 bytes each
uint8_t payload[8] = { 0, 0, 0, 0, 0, 0, 0, 0};
 
// union to convery float to byte string
union u_tag {
    uint8_t b[4];
    float fval;
} u;
 
 
// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x406F4973);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
 
int statusLed = 13;
int errorLed = 13;
 
void flashLed(int pin, int times, int wait) {
 
  for (int i = 0; i < times; i++) {
    digitalWrite(pin, HIGH);
    delay(wait);
    digitalWrite(pin, LOW);
 
    if (i + 1 < times) {
      delay(wait);
    }
  }
}
 
void setup() {
  pinMode(statusLed, OUTPUT);
  pinMode(errorLed, OUTPUT);
  dht.begin();
  xbee.begin(9600);
}
 
void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();
 
  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (!isnan(t) && !isnan(h)) {
     
    // convert humidity into a byte array and copy it into the payload array
    u.fval = h;
    for (int i=0;i<4;i++){
      payload[i]=u.b[i];
    }
     
    // same for the temperature
    u.fval = t;
    for (int i=0;i<4;i++){
      payload[i+4]=u.b[i];
    }
     
    xbee.send(zbTx);
 
    // flash TX indicator
    flashLed(statusLed, 1, 100);
 
    // after sending a tx request, we expect a status response
    // wait up to half second for the status response
    if (xbee.readPacket(500)) {
      // got a response!
 
      // should be a znet tx status             
      if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
        xbee.getResponse().getZBTxStatusResponse(txStatus);
 
        // get the delivery status, the fifth byte
        if (txStatus.getDeliveryStatus() == SUCCESS) {
          // success.  time to celebrate
          flashLed(statusLed, 5, 50);
        } else {
          // the remote XBee did not receive our packet. is it powered on?
          flashLed(errorLed, 3, 500);
        }
      }
    } else if (xbee.getResponse().isError()) {
      //nss.print("Error reading packet.  Error code: "); 
      //nss.println(xbee.getResponse().getErrorCode());
    } else {
      // local XBee did not provide a timely TX Status Response -- should not happen
      flashLed(errorLed, 2, 50);
    }
  }
  delay(1000);
}

Thank you in advance!!
Dave
3  Using Arduino / Programming Questions / Port manipulation Arduino Uno on: November 14, 2013, 09:34:34 am
Could someone please have a look at the following code, and confirm if I've written the port manipulation  equal to the digitalWrite format?

Thank you!
Dave

Code:
  DDRD = DDRD | B11111100;  //  sets pins 2 to 7 as outputs
                  // without changing value of pins 0 & 1, which are RX & TX
  PORTD = PORTD & ~B00000000;// set pins 4&7 LOW
  delayMicroseconds(2);
  PORTD = B10010000; // sets pins 7,4 HIGH
  delayMicroseconds(5);
  PORTD = PORTD & ~B00000000;// set pins 4&7 LOW
 
  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
 
  DDRD = DDRD &~ B11111100; // //  sets pins 2 to 7 as inputs*/


Code:
  pinMode(pingPin1, OUTPUT);
  pinMode(pingPin2, OUTPUT);
  digitalWrite(pingPin1, LOW);
  digitalWrite(pingPin2, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin1, HIGH);
  digitalWrite(pingPin2, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin1, LOW);
  digitalWrite(pingPin2, LOW);
       
  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin1, INPUT);
  pinMode(pingPin2, INPUT);
4  Using Arduino / Programming Questions / Port Manipulation on: November 12, 2013, 11:28:41 am
Could someone please tell me if the following port manipulation is an equavaluent expression to the digitalWrite / pinMode?

Code:
  DDRH = DDRH | B11000000;// set pins 6&7 as OUPUTS
  PORTH = PORTH | B00000000;// set pins 6&7 LOW
  delayMicroseconds(2);
  PORTH = PORTH | B11000000;// set pins 6&7 HIGH
  delayMicroseconds(5);
  PORTH = PORTH | B00000000;// set pina 6&7 LOW
 
  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  DDRH = DDRH | B00000000;// set pins 6&7 as INPUTS


Code:
  pinMode(pingPin1, OUTPUT);
  pinMode(pingPin2, OUTPUT);
  digitalWrite(pingPin1, LOW);
  digitalWrite(pingPin2, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin1, HIGH);
  digitalWrite(pingPin2, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin1, LOW);
  digitalWrite(pingPin2, LOW);
       
  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin1, INPUT);
  pinMode(pingPin2, INPUT);
5  Using Arduino / Project Guidance / posting data to google docs via https? on: November 08, 2013, 10:57:49 am
has anyone found a way of posting https data to google docs via arduino?
Or any way this can be done with a current ethernet open source solution?

Thank you
Dave
6  Using Arduino / Sensors / Ultrasonic Ping Sensor on: November 04, 2013, 04:18:19 pm
I have the following code reading 2 ping sensors, where the transmitter on each has been removed leaving only the receivers. The transmitter that was removed from sensor 1 was soldered back to the board with a 10ft length of wire.  This will allow me to hold the transmitter 2ft from the 2 receivers on center.  The transmitter is triggered by sensor 1 and initializes both sensor 1 and sensor 2.  Each receiving sensor is spaced 18" apart and approx. 24" away from the transmitter on center.  I able to read the output in cm on sensor 1, however the output on sensor 2 seems to be approx. 10cm short of sensor 1.  I have tried changing the timing function and modifying the order of the code, but this does not change the outcome. 

Can anyone offer any advice or see anything that my help match the output of the sensors at equal distance?
Thank you
Dave

Please find the code below.

Code:
#include <NewPing.h>

#define TRIGGER_PIN_1  12  // trigger pin on ping sensor 1
#define ECHO_PIN_1     12  // echo pin on ping sensor1
#define MAX_DISTANCE_1 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

#define TRIGGER_PIN_2  8  // trigger pin on ping sensor 2
#define ECHO_PIN_2     8  // echo pin on ping sensor 2
#define MAX_DISTANCE_2 175 // Maximum distance to ping in centimeters

NewPing sonar1(TRIGGER_PIN_1, ECHO_PIN_1, MAX_DISTANCE_1);
NewPing sonar2(TRIGGER_PIN_2, ECHO_PIN_2, MAX_DISTANCE_2);

unsigned int pingSpeed_1 = 300; // Frequency of ping output (in milliseconds)
unsigned long pingTimer_1;     // Hold next ping time.
unsigned int pingSpeed_2 = 300; // Frequency of ping output (in milliseconds)
unsigned long pingTimer_2;     // Hold next ping time.


void setup() {
  Serial.begin(9600); // serial monitor
  pingTimer_1 = millis(); // Start
  pingTimer_2 = millis(); // Start
}

void loop() {

  if (millis() >= pingTimer_1) {   // pingSpeed milliseconds since last ping, do another ping.
    pingTimer_1 += pingSpeed_1;      // Set next ping time.
    sonar1.ping_timer(echoCheck1); // Send out ping, calls "echoCheck" function every 24uS to check ping status.
  }

  if (millis() >= pingTimer_2) {   // pingSpeed milliseconds since last ping, do another ping.
    pingTimer_2 += pingSpeed_2;      // Set next ping time.
    sonar2.ping_timer(echoCheck2); // Send out ping, calls "echoCheck" function every 24uS to check ping status.
  }
  // add other code with no delay
}

void echoCheck1() { // Timer2 interrupt calls function every 24uS to check the ping status.
  // Don't do anything here!
  if (sonar1.check_timer()) { // check to see if ping was received.
    // Here's where you can add code.
    Serial.print("Ping1: ");
    Serial.print((sonar1.ping_result / US_ROUNDTRIP_CM); // convert to cm with US_ROUNDTRIP_CM
    Serial.println("cm1");
  }
  // Don't do anything here!
}

void echoCheck2() { // Timer2 interrupt calls function every 24uS to check the ping status.
  // Don't do anything here! 
  if (sonar2.check_timer()) { // check to see if ping was received.
    // Here's where you can add code.
    Serial.print("Ping2: ");
    Serial.print(sonar2.ping_result / US_ROUNDTRIP_CM); // convert to cm with US_ROUNDTRIP_CM
    Serial.println("cm2");
  }
  // Don't do anything here!
}
7  Using Arduino / Project Guidance / Re: Ping Sensor on: November 01, 2013, 02:36:53 pm
Please find the current code I'm using below

Code:
// this constant won't change.  It's the pin number
// of the sensor's output:
const int pingPin1 = 10;
const int pingPin2 = 11;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}

void loop()
{
  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration1, inches1, cm1;
  long duration2, inches2, cm2;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin1, OUTPUT);
  pinMode(pingPin2, OUTPUT);
  digitalWrite(pingPin1, LOW);
  digitalWrite(pingPin2, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin1, HIGH);
  digitalWrite(pingPin2, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin1, LOW);
  digitalWrite(pingPin2, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin1, INPUT);
  duration1 = pulseIn(pingPin1, HIGH);
  pinMode(pingPin2, INPUT);
  duration2 = pulseIn(pingPin2, HIGH);

  // convert the time into a distance
  inches1 = microsecondsToInches(duration1);
  cm1 = microsecondsToCentimeters(duration1);
 
  // convert the time into a distance
  inches2 = microsecondsToInches(duration2);
  cm2 = microsecondsToCentimeters(duration2);
 
  Serial.print(inches1);
  Serial.print("in1, ");
  Serial.print(cm1);
  Serial.print("cm1");
  Serial.println();
 
  Serial.print(inches2);
  Serial.print("in2, ");
  Serial.print(cm2);
  Serial.print("cm2");
  Serial.println();
 
  delay(100);
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
8  Using Arduino / Project Guidance / Re: Ping Sensor on: November 01, 2013, 02:21:56 pm
Thank you so much for shedding light on this, I didn't realize you couldn't read more than 2 incoming signals at the same time.

I have each output one from each ping sensor that have been set to input digital pins 10 and 11(pingPin 1  & pingPin2).  And only 1 will give an output at a time, I've tried swapping the pins and this confirms they function, but only on the "const int" pin that's first on the list.   Is there a way manipulate my code to accomplish this or am I chasing the impossible.

Thank you again

Dave
9  Using Arduino / Project Guidance / Ping Sensor on: November 01, 2013, 11:59:56 am
I've used the ping sensor to measure distance to a wall and it works great.   How ever I would like to use 2 sensors to read direction(left and right).  My thought was to remove the transmit senor on each ping module leaving only the receiver.  Then use the transmitter that was removed from one the ping modules to send a ping to both modules positioned to the left and the right at a set distance, moving the transmitter from left to right would change the angle to each receiver hence changing the distance from the transmitter to each ping receiver.  I've got the transmitter to (ping)communicate with one of the receivers resulting in a distance output, how ever I haven't been able to successfully communicate to both receivers simultaneously.  Can anyone shed some light on this or has anyone ever tried this with success?  I'll be sure to post my current code this afternoon as well.

Thank you in advance for any help you can provide.

Dave
10  Using Arduino / Programming Questions / Re: writing a program that follows a specific oder of execution on: April 04, 2013, 11:21:23 am
Code:
if(bindicatorlowstatus1 == HIGH);{//bin has reached full close gate

The semicolon should not be there. You have other instances of this in your code too. Fix them all, tidy your code using the IDE menu Tools|Auto Format,  and then try running it again.

Pete

Excellent!! thank you, I'll give that a try!

Thank you
Dave Pina
11  Using Arduino / Programming Questions / Re: writing a program that follows a specific oder of execution on: April 04, 2013, 11:20:59 am
What input is there to indicate that a particular section has finished ?

Consider the use of while instead of if in your sections and test input(s) until there is an indication that a section has completed

Excellent!! thank you, I'll give that a try!

Thank you
Dave Pina
12  Using Arduino / Programming Questions / Re: writing a program that follows a specific oder of execution on: April 04, 2013, 11:19:56 am
I started to read
   your code, but it
       wandered across
           the page and
               I got tired of chasing it...


Well its clear you did not read my post, I also read your input and feedback but also appears to be a waste of my time chasing it as well.  This is a forum for which all walks of life come to learn, ask questions, share and provide experience and knowledge to those who are not as experienced.  So please, if you can not offer positive and/or constructive advice that will help those that are willing to use this forum for its purpose, then please DO NOT OFFER ANY INPUT.

Thank you
Dave Pina
13  Using Arduino / Programming Questions / writing a program that follows a specific oder of execution on: April 04, 2013, 10:15:11 am
Can any one offer any positive feedback and/or advice that will allow the code i have below to run and complete each section before moving to the next?

Thank you
Dave Pina

Code:

const int conv1 = 47;      // output pin the conveyor relay is attached to
const int turnhead = 48;   // output pin the turnhead relay is attached to

const int aggHopperGate1 = 49;      // output pin the gate1 relay is attached to
const int aggHopperGate2 = 50;      // output pin the gate2 relay is attached to
const int aggHopperGate3 = 51;      // output pin the gate3 relay is attached to

const int bindicatorlow1 = 25;          // input pin for the bin1 low signal
int bindicatorlowstatus1;
const int bindicatorlow2 = 26;          // input pin for the bin2 low signal
int bindicatorlowstatus2;
const int bindicatorlow3 = 27;          // input pin for the bin3 low signal
int bindicatorlowstatus3;

// Variables will change:
int bindicatorlow1_State;         // current state of the aggstoragebindicator1
int last_bindicatorlow1_State;     // previous state of the aggstoragebindicator1

const int turnheadBin1 = 28;      // input pin for turnhead position1
int turnheadposition1;     
const int turnheadBin2 = 29;      // input pin for turnhead position2
int turnheadposition2;
const int turnheadBin3 = 30;      // input pin for turnhead position3
int turnheadposition3;

// Variables will change:
int turnheadposition1_State;
int turnheadposition2_State;
int turnheadposition3_State;


void setup ()

{

  Serial.begin(9600);

  // sets all digital pins to OUTPUT state for conv1 and turnhead
  pinMode(conv1,   OUTPUT);
  pinMode(turnhead, OUTPUT);
  // sets all digital pins to OUTPUT state for each hopper gate
  pinMode(aggHopperGate1,  OUTPUT);
  pinMode(aggHopperGate2,  OUTPUT);
  pinMode(aggHopperGate3,  OUTPUT);

  // sets all digital pins to INPUT state for each bin low INPUT
  pinMode(bindicatorlow1, INPUT); 
  pinMode(bindicatorlow2, INPUT);
  pinMode(bindicatorlow3, INPUT);
  // Set all binlow input bins to HIGH state   
  digitalWrite(25, HIGH);
  digitalWrite(26, HIGH);
  digitalWrite(27, HIGH);

  // sets all digital pins to INPUT state for each turnhead position
  pinMode(turnheadBin1, INPUT);
  pinMode(turnheadBin2, INPUT);
  pinMode(turnheadBin3, INPUT);
  // Set all trunhead input bins to HIGH state
  digitalWrite(28, HIGH);
  digitalWrite(29, HIGH);
  digitalWrite(30, HIGH);

}


void loop()
{
  bindicatorlowstatus1 = digitalRead(bindicatorlow1);
  bindicatorlowstatus2 = digitalRead(bindicatorlow2);
  bindicatorlowstatus3 = digitalRead(bindicatorlow3);
 
 
//################################################## RUN SECETION 1 ###########################################################

        if  (( bindicatorlowstatus1 == LOW) || (bindicatorlowstatus2 == LOW) || (bindicatorlowstatus3 == LOW)){
          digitalWrite(conv1, LOW); //start conveyor 1     
          delay(2000);
          Serial.write("conveyor 1 has started");
     
              if (bindicatorlowstatus1 == LOW){ //if its bindicator 1 thats LOW meaning the material has dropped we fill the plant
                digitalWrite(turnhead, LOW); //start turnhead
                turnheadposition1_State = digitalRead(turnheadBin1); //read current state of turnhead position for bin 1
                 
                if (turnheadposition1_State = LOW){ //if turnhead has reached bin 1 position STOP turnhead
                digitalWrite(turnhead, HIGH); //stop turnhead
       
                delay(4000); //wait 4 seconds
                digitalWrite(aggHopperGate1, LOW); //open aggHopperGate1
               
                    if(bindicatorlowstatus1 == HIGH);{//bin has reached full close gate
                    digitalWrite(aggHopperGate1, HIGH);//close aggHopperGate1
                    }
                 }
              }
             
//##################################### WAIT TILL SECTION 1 IS COMPLETE THEN RUN SECETION 2 ############################################

              if (bindicatorlowstatus2 == LOW){ //if its bindicator 1 thats LOW meaning the material has dropped we fill the plant
                digitalWrite(turnhead, LOW); //start turnhead
                turnheadposition2_State = digitalRead(turnheadBin2); //read current state of turnhead position for bin 1
                 
                if (turnheadposition2_State = LOW){ //if turnhead has reached bin 1 position
                digitalWrite(turnhead, HIGH); //stop turnhead
       
                delay(4000); //wait 4 seconds
                digitalWrite(aggHopperGate2, LOW); //open aggHopperGate1
               
                    if(bindicatorlowstatus2 == HIGH);{//bin has reached full limit close gate
                    digitalWrite(aggHopperGate2, HIGH);//close aggHopperGate1
                    }
                 }
              }
             
//######################################## WAIT TILL SECTION 2 IS COMPLETE THEN RUN SECETION 3 ###########################################

              if (bindicatorlowstatus3 == LOW){ //if its bindicator 1 thats LOW meaning the material has dropped we fill the plant
                digitalWrite(turnhead, LOW); //start turnhead
                turnheadposition3_State = digitalRead(turnheadBin3); //read current state of turnhead position for bin 1
               
                if (turnheadposition3_State = LOW){ //if turnhead has reached bin 1 position
                digitalWrite(turnhead, HIGH); //stop turnhead
       
                delay(4000); //wait 4 seconds
                digitalWrite(aggHopperGate3, LOW); //open aggHopperGate1
               
                    if(bindicatorlowstatus3 == HIGH);{//bin has reached full limit close gate
                    digitalWrite(aggHopperGate3, HIGH);//close aggHopperGate1
                    }
                 }
              }                 
        }
}

//################################################REPEAT SECTION 1, 2, 3 ###########################################################


14  Using Arduino / Programming Questions / Re: Programming Question with a Color SmartGPU O'LED display on: February 10, 2013, 02:46:07 pm
I am glad that your code runs, but if you have not allocated more space for the print buffers then I can't help feeling that you are heading for a fall at some time as you don't know what is being overwritten when you put more data into an array than its declared size.

Ah, yes i see....thank you again!  I'll make sure to follow your advice and allocate more space.  I'll be sure to send you a video soon.

Thank you!!
15  Using Arduino / Programming Questions / Re: Programming Question with a Color SmartGPU O'LED display on: February 06, 2013, 07:35:01 pm
Start by declaring the 3 arrays as globals with enough elements to hold the strings as Paul has explained.  Within reason a larger array than necessary is OK.  Then move on to fix the other issues with data types.


Hi Bob,
Thank you for your input, and I appreciate your recommendations but it appears my code works perfectly except for a very small change in the Loop.  I experimented a little with delays and changing the "TRANS" to "FILL" in order to prevent re-write distortion.   I was shocked to see the whole system working great!!   When I have a chance I'll post some pics and a video.

Thank you again!
Pages: [1] 2 3 ... 7