Show Posts
Pages: [1] 2 3 ... 35
1  Using Arduino / Networking, Protocols, and Devices / Re: Can't set static IP using WIZ811MJ Ethernet module (dynamic works) on: July 21, 2014, 08:12:50 pm
I forgot to mention.  I tried using  the same IP as the one dynamically given, and other unused IPs on the same LAN.  I've tested it in  two different locations.  There's nothing unusual about my default gateway or subnet.
2  Using Arduino / Networking, Protocols, and Devices / Can't set static IP using WIZ811MJ Ethernet module (dynamic works) on: July 21, 2014, 08:07:26 pm
I've got a WIZ811MJ Ethernet module.  I can start the Ethernet client just fine using
Code:
Ethernet.begin(mac);

But this uses a lot of memory, I want to set a static IP
Code:
Ethernet.begin(mac, ip);

But it doesn't work, I Just get back 0,0,0,0 when I print the IP address.

The WIZ811MJ is connected to a Moteino.  A Moteino is Uno compatible, ATMega328P, plus it has a transceiver radio.

Here's my test code
Code:
#include <SPI.h>
#include <Ethernet.h>  // Modified by SurferTim to allow user selectable SS pin, see bit.ly/1nvz2ye

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC };
IPAddress ip( 192, 168,  46, 137 );

void setup() {
  Serial.begin(9600);
  Ethernet.select(9);  // Moteino radio uses D10 for SS
  Ethernet.begin(mac, ip);
  Serial.println(Ethernet.localIP());
}

void loop() { }
3  Using Arduino / Sensors / Re: Swimming Pool Water Level Sensor on: July 21, 2014, 10:19:04 am
Hello ScottG

Seems like you found an elegant solution to a problem I would like to solve. One year into it, how has your solution performed? Did you get reliable readings? How often did you end up having to change the battery?

It works great.  It's very reliable.  I think one battery will last all summer.  The battery I'm using now was installed May 28, so it's been almost 2 months.  You can see the battery voltage over time on Xively (it's channel 15).  I've got all the code on GitHub.

I did have an unusual problem the other day.  The program adds water in 15 minute increments when it senses the water level is low.  I get a text message every time this happens.  I got four text messages over an hour indicating the pool just kept adding water. I knew that wasn't right.  So I went home and discovered a chipmunk holding onto the float, trying not to drown.  The sensor just thought it was low water continuously.  That chipmunk was lucky I went home to check on things.

I need to make my code a little smarter so it waits a bit before adding water right away.  I do have a 120 minute per day max on the water fill, but I'm going to lower it to 60.  I typically only need 15 to 30 minutes a day for water.

4  Using Arduino / Programming Questions / Re: calculate running 60 minute total on: July 19, 2014, 01:48:53 pm
Here's what I came up with.  I haven't tested it yet.
rainCounter is a global byte and it's basically a pulse counter from the rain gauge.  It just counts up by one every time the rain gauge measuring cups tips.  When it reaches 255, it just rolls over to zero and keeps on going.

Code:
void updateRainAccum()
{
  static uint8_t rainEachMinute[60]; // array holds incremental rain for each minute of the hour
  static uint8_t prevRainCnt = 0;    // rain count (not incremental) from previous minute
 
  if ( isNewMinute() )
  {
    DateTime now = rtc.now();
    uint8_t newMinute = now.minute();
   
    // Calculate new rain since since the last minute
    int newRain; // incremental new rain since last minute
    if ( rainCounter < prevRainCnt )
    { newRain = (256 - prevRainCnt) + rainCounter; } // counter has rolled over
    else
    { newRain = rainCounter - prevRainCnt; }
   
    // add new rain and remove rain from an hour ago
    loopData.rainRate = loopData.rainRate + newRain - rainEachMinute[newMinute];   
     
    rainEachMinute[newMinute] = newRain;  // Update array with latest rain amount
    prevRainCnt = rainCounter;
   
    // Increment daily rain counter
    loopData.dayRain += newRain;
  }

  // reset daily rain accumulation
  if ( isNewDay() );
  { loopData.dayRain = 0; }
 
} // end updateRainAccum()
5  Using Arduino / Programming Questions / Re: calculate running 60 minute total on: July 17, 2014, 10:36:22 am
Yes, that's how I understood your original post. See my suggestion above.
I was looking at econjacks code and missed your post.  I like your suggestion.  I prefer to make the code more "elegant" even if I'll never notice the performance difference.  Thank you!

I'll post my code once I write it.

6  Using Arduino / Programming Questions / Re: calculate running 60 minute total on: July 17, 2014, 10:26:49 am
I'll be using the time.h library and getting the time from NTP time servers on the internet.

I don't want to reset the hourly rain to zero after an hour is over, I want to drop off any rain that's over an hour old.  For example lets say my rain came in like this (I'm skipping minutes with zero rain)

minute 1 = 0.1"
minute 2 = 0.2"
minute 3 = 0.1"
minute 55 = 0.3"

So at the end of the hour, my rain total would be all these added up = 0.7"
Assuming it's not still raining, at 1 hour and one minute, I'd drop off the 0.1" from an hour ago and my new hourly rain total would be .2 + .1 + 3. = 0.6
At 1 hour 2 minutes the hourly total would be .1 + .3 = .4"
At 1 hour and 55 minutes, I'd finally drop off all the old rain and my hourly rain total would be zero.


7  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?
8  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);
9  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.
10  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);
}
11  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?
12  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
13  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.   

14  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
15  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.

Pages: [1] 2 3 ... 35