Show Posts
Pages: 1 [2] 3 4 ... 35
16  Using Arduino / Programming Questions / calculate running 60 minute total on: July 17, 2014, 08:09:34 am
I have a weather station (Davis VP2) that will send my Arduino rain data.  It comes in as one byte and just counts up to 255 then rolls over.  Each digit is 0.1 inches of rain.  I want to send the data to Weather Underground and they want it as a rolling 60 minute total.  I was thinking of creating a 60 byte array (one element for each minute).  Then looping through the array to calculate the total.  As new data comes in for a particular minute, I'd overwrite the old data for that minute.  It seems like this approach should work okay, but I was wondering if there are other ways I could do this?
17  Using Arduino / Networking, Protocols, and Devices / Re: Problems with xbee.h v0.5 [SOLVED] on: July 02, 2014, 01:05:28 pm
Okay, I figured it out.  For my sketch that's running on a Leonardo, I need to use Serial1 instead of Serial, like this:

Serial1.begin(9600);
xbee.setSerial(Serial1);
18  Using Arduino / Networking, Protocols, and Devices / Re: Problems with xbee.h v0.5 on: July 02, 2014, 12:12:28 pm
I forgot to mention, one of my Xbees is used with a Leonardo, the other with an Mega.  Since Leonardo uses serial differently, maybe this is part of the problem.  Also, I'm using the xbees in API mode.
19  Using Arduino / Networking, Protocols, and Devices / Problems with xbee.h v0.5 on: July 01, 2014, 09:13:33 pm
I'm having trouble getting my Xbee (Series 1) to communicate.  They worked fine when I was using xbee.h library v0.4, but there was a change in v0.5 that's causing me problems.   The v0.5 change has to do with serial setup, here's the release note for it.

Originally I started started xbee like this:
Code:
Serial.begin(9600);
xbee.begin(9600);

With version 0.5, I'm supposed to do this (I think):
Code:
Serial.begin(9600);
xbee.setSerial(Serial);

I'm not using soft serial, just hard serial.

Here's the xbee library diff comparison for the changes from 0.4 to 0.5: xbee.h, xbee.cpp

Below are the Rx and Tx sketches.  Basically the two xbees are not able to communicate.  The error from the transmitter sketch is: "XBee did not provide a timely Tx Status Response"

Receiver sketch:
Code:
#include <XBee.h> 
#define PRINT_DEBUG       // comment out if you don't want anything to go to serial monitor
XBee xbee;
XBeeResponse response;
// create reusable response objects for responses we expect to handle
Rx16Response rx16;


