Show Posts
Pages: [1] 2 3
1  Using Arduino / Networking, Protocols, and Devices / Re: Data incoming via SoftwareSerial not detected on: July 26, 2013, 05:14:03 pm

Sorry if I haven't been here for a while, been busy...

I think I have found the source (and a possible solution) of this problem. It seems that my gprsReset() function sends the communication GPRS shield into some kind of brownout state. How and why exactly this happens is a topic on its own.

I am able to get the GPRS shield out of this state by sending the "AT" AT command, which is basically just a test command that returns "OK". Once this has been done, I am able to pick up incoming transmissions just fine. At the moment, my solution to the problem is to just send "AT" down the line every 20 seconds.

Just btw, I did run some memory tests on the sketch, and I always had around 700 bytes free, so I don't think that is a problem at the moment...

Thanks liudr  smiley
2  Using Arduino / Networking, Protocols, and Devices / Re: Data incoming via SoftwareSerial not detected on: July 22, 2013, 09:53:45 am
Hi liudr

Basic_AT.ino is a sketch that tests the AT capabilities of my setup. It works like a command line via the serial line, and I can use it to enter AT commands, as well as receive responses. This sketch is there just to illustrate roughly how the AT-side of my setup functions. I also mentioned that when I test my setup with this sketch, it behaves correctly.

Bluegum_Logger_2.ino is my main project and the source of all my problems.

File_maker_forum.ino is used to create all the files on the SD card Bluegum_Logger needs to work.

I will start to run a few memory tests, to see if that is my problem. I cannot do tests with the mega 2560. I only have access to Stalkers.

Thanks so far
3  Using Arduino / Networking, Protocols, and Devices / Data incoming via SoftwareSerial not detected on: July 20, 2013, 08:11:47 am

I'm currently building a logger using a Seeduino Stalker v2.3 and GPRS shield V2. I also use an SD card for saving log data and long strings. The sending and receiving of GPRS data is done with SoftwareSerial. I attached all relevant code. I've been successfully testing this device, adding bits of code for extra functionality. I am logging the level changes on two pins.

I have now reached a point where I want to start wrapping the project up, but now I am encountering a weird issue.
The program gets past the setup function, doing a thorough diagnostic routine. Then it enters the loop. The loop has 5 parts: First it makes sure I'm not stuck in an incorrect state. Then it goes through a switch that controls the action to be taken for each state. Then it logs(if neccesary). Then it checks if the GPRS shield has anything waiting in it's buffer.

This is the point where I am encountering problems: the command GPRS.available() isn't acting the way it should. I loaded my program onto the Stalker, allowed it to start, and called the GPRS shield with my phone. Even though I can hear it ringing on my phone, there is no reaction on my serial monitor. I know the program isn't stuck, because the watchdog timer would restart it, and I tested it with printouts. It also still logs exactly the way it should.

Note: I test the GPRS SoftwareSerial port right at the beginning of the program by sending "AT" and waiting for it to reply "OK". I also tested my setup with a simpler sketch("Basic AT").
File_maker creates all the files required for the successful operation.
Bluegum_logger_2 has worked correctly in the past. The problem started when I did some minor edits. I have tried to reverse most of this.

Please take a look. Is this a memory issue? Or a bug in SoftwareSerial? I am very frustrated.

4  Using Arduino / Networking, Protocols, and Devices / Re: Use of buffer causes loss of data on: July 16, 2013, 02:31:45 pm
Here's the code:

#include <SoftwareSerial.h>
#define MAX_AT_COMM_LEN_I 24 // Max length of incoming AT commands
SoftwareSerial GPRS( 7, 8 ); // A softwareSerial line is defined for the GPRS Shield
char buffer[MAX_AT_COMM_LEN_I + 1];
char temp;
void setup()
  buffer[MAX_AT_COMM_LEN_I] = '\0';

void loop()

// returns expected output....
 // if (GPRS.available())
  //  Serial.print((char);
 // returns unexpected output
 if (GPRS.available())

void powerUp()
  Serial.println("Powering Up SIM900");
  pinMode(9, OUTPUT);
  Serial.println("SIM900 Powered Up");

void addToBuffer(char ch) // Maintains a FIFO buffer.
{                         // In this buffer, chars will appear to move from the right to left of the buffer:
  // Adding 's' to the buffer #### will result in ###s.
  // Then adding '@' will result in ##s@
  // The buffers length is determined by the longest AT command we have to listen for.
  if( ((int)ch >= 20 && (int)ch <= 126) ) // ignores all whitespaces and garbage chars except space
    //  all chars in the buffer are moved one position to the right, and the new char is added to the end
    for(int i = 0; i < (MAX_AT_COMM_LEN_I - 1); i++)
      buffer[i] = buffer[i+1];
    buffer[MAX_AT_COMM_LEN_I - 1] = ch;
    Serial.print("b: ");

void wipeBuffer() // fills buffer with # chars
  for(int i = 0; i < MAX_AT_COMM_LEN_I; i++)
    buffer[i] = '#';
5  Using Arduino / Networking, Protocols, and Devices / Use of buffer causes loss of data on: July 16, 2013, 02:11:22 pm

I'm currently having a little trouble reading data from my GPRS shield V2 with my Seeeduino Stalker V2.3. In the attached code, directly printing from the GPRS to serial works good enough, printing all the data being sent. I commented that out.
The problem occurs when I try to use a buffer for the same purpose. If you look at the attached text file, you will see that the buffer readout misses the last 68 characters of the data. It also incorrectly reads a "9" and an "e" at the end of the buffer.

The code I attached is a replication of an error I am experiencing in a larger program that already uses this buffer without a problem. I copied the code directly, and isolated the problem.

Please help me understand this behaviour
6  Using Arduino / Programming Questions / Re: Passing a File object as a function parameter on: July 13, 2013, 11:38:32 am
7  Using Arduino / Programming Questions / Re: Passing a File object as a function parameter on: July 13, 2013, 11:14:23 am
Just for interests' sake and future reference: Mark, if one were to force the pointer, how would the second block of code in my original post look?
8  Using Arduino / Programming Questions / Re: Passing a File object as a function parameter on: July 13, 2013, 11:00:59 am
Ok, thanks guys. This really helps  smiley
9  Using Arduino / Programming Questions / Passing a File object as a function parameter on: July 13, 2013, 10:21:48 am

Let's say I have a function:
void doSomething( File file )

What exactly the function does, is not so important, but we may assume that the file object will be used to write data to an SD card, and will again be closed within the function. Basically:

void doSomething( File file )
  file ="FILE.TXT", FILE_WRITE);
  file.print(); // arbitrary data is added

Is the file object passed by value or by reference? I am worried about this because I want to avoid memory issues later on. If I can reuse one file object by reference, it is a great plus if I call doSomething( File file ) from a function that already contains a file object, ie:

void bigFunction()
  File file;
  file ="name.txt", FILE_READ);; // arbitrary file operation
  // We are done with file, but it remains in the memory.
  doSomething( file ); // Thus, reusing the same object makes sense.

If a copy of the file object is sent as a parameter (aka call by value), I would have another instance of the object sitting in the memory unnecessarily.

If it is sent by value, a little help adapting the syntax to pass it by reference would be appreciated.

I have been googling this, but most of the stuff I read left me uncertain. I also tried some of the RAM usage measurement functions, but their results reported no change in memory usage between the the different File and SD operations, so they also left me confused, as I expected a rise in memory usage with the initialization of the file objects.

To the slightly more experienced C++ programmers out there, this is hopefully a no-brainer.

10  Using Arduino / Microcontrollers / Re: ATmega328P: Watchdog timer stops program, but doesn't reset... on: July 09, 2013, 07:17:31 am
For petting the dog, wdt_reset() works fine. Only the wdt_enable() function seems to have a problem. So I'm happy :-)
11  Using Arduino / Microcontrollers / Re: ATmega328P: Watchdog timer stops program, but doesn't reset... on: July 09, 2013, 06:54:22 am
OK, the timer works now, and restarts everything every 8 seconds like it should. I used this code I got from

void watchdogOn() {
// Clear the reset flag, the WDRF bit (bit 3) of MCUSR.
MCUSR = MCUSR & B11110111;
// Set the WDCE bit (bit 4) and the WDE bit (bit 3)
// of WDTCSR. The WDCE bit must be set in order to
// change WDE or the watchdog prescalers. Setting the
// WDCE bit will allow updtaes to the prescalers and
// WDE for 4 clock cycles then it will be reset by
// hardware.
WDTCSR = WDTCSR | B00011000;

// Set the watchdog timeout prescaler value to 1024 K
// which will yeild a time-out interval of about 8.0 s.
WDTCSR = B00100001;

// Enable the watchdog timer interupt.
WDTCSR = WDTCSR | B01000000;
MCUSR = MCUSR & B11110111;


Now I'm just trying to come up with a way to pet the dog...

Thanks for the pointer, Coding Badly and fungus :-)
12  Using Arduino / Microcontrollers / Re: ATmega328P: Watchdog timer stops program, but doesn't reset... on: July 09, 2013, 05:18:53 am

I tested your code, and it only printed one line of "Eight seconds and...", and then froze. The same as my big sketch.

As for the gobbledygook: It is supposed to to use millis as a timer for 60 seconds before actually starting to neglect the watchdog, thus leaving me with a 68 second watchdog timer. But the error state in which the program is initialized bypasses this ( "...gobbledygook... || state == _ERROR_" ), so I don't think we need to worry about that right now. The only reason it looks a little big and scary is because I also catered for a millis rollover. Feel free to remove it.

Thanks so far :-)
13  Using Arduino / Microcontrollers / ATmega328P: Watchdog timer stops program, but doesn't reset... on: July 08, 2013, 02:42:37 pm
Hi all

I'm building a data logger using Seeeduino Stalker V2.3 and a GPRS V2.0 shield. It will be functioning at a remote location for very long(years, hopefully), so I don't want it to freeze up in the first week, and just stop working. I'm storing all data on an SD card, and I'm making it accessible via SMS, so an occasional reset won't hurt.

I want to use the built-in watchdog timer to reset it if the program freezes. As far as I understand it should work as follows (using the avr/wdt.h library):
You activate it with the "wdt_enable(CONST)" command in the setup. I used "wdt_enable(WDTO_8S)" for an 8 second watchdog timer.
After this the watchdog should regularly petted with the "wdt_reset()" command.
If the watchdog isn't petted within the specified time(in my case: 8 seconds), it bites, and resets the Stalker. This reset should have the same effect as pressing the reset button on the controller itself, causing the program to run from setup().

IMPORTANT: If my understanding of the watchdog timer is wrong, please correct it.

So if you look at my attached code, you will see this is what I have done. I activated the timer at the very top of my setup(), and I reset it in the function "stateTransitionMonitor", which is called at the top of loop(). Please note that I use a state machine architecture, and that I initialize the program to an error state only to demonstrate my problem. The idea is that it resets either when the error state is reached, or if it is stuck in any state other than _IDLE_ for too long.

If I run my code, the following happens:
The program gets through setup() fine, printing "Entering loop..." at it's end. Then it goes into stateTransitionMonitor(), where it prints "Watchdog missed" and "ERROR" for 8 seconds, just like it should.

Then it stops. Indefinitely. Which is wrong, right? It should be starting with setup() again, printing "Entering loop...", and repeating the events that happened just before.

So what's going wrong? How can I make it reset?

I googled this, and found slightly similar cases, but most of them had different hardware and solved their problems by burning a new bootloader. As an only slightly experienced Arduino enthusiast, I thought it might be wise to seek the forums advice before messing with the bootloader.

14  Using Arduino / Programming Questions / Re: Receiving strings in F() as parameters. on: April 01, 2013, 10:27:42 am
Thanks guys! My mistake was extremely dumb. I left out a space when I inserted the new data type, so the compiler didn't recognize it as valid data type. damn typo
15  Using Arduino / Programming Questions / Receiving strings in F() as parameters. on: April 01, 2013, 09:57:49 am

As part of a bigger project, I want to save my programs' general output strings to a text file on the SD card instead of sending it down Serial all the time. Doing this is straightforward:

#include <SPI.h> // for SD storage
#include <SD.h> // for SD storage
File blackBox;

void addToBlackBox(char* in)
  blackBox ="BB.TXT", FILE_WRITE);

This function works for well enough, but I need to save memory because of my elaborate program. The idea that seemed the simplest was to put all the non-changing strings I wanted on the SD card in F(), the flash memory. So I tried this:


, but the compiler complained about my parameter type in addToBlackBox(), claiming that it should be a const_FlashStringHelper* . So I changed it to that in the parameters, but then the compiler complained even more, claiming that "variable or field 'addToBlackBox' declared void". I tried poking around the class files of classes that had built-in print()s and println()s, but I couldn't really find out why println() doesn't care about whether it's arguments are in F() or not. Googling it didn't help much either, since I could find little documentation on F() itself.

Please share some experience. Maybe I should approach the entire situation differently? How can I allow addToBlackBox() to accept its' argument from the flash memory?

PS I'm using a Seeeduino Stalker V2.3, and I got my libraries for SD from here:
Pages: [1] 2 3