Pages: [1]   Go Down
Author Topic: Arduino Serial Problems  (Read 1287 times)
0 Members and 1 Guest are viewing this topic.
Cambridge,UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
If at first you don't succeed; call it version 1.0
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I've got some code (there's a lot of it, hence why I'm not posting straight away) that polls two analog inputs, stores the values temporarily in RAM, then serves up a serial string consisting of a S/N and the two archived values.

Now, the code works, for a few minutes, then just seems to flake out, mid-string.

I'm using the default serial rate of 9600 bps, with a FT-232 Adapter board.

I've tried the code on a variety of boards (MEGA 1280, Mini Pro 328, Demilunovae and a selection of hand-built boards), to no avail...

Changing the program cycle frequency seems to have no effect, with the code eventually halting abruptly mid-string, every time(!).

Here's the function for sending the data string...

 
Quote
void transmit_packet(int RH,int temp)
{
  xb_awake();
  xb_init();
 // Serial.print("&");
   for (int i = 0; i<6;){
   Serial.print(serial);
   i++;}
 
  Serial.print(",");
 // Serial.print("T=");
  Serial.print(temp);
  Serial.print(",");
  Serial.print(RH);
  Serial.println("");
  xb_sleep();
}


And the main program flow...

Quote
void loop()                        //MAIN PROGRAM

  get_data();                      // Poll Analog Inputs
  transmit_packet(RH, temp);       // Pass data to xBee for transmission
  delay(transmission_delay);
  check_serial_num();
  
  loop();                          // Loop Around
}


I haven't included the get_data function, as I don't think it's causing any problems, but its pretty simple, read A0 and A1, store to variables RH and temp.

The code seems to be breaking mid-flow of transmit_packet, and it's left me at a loss...  :-/

Has anyone experienced anything similar when going heavy on the Serial.print function?

Thanks all,

Tom
« Last Edit: October 05, 2010, 07:43:47 am by tomfleet » Logged

0
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2855
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's your problem:

Code:
void loop()                        //MAIN PROGRAM
{
  get_data();                      // Poll Analog Inputs
  transmit_packet(RH, temp);       // Pass data to xBee for transmission
  delay(transmission_delay);
  check_serial_num();
  
  loop();                          // Loop Around [glow]<---- NOOOOO!!!!!!![/glow]
}

You should not have loop() calling itself as you will eventually smash the available stack space on the processor. loop() is called in a loop anyways...there is no need for you to keep calling it.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there.

I have a similar problem ith a NANO-board. That is that when I run a program that sends out strings (regular intervals ~ 1sec) the program seems to halt after a while when I don't read the data.
The program flow is monitored by an activity-led (13) when the data is sent. When I plug the USB back in or read data the program resets (values are re-initialized!)
The problem is that the board is intended for stand-alone use and sometimes can be monitored for correct functioning.

Anyone an idea?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 208
Posts: 12936
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Anyone an idea?
Create a new topic in the Software section where your problem can be discussed.

Post your entire Sketch using code tags.

Include a detailed description of what is happening and what you expect to happen.
Logged

Pages: [1]   Go Up
Jump to: