Show Posts
Pages: 1 ... 5 6 [7] 8 9
91  Using Arduino / Programming Questions / Baud rates and resistors. on: August 11, 2012, 04:42:40 am
Hi all.

A little question for you all. Do different baud rates require different pullup resistors for the receive pin?

Thanks.
92  Using Arduino / Programming Questions / Re: Little coding help needed please. on: August 02, 2012, 03:58:55 pm
Some good advice is coming here so thanks. As you can see i already have some error checking going on with the byte i counter and further on in my code i have header checking of the received data that is all working well. I don't want to wait in this subroutine for data that is not gonna come so my sketch can make a error flag and move on or bailout and try again. Maybe the puting it all inside a
Code:
if (SoftwareSerial.available() > 0)
statement is the best way to stop this from happening if the IC am reading fails?
93  Using Arduino / Programming Questions / Re: Little coding help needed please. on: August 02, 2012, 03:42:00 pm
Quote
Using if's instead of whiles will prevent your subroutine from hanging. Error catching could also be implemented without stalling your program with while loops.

I understand your thinking with the if's instead but am new to Arduino/C and this is my first sketch so still learning and don't know how todo it with just if statements. I thought a while statement was the best way.
94  Using Arduino / Programming Questions / Re: Little coding help needed please. on: August 02, 2012, 03:27:32 pm
What my thinking is Arrch is if for some reason the IC am talking to fails my sketch will not hang inside that subroutine so i can set a error flag for it.

Thanks for the replies so far people.
95  Using Arduino / Programming Questions / Little coding help needed please. on: August 02, 2012, 03:12:21 pm
Hello all.

Hope someone can help here. Below is a small part of my sketch am coding that reads serial data of ASCII characters bigger then the space character untill a > character is received then subroutine exits. But if byte i gets to 16 before a > character is received the subroutine also exits. Works well.

So my problem now is that what if this subroutine is called but no device is attached/goes faulty?  My tests show that my sketch hangs inside this subroutine.

What i would like todo and think is the right way to go is to add a bailout function after lets say 10 seconds. Could someone help me implement this into the subroutine below? Am just not sure how todo it and if the millis() would be a good answer. Would be much grateful.

Code:
byte STN_read(char *str)
{
  int temp;
  byte i = 0;
 
  unsigned long time_out = millis();
 
  while((temp = SoftwareSerial.read()) != '>' && time_out <= 3000)
  {
    if(temp >= ' ')
    str[i++] = temp;
    if(i >= 16)
    return 0; //Read is probably bad.
  }
  str[i] = '\0';
  return 1; //Read is probably good.
}

Thanks all.
96  Using Arduino / Programming Questions / Re: SoftwareSerial library on: August 01, 2012, 02:24:14 pm
Code:
SoftwareSerial.begin(9600); //Initialize the software serial port.

If that helps.
97  Using Arduino / Programming Questions / Re: strcpy info on: August 01, 2012, 09:12:39 am
Sorry, edited to correct the CMD case. So i dont need to add \0 to my defines because strcpy does that for me and am i correct in thinking my str size is going to be 7?
98  Using Arduino / Programming Questions / Re: PSTR and it's use. on: August 01, 2012, 09:01:31 am
Thank you, i have this all sorted now and freed up some SRAM by using this function.
99  Using Arduino / Programming Questions / strcpy info on: August 01, 2012, 09:00:25 am
Hi again ppl.

Am using this line of code
Code:
strcpy_P(str, CMD);
that copies CMD into str and CMD is defined as
Code:
#define CMD  "ATSP2\r"
.

My question is does strcpy add NULL (\0) automatically at the end like sprintf does? Or if not is it good practice to have CMD as this instead
Code:
#define CMD  "ATSP2\r\0"
with the NULL added.

Many thanks.
100  Using Arduino / Programming Questions / Re: PSTR and it's use. on: August 01, 2012, 05:27:48 am
Does the PSTR/F macro work with the SoftwareSerial library? My sketch works with PSTR with Serial.print(); but don't with the SoftwareSerial.print();.
101  Using Arduino / Programming Questions / Re: Including/define version numbers in sketch. on: July 31, 2012, 04:09:42 pm
Many thanks to you all, learnt alot  smiley-wink.
102  Using Arduino / Programming Questions / Re: PSTR and it's use. on: July 31, 2012, 04:05:48 pm
Thank you  smiley.

I have used #define SoftwareVersion "v0.1.0\r" then used the Serial.println(F(SoftwareVersion));. Saves some space.
103  Using Arduino / Programming Questions / Re: PSTR and it's use. on: July 31, 2012, 03:47:02 pm
I get this error when i try to use Serial.println(F(SoftwareVersion));
SoftareVersion = const char SoftwareVersion[] = "v0_1_0";


warning: only initialized variables can be placed into program memory area
initializer fails to determine size of'__c'

Any ideas?
104  Using Arduino / Programming Questions / PSTR and it's use. on: July 31, 2012, 03:13:58 pm
Hello all again.

What is PSTR and how should it be used? I understand it's something about just using flash instead of flash and ram?

Many thanks ppl.
105  Using Arduino / Programming Questions / Re: Including/define version numbers in sketch. on: July 31, 2012, 03:01:50 pm
What does the F macro do?
Pages: 1 ... 5 6 [7] 8 9