Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Ethernet and UDP, correct connection practice on: January 28, 2013, 10:57:46 pm
Hello, On an Arduino Ethernet I've got a remote sensor app that connects to the internet once a day to get the time from a time server, then once a week posts the sensor readings.

My question is about correct connection practices and, unfortunately, I don't know that much about the inner workings of network transport.

So all the sample code I've found puts these two lines:

Code:
...
  if (Ethernet.begin(mac))
  {
    if (Udp.begin(localPort))
...

in the setup and then makes the various network calls in the loop.  But I think that assumes constant use of the connection.  My use of the connection is once a week and, after a few days, my connections fail.

Ideally I'd like to have an Ethernet.end and a Udp.end so I can put the .begin and .end in the loop at the time I want to make the connection, but those calls aren't available.

Can you please tell me what the proper method is to make a connection once a day and ensure that the connection does not fail?

I can post more code here if you'd like.

Thank you,

DougM


2  Development / Suggestions for the Arduino Project / Re: re-display serial monitor after upload? on: January 21, 2013, 02:21:40 pm
Ok, here's the perfect solution (for me).

when the user loads or creates and compiles/uploads a new file, do not pop up the serial monitor after the completion of upload.

However if the user invokes the serial monitor, for that file, for that session, pop the monitor up after all compile/upload events.

Thanks,

DougM
3  Using Arduino / Programming Questions / Re: concatenating date into array on: January 19, 2013, 02:21:09 pm
Thank you both for your responses - that makes much more sense.

I'll try the sprintf route tonight when I get back to it.

DougM

4  Using Arduino / Programming Questions / concatenating date into array on: January 18, 2013, 12:46:15 am
Hi, I'm trying to build up a string that contains a date. 

I have this array:
char msg[80];

I have this time object from <Time.h>
time_t pctime;

I go get the time from the interwebs using magic

then I can Serial.print(day(pctime));

and it works great.  Then I start building up my string:
strcpy(msg, "Day ");

But when I try to put the day in:
  strcat(msg, day(pctime));

I get this message:

error: invalid conversion from 'int' to 'const char*'
error: initializing argument 2 of 'char* strcat(char*, const char*)'

Sadly, my C acumen isn't sharp enough to figure out what any of that means.

Thank you for any insights you may have.

DougM









5  Topics / Science and Measurement / Re: Frequency Counter Library on: February 28, 2012, 11:23:31 pm
Thanks for the tip - I went back and edited.  I find it ironic that there are 35 buttons to put different smileys in the message but not one button to put code in the message.

DougM
6  Topics / Science and Measurement / Re: Frequency Counter Library on: February 28, 2012, 06:06:05 pm
I modified the cpp file to work with the mega2560.  It was pretty easy.  Uses pin 47 same as the 1280.  It works but sadly it does not play nice with the servo module (presumably they both use the same timer).

Code:
/*
  FreqCounter.h -
  Using Counter1 for counting Frequency on T1 / PD5 / digitalPin 5
  Uses Counter5 on the Mega digitalPin 47

  Using Timer2 for Gatetime generation

  Martin Nawrath KHM LAB3
  Kunsthochschule für Medien Köln
  Academy of Media Arts
  http://www.khm.de
  http://interface.khm.de/index.php/labor/experimente/

  History:
    Dec/08 - V0.0
    May/20  modified by mem to support Mega usting T5 /PL2 on digitalPin 47


  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/



#include <FreqCounter.h>


unsigned long FreqCounter::f_freq;

volatile unsigned char FreqCounter::f_ready;
volatile unsigned char FreqCounter::f_mlt;
volatile unsigned int FreqCounter::f_tics;
volatile unsigned int FreqCounter::f_period;
volatile unsigned int FreqCounter::f_comp;

// 16 bit timer defines added by mem to enable redifining the timer used
#if defined(__AVR_ATmega2560__)
#define TCCRnA TCCR5A
#define TCCRnB TCCR5B
#define TCNTn  TCNT5
#define TIFRn  TIFR5
#define TOVn   TOV5
#elif defined(__AVR_ATmega1280__)
#define TCCRnA TCCR5A
#define TCCRnB TCCR5B
#define TCNTn  TCNT5
#define TIFRn  TIFR5
#define TOVn   TOV5
#elif defined (__AVR_ATmega168__)
#define TCCRnA TCCR1A
#define TCCRnB TCCR1B
#define TCNTn  TCNT1
#define TIFRn  TIFR1
#define TOVn   TOV1
#endif
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

void FreqCounter::start(int ms) {

  f_period=ms/2;
  if (f_comp ==0) f_comp=1;

// hardware counter setup ( refer atmega168.pdf chapter 16-bit counter1)
  TCCRnA=0;     // reset timer/countern control register A
  TCCRnB=0;  // reset timer/countern control register A
  TCNTn=0;     // counter value = 0
  // set timer/counter1 hardware as counter , counts events on pin Tn ( arduino pin 5 on 168,47 on Mega )
  // normal mode, wgm10 .. wgm13 = 0
  sbi (TCCRnB ,CS10); // External clock source on Tn pin. Clock on rising edge.
  sbi (TCCRnB ,CS11);
  sbi (TCCRnB ,CS12);


  // timer2 setup / is used for frequency measurement gatetime generation
  // timer 2 presaler set to 256 / timer 2 clock = 16Mhz / 256 = 62500 Hz
  TCCR2A=0;
  TCCR2B=0;
  cbi (TCCR2B ,CS20);
  sbi (TCCR2B ,CS21);
  sbi (TCCR2B ,CS22);

  //set timer2 to CTC Mode
  cbi (TCCR2A ,WGM20);
  sbi (TCCR2A ,WGM21);
  cbi (TCCR2B ,WGM22);
  OCR2A = 124;


  f_ready=0;    // reset period measure flag
  f_tics=0;     // reset interrupt counter
  sbi (GTCCR,PSRASY); // reset presacler counting
  TCNT2=0; // timer2=0
  TCNTn=0; // Countern = 0

  cbi (TIMSK0,TOIE0); // disable Timer0  //disable  millis and delay
  sbi (TIMSK2,OCIE2A); // enable Timer2 Interrupt

  TCCRnB = TCCRnB | 7; //  Counter Clock source = pin Tn , start counting now

}



//******************************************************************
//  Timer2 Interrupt Service is invoked by hardware Timer2 every 2ms = 500 Hz
//  16Mhz / 256 / 125 = 500 Hz
//  here the gatetime generation for freq. measurement takes place:

ISR(TIMER2_COMPA_vect) {
// multiple 2ms = gate time = 100 ms
if (FreqCounter::f_tics >= FreqCounter::f_period) {
   // end of gate time, measurement ready

   // GateCalibration Value, set to zero error with reference frequency counter
    delayMicroseconds(FreqCounter::f_comp); // 0.01=1/ 0.1=12 / 1=120 sec
    TCCRnB = TCCRnB & ~7;   // Gate Off  / Counter Tn stopped
    cbi (TIMSK2,OCIE2A);    // disable Timer2 Interrupt
    sbi (TIMSK0,TOIE0);     // enable Timer0 again // millis and delay
    FreqCounter::f_ready=1; // set global flag for end count period

   // calculate now frequeny value
    FreqCounter::f_freq=0x10000 * FreqCounter::f_mlt;  // mult #overflows by 65636
    FreqCounter::f_freq += TCNTn; // add countern value
    FreqCounter::f_mlt=0;

  }
  FreqCounter::f_tics++; // count number of interrupt events
  if (TIFRn & 1) {    // if Timer/Counter n overflow flag
    FreqCounter::f_mlt++;   // count number of Countern overflows
    sbi(TIFRn,TOVn);  // clear Timer/Counter n overflow flag
  }
  // PORTB = PORTB ^ 32;  // int activity test
}


7  Using Arduino / Programming Questions / Re: time delay in interrupt on: May 19, 2011, 03:02:59 pm
Nice!

final (pertinent parts of)code:

Code:
#define F_CPU 16000000UL  // 16 MHz

#include <util/delay.h>

attachInterrupt(3, HAInt, CHANGE);

void HAInt()
{
   _delay_us (hallDelay);
   digitalWrite(HAOut, digitalRead(HAInt3));
}

Thanks so much!

DougM
8  Using Arduino / Programming Questions / Re: time delay in interrupt on: May 19, 2011, 02:25:10 pm
re:

>
> Are you hoping to get a 9 millisecond delay in your ISR?
>
no, I really don't know but I'm guessing the range could be anywhere from 20uS to 2mS

I've got 3 signals I need to condition.  I realize that putting delays in ISR's isn't good, but this is a proof of concept, not a final implementation.  the final implementation will use a hardware delay - I am using Arduino to determine what that delay is.

Thanks,

DougM
9  Using Arduino / Programming Questions / time delay in interrupt on: May 19, 2011, 02:09:36 pm
I have what I thought was a simple task, to insert a short time delay in a signal (in this case the output from a hall sensor (signal transition every 9ms)) via the use of an interrupt and a simple loop:

Code:
void HAInt()
{
   for (unsigned long i = 0;i<5;i++);
   digitalWrite(HAOut, digitalRead(HAInt3));
}

  attachInterrupt(3, HAInt, CHANGE);

Interestingly, no matter what number I put in the for loop (5, 50, 500, 5000, 50000, 500000) it has no effect on when the digitalWrite event occurs.  Could this be because the compiler sees that the for loop does nothing and optimizes it out?

Since I can't use delay() functions in interrupts what is the proper method of inserting a time delay?

Thank you,

DougM
10  Development / Suggestions for the Arduino Project / re-display serial monitor after upload? on: February 15, 2011, 10:06:47 pm
Would it be possible for you to add an option that will automatically re-display the serial monitor window after an upload if it was previously displayed?  I find every time I upload to the board I have to go click on the button again.

Thank you,

DougM
Pages: [1]