Show Posts
Pages: 1 [2] 3
16  Using Arduino / Programming Questions / Re: Half a string becomes garbage chars for mysterious reasons... on: March 31, 2013, 05:39:01 pm
So I tried a few things on v1e2, but to no avail. After that I just abandoned all that, and built a new version based on the very first version: v1e0. Now it seems to be working just fine.

WooHoo!

At least now I know strcmp  smiley-lol

Thanks!
17  Using Arduino / Programming Questions / Re: Half a string becomes garbage chars for mysterious reasons... on: March 31, 2013, 04:43:25 pm
OK. So far so good. I'll check out the arrays. And use strcmp in the very near future...
18  Using Arduino / Programming Questions / Half a string becomes garbage chars for mysterious reasons... on: March 31, 2013, 04:20:37 pm
Hi guys and girls

I'm currently busy with a project that receives phone calls, logs them, and sends reports to admin users via SMS. Admin users can also reset the values that are being logged via an SMS. I use a Seeeduino Stalker v2.3 and a GPRS Shield v1.4.

My problem is as follows:
Function sendTextMessage( char[] number, char[] messg ) sends an SMS containing messg as body to number. I use AT commands to achieve all this:

in: AT+CMGF=1\r                   <- "Please send a text message."
out: OK                               <- "Sure thing!"
in: AT + CMGS = "[number]"\r  <- "Here's the number."
out: OK                               <- "Thanks!"
in: [messg] ctrl-z \r               <- "The body..."
out: > [some gibberish] OK     <- "Your message is sent"

There is no question of whether or not this works. I've been using it successfully for quite a while now. The problem is: the first 6 characters of number come out as gibberish chars when I run my sketch. In previous versions of this project I used an identical version of sendTextMessage() with no problems. In fact, I made no huge changes in the programs' overall structure between the two versions, which are both attached. I also attached a sample output, containing the gibberish in line 52. I manually added line numbers afterward.

Having encountered a similar problem before, I immediately assumed the problem was related to memory, so I made the standard changes: Moved any non-changing Strings to PROGMEM, put all misc strings in F(). I also got a little memory measurement function off of the forums, and I call it at places of interest. Finally I added Serial printouts at the beginnings and ends of all relevant functions, to look for crashes or weird behavior. (">functionName + date/time = beginnig of funtion, <functionName + date/time = end of function")

According to the memory function, I never get close to filling up the RAM. You'll see those numbers on the sample output(lines 31, 34, 38, 40, 41, 43, 45). Furthermore, all of the functions seem to be behaving themselves.
Which sucks.

Please take a look. I know my code isn't super awesome. I am quite new to Arduino. Please tell me what steps I can take to further investigate and/or solve this problem. If it's a memory issue, please tell how you knew.

Please note that the previous version is quite stripped down, having no Serial outputs. For some reason I thought removing them would save memory. But the part of the program in question works perfectly, although there are other unrelated errors I'm fixing. The current version is also not perfected yet, with a few possible unrelated bugs.

Previous version: RemoteCallLoggerV1e1safe.ino
Current version: RemoteCallLoggerV1e2safe.ino

 smiley-lol
19  Using Arduino / Programming Questions / Re: Strugling with RTC on: March 28, 2013, 03:59:39 pm
Hi, I'm not the biggest expert, but here is something to start with:
Have you tested your Uno with any other code? Could be that the hardware isn't working right. Try loading this sketch first:
Code:
void setup()
{
Serial.begin( 9600 ); // Opens the serial line @ 9600 baud
delay( 10 );
Serial.println( "Hello, world" ); // prints out on the Serial monitor
}

void loop()
{
}

This should print "Hello World" on your serial monitor.

If this works, there is something weird about the RTC code you are trying to run. You should upload it, so we can take a look.
If the Hello World thing doesn't work, there is probably a big hardware problem.

This is just a starting point. Tell us what you find.
20  Using Arduino / Programming Questions / Re: Global variable value changes mysteriously between initialization and setup() on: January 31, 2013, 03:19:32 pm
 smiley-lol
lol, I see what you're saying.
Took me a while to see, I'm still working on my greek degree (engineering)
Silly me
21  Using Arduino / Programming Questions / Re: Global variable value changes mysteriously between initialization and setup() on: January 31, 2013, 02:42:01 pm
Also, I wrote this bit of code to make the transition between the new and old memory regimes smoother:

Code:
char* phoneBook(int a, int b)
{
 strcpy_P(strBuffer, (char*)pgm_read_word(&(numbers_table[a][b]))); // Necessary casts and dereferencing, just copy.
return strBuffer;
}


Would it matter if I made strBuffer a local variable? ie

Code:
char* phoneBook(int a, int b)
{
char[13] strBuffer;
 strcpy_P(strBuffer, (char*)pgm_read_word(&(numbers_table[a][b]))); // Necessary casts and dereferencing, just copy.
return strBuffer;
}