void setup()
{
  Serial.begin(9600);
  #ifdef PRINT_DEBUG
    Serial.println("Xbee Rx/Coordinator setup()");
  #endif
  xbee.setSerial(Serial);


void loop()
{
  uint8_t option;           
  uint8_t signalStrength;     
  uint8_t dataLength;       
  static int16_t RxData[3];  // Array to hold data received
  uint16_t Tx_Id;            // Address of transmitter (MY ID)
 
    xbee.readPacket();
   
    if (xbee.getResponse().isAvailable())
    {
      // got something
      #ifdef PRINT_DEBUG
        Serial.println("Got Something:");
      #endif
     
      if (xbee.getResponse().getApiId() == RX_16_RESPONSE )
      {
        // got a Rx packet

       
        xbee.getResponse().getRx16Response(rx16);
        option = rx16.getOption();               
        dataLength = rx16.getDataLength();       

        Tx_Id = rx16.getRemoteAddress16();
        signalStrength = rx16.getRssi();
       
        for(int i=0; i < dataLength; i=i+2)
        {
          RxData[i/2]  = rx16.getData(i) << 8;
          RxData[i/2] |= rx16.getData(i+1);
     
          #ifdef PRINT_DEBUG
            // Print data received (16-bit integers that have been divided into 2 bytes)
            Serial.println(RxData[i/2]);
          #endif             
        }
        #ifdef PRINT_DEBUG
          Serial.print("Transmitter MY address: ");
          Serial.println(rx16.getRemoteAddress16(), HEX);
          Serial.print("Signal strength = ");
          Serial.println(signalStrength);
          Serial.print("Data Length = ");
          Serial.print(dataLength);
          Serial.println(" bytes");
        #endif
       
      }
      else
      {
      // not something we were expecting
      }
    }
    else if (xbee.getResponse().isError())
    { // Got something, but not a packet
      #ifdef PRINT_DEBUG
        Serial.print("Error reading packet.  Error code: "); 
        Serial.println(xbee.getResponse().getErrorCode());
      #endif
    } // End Got Something
    else
    {
      // xbee not available and no error
      #ifdef PRINT_DEBUG
        Serial.print("isAvailable(): "); 
        Serial.println(xbee.getResponse().isAvailable());
        Serial.print("Error reading packet.  Error code: "); 
        Serial.println(xbee.getResponse().getErrorCode());
      #endif
    }
   
    delay(1000);   
}

Transmitter sketch:
Code:
#include <XBee.h> 

#define PRINT_DEBUG       // comment out if you don't want anything to go to serial monitor
#define MY_ADDR_RX 0x250 

#define NUM_DATA_PTS   3 

// allocate array to hold bytes to send to other xbee.  Size is 2x the number if integers being sent 
uint8_t payload[NUM_DATA_PTS * 2];

XBee xbee;
// 16-bit addressing: Enter address of remote XBee, typically the coordinator
Tx16Request tx = Tx16Request(MY_ADDR_RX, payload, sizeof(payload));
TxStatusResponse txStatus;

void setup()
{
  Serial.begin(9600);
  #ifdef PRINT_DEBUG
    Serial.println("Xbee Tx/End Node - setup()");
  #endif
  xbee.setSerial(Serial);
}


void loop()
{
    int16_t xbeeData[NUM_DATA_PTS];  // Array to hold integers that will be sent to other xbee
 
    // Test data to send to other xbee
    xbeeData[0] = 1234;
    xbeeData[1] = 5678;
    xbeeData[2] = -500;
   
    // break down integers into two bytes and place in payload
    for(int i=0; i<NUM_DATA_PTS; i++)
    {
      payload[i*2]     = xbeeData[i] >> 8 & 0xff; // High byte - shift bits 8 places, 0xff masks off the upper 8 bits
      payload[(i*2)+1] = xbeeData[i] & 0xff;      // Low byte, just mask off the upper 8 bits

      #ifdef PRINT_DEBUG
        Serial.print("Data = ");
        Serial.print(xbeeData[i]);
        Serial.print(", payload high byte = ");
        Serial.print(payload[i*2]);
        Serial.print(", payload low byte = ");
        Serial.println(payload[(i*2)+1]);
      #endif
    }
    xbee.send(tx);
 
    // after sending a tx request, we expect a status response
    // wait up to 5 seconds for the status response
    if (xbee.readPacket(5000))
    {
        // got a response!
        #ifdef PRINT_DEBUG
          Serial.println("\nGot a response from receiver");
        #endif
       
        // should be a znet tx status           
        if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE)
        {
          xbee.getResponse().getZBTxStatusResponse(txStatus);
   
       // get the delivery status, 0 = OK, 1 = Error, 2 = Invalid Command, 3 = Invalid Parameter
          if (txStatus.getStatus() == SUCCESS)
          {
            // success.  time to celebrate
            #ifdef PRINT_DEBUG
              Serial.println("Tx Succeeded");
            #endif
          }
          else
          {
            // the remote XBee did not receive our packet. is it powered on?
            #ifdef PRINT_DEBUG
              Serial.print("\nTx Failed, xbee status = ");
              Serial.println(txStatus.getStatus());
            #endif
           }
        }     
    }
    else if (xbee.getResponse().isError())
    {
      #ifdef PRINT_DEBUG
        Serial.print("\nError reading packet.  Error code: "); 
        Serial.println(xbee.getResponse().getErrorCode());
      #endif
     
    }
    else
    {
      // local XBee did not provide a timely TX Status Response.  Radio is not configured properly or connected
      #ifdef PRINT_DEBUG
        Serial.println("\nXBee did not provide a timely Tx Status Response\n"); 
      #endif
     
    } // Finished waiting for XBee packet
   
    delay(1000);
}
20  Using Arduino / Programming Questions / Re: Multiple definitions error with TIMER0_OVF_vect on: May 28, 2014, 04:57:23 pm
You are now responsible for initializing everything else: timers for PWM, ADC, whatever else I can't think of right now.

That's pretty cool.  I don't know anything about initializing all this stuff, but I'm wondering if that's already being taken care of in the original program.  Can you tell me if that's the case?
21  Using Arduino / Programming Questions / Multiple definitions error with TIMER0_OVF_vect on: May 28, 2014, 01:52:55 pm
I'm using a program (written by someone else), that uses ISR(TIMER0_OVF_vect).  When I try to compile in Arduino IDE (v1.05)  I get a multiple definition error because Arduino's wiring.c also uses TIMER0_OVF_vect.  Wiring.c isn't used by this program, but I guess Arduino checks it anyway.   The author doesn't compile using the Arduino IDE, so he doesn't have to worry about this.
I don't know much about interrupts and don't know anything about which one TIMER0_OVF_vect represents.  How do I get rid of this error?  I have a feeling it's more complex then just renaming something.

The program can be found here: https://github.com/grbl/grbl/tree/dev
The specific file is  stepper.c, line 419
22  Using Arduino / General Electronics / Re: opto-coupler: transistor vs logic on: May 18, 2014, 10:00:29 pm
So you're saying that if you write a simple sketch that starts a stepper to spinning and monitors those input pins that then those inputs (D9,10,11) will report back Highs when there should be Lows and/or Lows when there should be Highs?
I'm not familiar enough with steppers and the gshield to write a sketch to that.  Maybe it's easy, I'm not sure. 

