Show Posts
|
|
Pages: [1] 2
|
|
2
|
Using Arduino / Programming Questions / Receiving strings in F() as parameters.
|
on: April 01, 2013, 09:57:49 am
|
Hi 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 = SD.open("BB.TXT", FILE_WRITE); blackBox.println(in); blackBox.close(); }
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: addToBlackBox(F("hello"));
, 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: https://code.google.com/p/sdfatlib/downloads/detail?name=sdfatlib20130313.zip&can=2&q=.
|
|
|
|
|
5
|
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 
|
|
|
|
|
6
|
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: 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.
|
|
|
|
|
8
|
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: 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 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.
|
|
|
|
|
9
|
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 } ; ? 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 } };
|
|
|
|
|
10
|
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...
|
|
|
|
|
13
|
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 #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() 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: 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!
|
|
|
|
|