When I say "matter", I mean memory-wise.
22  Using Arduino / Programming Questions / Re: Global variable value changes mysteriously between initialization and setup() on: January 31, 2013, 02:07:31 pm
OK, I'm busy playing with PROGMEM, but I have 1 question:
As shown below, you declare and initialise all the prog_char arrays, and then place them into the structure. Is there a shorthand way of doing this?
Maybe something along the lines of

char[][3] list = { "aq", "er", "qw" } ;

instead of

char[3] str1 = "aq";
char[3] str2 = "er";
char[3] str3 = "qw";
char[][3] list = { str1, str2, str3 } ;

?

Code:
prog_char string_0[] PROGMEM = "+2xxxxxxxxx3";   // "String 0" etc are strings to store - change to suit.
prog_char string_1[] PROGMEM = "+2xxxxxxxxx0";
prog_char string_2[] PROGMEM = "+2xxxxxxxxx9";
prog_char string_3[] PROGMEM = "+2xxxxxxxxx4";
prog_char string_4[] PROGMEM = "+2xxxxxxxxx6";
prog_char string_5[] PROGMEM = "+2xxxxxxxxx6";
prog_char string_6[] PROGMEM = "+2xxxxxxxxx4";   // "String 0" etc are strings to store - change to suit.
prog_char string_7[] PROGMEM = "+2xxxxxxxxx4";
prog_char string_8[] PROGMEM = "+2xxxxxxxxx5";
prog_char string_9[] PROGMEM = "eeeeeeeeeeee";
prog_char string_a[] PROGMEM = "eeeeeeeeeeee";
prog_char string_b[] PROGMEM = "eeeeeeeeeeee";

// Then set up a table to refer to your strings.