When I first installed the limit switches, I had the shields from the limit switch wires and the shields from the stepper motor wires all connected to the Arduino ground.  When I turned everything on, it immediately went into alarm mode because it thought a limit switch had been tripped.   If I reset the alarm, it would just go right back into alarm mode for a limit switch. 
The next thing I did was disconnect the motor shield from ground and just let it float.  This helped a lot, the machine didn't go into alarm mode as before. 
I put my scope on the input as shown in a previous photo and I looked at the signal under both scenarios above.  With the motor shield connected to ground I had big oscillations, ringing or something.  It was a couple volts p-p.  When I had the shield floating, it was much better. A number of people who have the same CNC router (a ShapeOko) report that they have problems with noise and the limit switches.  What I'm trying to do now is just decrease the noise as much as possible to minimize the chance of false limit switch triggers.   

23  Using Arduino / General Electronics / Limit switch Schematic on: May 18, 2014, 07:15:53 pm
Here's a schematic of my wiring (not including wires going to the stepper motors).
The gshield schematics can be found here:
https://github.com/synthetos/grblShield/tree/master/hardware/gshield_v5_schematic
24  Using Arduino / General Electronics / Noise on CNC limit switch wires on: May 18, 2014, 06:26:30 pm
Here's a picture of where my scope probes are connected and a few screenshots of what I'm seeing on the scope.  The ground wire for the scope is coming out of one of the unused terminal block pins.

25  Using Arduino / General Electronics / Noise on CNC limit switch wires on: May 18, 2014, 06:25:46 pm
Here are some pictures of my setup.  Inside the yellow electrical enclosure I have an Uno.  Plugged into the Uno is a gshield motor controller.  In the upper left is a proto board with some screw terminal blocks.  Into the top set of screw terminal blocks plug two push-button switches which then go to A0 and A1 on the Uno.  The 3 limit switch cables go into the screw terminal blocks on the right side of the proto board.  For the limit switches, I have the ground wire and shield connected together in the same opening in the terminal block.  On the X-axis limit switch you can see I have a 0.1uF cap, nothing on the other two.  On the bottom of the Uno (which you can't see) I have three 330 ohm  pull-up resistors for the limit switch lines, which are inputs D9,10,11 and the 5V pin.  The limit switches wires actually connect to the gshield, but it's a direct connection down to the Uno via the stacking header.  The ground on the proto board (and thus all the limit switches and push-buttons) comes from the ground pin next to D13.
The gsheild is powered by a 24 VDC power supply.  The Uno does not get power from the ghsield, instead it's powered by the USB cable from my laptop.
The three stepper motors are connected on the right side of the gshield.  The shields are not connected to ground, but they are connected to each other.  I initially had the stepper motor shields connected to ground, but this caused the Uno to think the limit switch was activated.  

I'm working on a schematic I'll upload shortly.

Edit: The limit switch wires have ferrite chokes right outside the yellow enclosure.
26  Using Arduino / General Electronics / Re: opto-coupler: transistor vs logic on: May 18, 2014, 03:53:10 pm
Quote
I'm showing the circuit using the normally-closed terminal.
@Runaway Pancake
Been telling him that for ages but he keeps on ignoring it.
I wasn't ignoring it, I appreciate all the feedback.  I did do some testing with normally closed switch - actually I just closed the limit switch to see if that made any difference with the noise I saw on the scope.  Unfortunately,  I didn't see any difference.  I thought I posted that on the forum, but apparently I didn't.
27  Using Arduino / General Electronics / Re: opto-coupler: transistor vs logic on: May 18, 2014, 01:54:34 pm
Quote
Can you explain why this would make it worse?
Because when the switch has been triggered it is only being pulled down with 1K5 which is not as hard as a direct pull to ground therefore making it more prone to interference.

What happened when you tried the fail safe option of having the switch normally connect to ground?

The way I see it you have a grounding problem.

Good point.  Do you have any suggestions for how I should filter out the noise?
28  Using Arduino / General Electronics / Re: opto-coupler: transistor vs logic on: May 18, 2014, 09:02:39 am
What ever made you think that would work?
I would imagine that is worse than ever.
Not worse, but not better either.  I wanted a low-pass filter to get rid of the noise on the limit switch line.  Can you explain why this would make it worse?
29  Using Arduino / General Electronics / Re: opto-coupler: transistor vs logic on: May 17, 2014, 10:09:16 pm
I tried the RC low-pass filter on one of the limit switch wires, it didn't seem to do much looking at my scope.  Attached is the circuit I used.  I used a 1.5k resistor.  Tomorrow I'll try 100k.
30  Using Arduino / General Electronics / Re: opto-coupler: transistor vs logic on: May 17, 2014, 07:34:00 pm
connect D9  between C1 and R2
R2 can have much higher resistans, 100 kohms.
0.1 uF and 100 kohms make an timeconstant (RC) of 10 ms
Pelle
Thanks. I'll give it a try.
Pages: 1 [2] 3 4 ... 35