PROGMEM const char *string_table[ 2 ][ 6 ] =    // change "string_table" name to suit
{ { 
  string_0,
  string_1,
  string_2,
  string_3,
  string_4,
  string_5 },
{
  string_6,
  string_7,
  string_8,
  string_9,
  string_a,
  string_b
}
};
23  Using Arduino / Programming Questions / Re: Global variable value changes mysteriously between initialization and setup() on: January 31, 2013, 12:33:30 pm
Well, I used F() on a bunch of my strings, and callsToday[ 0 ] is now 0, the way it should be.
As for the PROGMEM, I'm reading about it now, and it seems wonderful, but also complicated. It's going to take me a while to learn this.
Maybe someone (if they're feeling extremely charitable) can send me some example code for converting my 3d char arrays to PROGMEM arrays?
I've googled it, and found some info, but to make sense of it all is going to be quite a task...
24  Using Arduino / Programming Questions / Re: Global variable value changes mysteriously between initialization and setup() on: January 31, 2013, 11:14:16 am
Ah... It worked. Thanks.
25  Using Arduino / Programming Questions / Re: Global variable value changes mysteriously between initialization and setup() on: January 31, 2013, 10:34:17 am
Well, it's a Seeduino Stalker v2.3, and the website says its got 2 kB. I don't know how to check the amount of RAM I'm using smiley-confuse
26  Using Arduino / Programming Questions / Global variable value changes mysteriously between initialization and setup() on: January 31, 2013, 10:25:54 am
Hi, I'm building a little gizmo that logs phone calls, and can send its data to you via SMS. As I'm quite new here, I've encountered quite a few obstacles, but I'm now finally in the last stages of development.
The following problem, I think, is pretty isolated, so I'll put the appropriate code in this message, but I will also attach the whole thing, just in case. Please note: I'm still developing, so it's not that neat yet:

The problem:
I declared these global variables as follows
Code:
#include <SoftwareSerial.h> // required to send and receive AT commands from the GPRS Shield
#include <Wire.h> // required for I2C communication with the RTC

#define TELESCOPE_NUMS 0
#define ADMIN_NUMS 1

// pin numbers for RTC
#define DS3231_I2C_ADDRESS 104 // 0x68 // Address for RTC
#define DS3231_TIME_CAL_ADDR        0 // 0x00
#define DS3231_ALARM1_ADDR          7 // 0x07
#define DS3231_ALARM2_ADDR         11 // 0x0B
#define DS3231_CONTROL_ADDR        14 // 0x0E
#define DS3231_STATUS_ADDR         15 // 0x0F
//#define DS3231_AGING_OFFSET_ADDR   16 // 0x10
#define DS3231_TEMPERATURE_ADDR    17 // 0x11
// Declarations for GPRS shield
byte buffer[ 64 ]; // Buffer is used to transfer data from the GPRS line to the serial line
int count = 0, smsMemIndex;
char temp, lastCaller[13] = "blank", lastSmsSender[13] = "blank", smsBody[ 160 ];
boolean callIncoming = false, done = true, smsIncoming = false, smsBodyIncoming = false, airtimeBalanceIncoming = false, firstAirtimeCheck = false;

// Declarations for RTC
byte time[ 7 ]; // second, minute, hour, dow, day, month, year
byte time_A1[ 5 ]; // second_A1, minute_A1, hour_A1, day_A1, DY/DT
byte time_A2[ 4 ]; // minute_A2, hour_A2, day_A2, DY/DT
byte received[1]; // used to catch bytes sent from the clock
float temperature; // clock temperature is updated every 64 s

// Declarations for RemoteCallLogger
int phoneBookSize = 6;
char phoneBook[ 2 ][ 6 ][ 13 ] = {
  {
    "+27xxxxxxx3",
    "+27xxxxxxx0",
    "+27xxxxxxx9",  // telescope numbers
    "+27xxxxxxx4",
    "+27xxxxxxx6",
    "+27xxxxxxx2"                        }
  ,

  {
    "+27xxxxxxx4",
    "+27xxxxxxx4",
    "+2xxxxxxxxx5",  // admin numbers
    "eeeeeeeeeeee",
    "eeeeeeeeeeee",
    "eeeeeeeeeeee"                        }
};
char callerNames[ 2 ][ 6 ][ 6 ] = {
  {
    "TB1",
    "TB2",
    "TB3",   // telescope names
    "TB4",
    "TB5",
    "TB6"                   }
  ,
  {
    "Coert",
    "Ma",
    "Pa",
    "leeg",    // admin names
    "leeg",
    "leeg"                   }
};

char smsCommands[ 3 ][ 10 ] = {
  "REPORT\0", "RESET\0", "DIAL\0" }; // sms command strings
double airtimeBalance = 0.00;
double smsTariff = 0.00; // amount of airtime available, and cost per sms
int noOfCommands = 3, lastCommandIndex = -1;
int callsToday[ 6 ] = { // increments with every missed call from a telescope, resets every 24 hours
  0, 0, 0, 0, 0, 0};
int daysDown[ 6 ] = { // increments for each consecutive day there were no wissed call from a telescope, resets when a missed call is made
  0, 0, 0, 0, 0, 0};
int callsThisMonth[ 6 ] = { // increments with every missed call from a telescope, resets manually via sms
  0, 0, 0, 0, 0, 0 };
int lastMatchIdentifier = 0; // indicates whether the last missed call came from admin or a telescope
int lastMatchIndices[ 2 ] = { // indicates which one of each of the two phonebooks' numbers called last
  -1, -1 };
SoftwareSerial GPRS( 7, 8 ); // A softwareSerial line is defined for the GPRS Shield

And this is my setup()
Code:

void setup()
{
  Serial.begin(9600);
  delay(1000);

  // GPRS Shield startup code
  GPRS.begin( 9600 );
  delay(1000);
  setPowerStateTo(1);
  delay(1000);

  // RTC Startup code
  Wire.begin();
  delay(1000);
  for(int i = 0; i < 6; i++)
    Serial.println(callsToday[ i ]);

}

And my output:
Code:
4865
0
0
0
0
0

Question: I clearly initialized the array callsToday with all 0 values, so why is callsToday[0] = 4865?
And how can I fix it?

There isn't even a function I made that could have screwed with anything!
27  Using Arduino / Project Guidance / Re: Using GPRS Shield and RTC simultaneously on Stalker v2.3 on: January 26, 2013, 04:14:37 pm
I have connected pin 17 ( D17(A3) ) to the Uart pin R1 (or RI? I can't see) with a 10k resistor. Now I can read pin 17 for a power status (the pin goes high when the shield comes on).

Let me know if you think this will cause issues.
28  Using Arduino / Project Guidance / Re: Using GPRS Shield and RTC simultaneously on Stalker v2.3 on: January 26, 2013, 02:42:28 pm
Before I bent away these pins, I used them to check if the shield was on. I don't know why it worked, but it did. Now I need a new way to check if the shield is on. Any suggestions?
29  Using Arduino / Project Guidance / Re: Using GPRS Shield and RTC simultaneously on Stalker v2.3 on: January 26, 2013, 02:08:02 pm
Yeah, I got impatient, so I just bent them out of the way and tested.
It works smiley
I will probably cut them later.
Thanks
30  Using Arduino / Project Guidance / Using GPRS Shield and RTC simultaneously on Stalker v2.3 on: January 26, 2013, 04:07:28 am
Hi everybody

I am currently working on a device that logs incoming phone calls, and sends data to me via text message. I am using a Seeeduino Stalker v2.3 and a SIM 900 GPRS Shield v1.4.

One of the reasons I use the Stalker is because of it's nifty onboard Real Time Clock, which works great. I've also mastered controlling the GPRS Shield pretty well.

Yesterday I was unpleasantly surprised when I tried to use the two simultaneously. The GPRS Shield somehow prevents I2C communication with the RTC.

So I did some reading, and the only (relatively) clear guidance I could find was here:
http://www.seeedstudio.com/depot/seeeduino-stalker-v2-p-727.html?pages=3&cPath=80&r_q=q
( 2nd question from the bottom )

Here they claim I can simply cut the SDA and SCL pins, and it will sort out the problem. Apparently the shield doesn't use these pins at all. Is this true?

Before I perform irreversible surgery on my GPRS Shield, I'd like to have some more experienced opinions.
My Stalker and Shield are both newer versions than mentioned in the above website.

So, should I cut those pins?
Pages: 1 [2] 3