Show Posts
Pages: 1 [2] 3 4 ... 6
16  Using Arduino / Project Guidance / Re: anti-tamper circuit for Arduino Mega on: March 04, 2011, 12:37:07 pm
Thanks for the responses, just to clarify, the arduino device will be writing data to an SD card sealed inside the same box. The anti-tamper device is needed to guarantee the integrity of the data on the SD card, I'm not trying to stop anyone from opening the box, I just want to ensure that if they do I get to know about it! It doesn't mater if the persons who opens the box knows he's been caught, but he mustn't be able 'reset' anything or cover his tracks in any way, that why it needs to be something electrical, rather than something mechanical.
17  Using Arduino / Project Guidance / anti-tamper circuit for Arduino Mega on: March 04, 2011, 06:42:13 am

I need to make an arduino Mega tamper-evident. The traditional way of doing this is to put a micro-switch under the lid of the box that the device is in and when the lid is removed the switch operates.

I need to be able to detect that this has happened even when the power is disconnected and the processor isn't running. Any suggestions as to how to do this? I'm thinking something along the lines of a normally charged capacitor that get's discharged when the microswitch closes. This can be connected to one of the input pins, and as soon as the processor is powered up the state of the pin is checked and thus the tampering has been detected.

I suspect that this method probably wouldn't work because the capacitor would lose it charge naturaly over just a few hours. Another option would probably be to use a button cell to keep the capacitor charged up, but then I'd have to have some circuitry to ensure the cell gets charged up.

Is there a better way? has anyone done this before and is there a circuit diagram available? I guess I'm looking for some sort of one byte storage device that will work with no power, does such a thing exist?

18  Using Arduino / Programming Questions / Re: Memory Management on: February 22, 2011, 03:32:47 am
Thanks, that 2nd link was particularly informative.

Most of my librarys are large and require extra hardware, so I'm niot sure ther'd be much to gain by posting the whole thing here.

Thanks guys
19  Using Arduino / Programming Questions / Memory Management on: February 21, 2011, 04:33:41 pm
Can I use alloc() to load a whole class into memory? (I guess I mean a whole object based on a class), and then use free() afterwards?

I’ve written a project based on a dozen or more library’s I’ve written. I’ve estimated the memory footprint of some of the larger objects to be about 500 bytes (I do quite a bit of string manipulation which seems to take up a lot of space). Several of those objects are used once and once only during the ‘setup()’ part of the sketch. My (limited) understanding is that this memory once allocated stays there permanently, even if the object doesn’t get used again, is this correct?

My application is running (very) low on memory, is there a way of freeing up this memory after the object has done what it’s got to do?

Also, is there a tutorial on memory management directed specifically to the arduino? I’ve tried to read-up on this subject, but a lot of the general C and c++ stuff I read is often different from what I read on this forum.

20  Using Arduino / Programming Questions / Re: Constructor code on: February 11, 2011, 04:50:34 am
What's the difference between the 'actual arduino program' and a 'sketch'?

Sounds like the begining of a whole new subject for me, is there a link to some information on this you could send me?


21  Using Arduino / Programming Questions / Re: Constructor code on: February 10, 2011, 05:50:23 pm
Thanks, what is the 'init' call?

Although the constructor code is only one line, it creates a file on an SD card, so involves calls to half a dozen library's - including it here probably wouldn't help.
22  Using Arduino / Programming Questions / Constructor code on: February 10, 2011, 05:34:08 pm
I’ve just solved a problem I had with code within a constructor. Although the problem is now solved, can anyone give me an explanation.

I had a working sketch and a class library. The sketch created an object (based on my class) in the declarations section (i.e. before the setup() bit). This worked fine until I added some code to the constructor, as soon as I did this the sketch wouldn’t even start. I solved the problem by adding a begin() section to the class and moving the code that was in the constructor to begin(). I then called the begin() from within the setup(). It all works fine again.


I’ve put code within other constructors before without problems, the only difference this time is that my code involved calls to multiple objects and other classes. Most of the stuff I normally add to constructors is just to initialise a few variables.

Whats the difference here?

23  Using Arduino / Programming Questions / General advice on de-bugging on: February 06, 2011, 01:25:44 pm

Sorry for the length of this post, I’m looking for some general advice on debugging not for the answer to a particular question

I’m trying to build an arduino application based on some off-the-shelf shields, a little bit of custom hardware and about 20+ class librarys, (some that I’ve written, some that I’ve found on the web and heavily modified (for example the GSM shield library from the hardware kitchen) and some that I’ve taken from the web and have used without changes (the SDfat library for example).

I’ve been working on each library in isolation and written various test scripts to test all of the functionality in each library. On their own each library (and hardware) works ok. The main problems seem to occur when I start building larger applications that require several of these librarys together.

These are the sort of bugs/errors I’m talking about
1)   Application just won’t start running.
2)   Code gets to a certain point and then the whole thing ‘reboots’ and starts again at the beginning
3)   Character arrays get corrupted.
4)   Code seems to be running ok, but the overall results doesn’t seem to be correct.
5)   Code execution ‘jumps’ from where it should be running to some totally different part of the application

What tends to happen is that the errors only manifest themselves when I’ve got a large application, they’re often hard/impossible to reproduce in a test sketch for an individual library. I often find myself ‘fiddling’ with the code for a bit, the error then suddenly disappears (without me actually spotting a definitive error) then I carry on testing, only for the error (or a similar one) to re-appear somewhere else later.

I’m making the following assumptions, are they correct?
1)   The ultimate cause of the errors must be because something somewhere in my application is corrupting the data memory (I assume that program memory can’t get corrupted?)
2)   The errors are probably still present in my small test sketches but they don’t show up because the corruption that is occurring is only effecting un-allocated memory that isn’t being used by anything else. – it’s only as the size of the overall application builds and more memory gets used that the corruption problems starts to corrupt memory that actually being used.
3)   If I know a particular function hasn’t been called before a problem occurs, then I can be sure that function hasn’t corrupted anything?
4)   The most likely cause of a problem is likely to be setting an array index outside of it’s bounds i.e. temp
  • =y where x is 10 and the array only consists of 5 elements.
5)   Number variables (i.e. ints, longs and floats etc) are unlikely to cause corruption because if they overflow they will ‘wrap around’ rather than corrupt other memory.
6)   Any code that runs could be corrupting something, just because the error appears in function X doesn’t mean that function X is the cause.

My main de-bugging technique is to insert lots of ‘serial.print’ to see what point the processing has got to and see what’s in various variables and arrays. Is there a better way than this? One drawback seems to be that simply inserting a ‘serial.print’ seems effect the execution of the code and can cause the error to disappear or move.

In each of my test sketches I try to make the test recursive and introduce some random element to alter the flow on each iteration of the test. (for instance when testing the GSM module I generate pseudo random phone numbers and messages on each iteration) Is there a better way?

All advice gratefully received!

24  Using Arduino / Programming Questions / Re: strange array corruption on: February 05, 2011, 08:20:52 am
The ">" is basically the 'cursor' - it's the response back from the SMS module that you expect to see to indicate the previous command was processed. Sorry, should have made it clearer.
25  Using Arduino / Programming Questions / Re: strange array corruption on: February 05, 2011, 06:38:37 am
thanks Rob, I think you're miss-quoting. expected_resp_string is actually ">" and the result is...
WaitResp. Expected <>>
that also explains the extra ">".

My application is in a state of flux, info has moved, and I'm no longer using clean_buff - but the corruption is still the same. It's nice to know there's some things you can rely on!

Any thoughts on wether I should be using char or byte arrays as per my last post?

26  Using Arduino / Programming Questions / Re: strange array corruption on: February 05, 2011, 05:28:51 am
Thanks guys, lots of interesting stuff here, much of it is raising more questions.

The application I’m having trouble with involves sending and receiving SMS’s, thus I’m doing a lot of fiddling about with strings. I’m using an SMS shield from the HW kitchen, and my code is based a much-modified version of the SMS library they provide. The library involves sending text commands to the SMS module, and processing the text that comes back, I was curious from day one as to why the incoming data from the SMS module is held in a byte array, and not a char array, to me it seemed to me more sensible to hold and process ascii text in character array, is this not the case?

If I’m going to be processing text (in the form of SMS commands) should I be storing that text in byte arrays, or char arrays? The basic string manipulation commands ( strpy(), strcmp(), strcat() ) seem to work with either, or am I playing with fire here?

Several of the above post have shown how isolated elements within an array can be corrupted by explicitly setting an array element outside of the bounds of that array (i.e. trying to set the 12th element in a 10 element array). I assume this sort of corruption can’t occur from the normal string manipulation commands (ie strcat() and strcpy() ) because even if you do attempt to move/copy a 20 element array into a 10 element array, then the corruption has to be linear – by this I mean the first 10 elements will be handled correctly, and the next 10 memory locations will be corrupted in order. Is this right?


27  Using Arduino / Programming Questions / Re: strange array corruption on: February 04, 2011, 12:09:33 pm
Thanks Paul, I know that buffer overflows are the traditional cause of problems like this, but buffers are linear aren't they? so how does a buffer overflow corrupt only the 2nd and 5th character, without effecting others?

My application uses lots of char arrays (which may explain why I'm having such trouble tracking this problem down) but they all contain only printable characters, if one off these buffers is overflowing into the memory allocated for ", got <" then wouldn't the corruption take the form of ascii characters?
Dave - cleanBuffer() takes the output from my SMS module and strips out all the non-printing characters. heres the code...

void MiniGSM::cleanBuffer()
  clean_buff[0]=0;  //empty the array
  int i=0;
  int y=0;
  while (comm_buf[i] != 0)  //check all characters until the end
    if ((comm_buf[i] >= 32) && (comm_buf[i] <= 126))
      clean_buff[y] = char(comm_buf[i]);

  clean_buff[y] =0;  //stick a null terminator on the end
Thanks for your help guys
28  Using Arduino / Programming Questions / strange array corruption on: February 04, 2011, 05:21:26 am
Hi, anyone got any ideas about this one? – I’ve got a array of characters that I’m using to create and display various error messages. It’s all very basic, I’m not doing rocket science here but it’s getting corrupted straight away.
Here’s the code that populates and displays the array….
  if (ret_val != RX_FINISHED_STR_RECV)
    // Strip all the control characters from the output buffer, and use this to populate clean_buff...
    info[0]=0;   // reset string
    sprintf(info,"WaitResp. Expected <%s>",expected_resp_string);
    if (ret_val == RX_FINISHED_STR_NOT_RECV)
      strcat(info,", got <");     // this is the bit that's getting corrupted
      strcat(info,clean_buff);  // add the actual error message
    else if (ret_val == RX_TMOUT_ERR)
      strcat(info,". Timeout");
    Serial.println(info);                            // display message.
    loggerMiniGSM->writeLn(info);  // write message to log file (and echo to screen)


And here’s what I see on the screen…..
WaitResp. Expected <>>,çgotñ<+CMS ERROR: 310>
33:24:27 WaitResp. Expected <>>,çgotñ<+CMS ERROR: 310>

As you can see the characters immediately before and after the word ‘got’ have somehow been corrupted. The second line (with the timestamp) is also written to the logfile. (I check the logfile, and those characters are also corrupted there) So whats going on?

One of the things I don’t get how the array can get corrupted so quickly, - the error message is formed, and then it’s displayed straight away, no other functions are getting called in the meantime so what’s causing the corruption?
Also, the ‘info’ array is constantly being reset (i.e. info[0]=0;) and constantly been used by other functions without problems, and yet the same corruption is always appearing in the same place.

Other points….
Info is declared as “char info[90+1];”
The error is repeatable.
The array ‘info’ is available to all functions in the class, each of the functions use ‘info’ to display the error message in a similar manner, but none of those functions is there any similar corruption.
The arduino application is cycling through the same code, but the corruption doesn’t appear straight away. In the above example, the corruption after ‘got’ appeared after about five minutes, and the corruption before it about 5 minutes later.
The corruption doesn’t get any worse – the above example is after 33 hours of running.
The whole application involves a dozen librarys and external hardware, so I can’t really post the whole thing.
It’s running on an Mega2560

29  Using Arduino / Programming Questions / Re: Trivial code – strange behavior….. on: February 03, 2011, 06:37:52 am
Thanks Paul - you got it! the definitions are...
int sig_stren = 0;                 // Signal strength before message sent
unsigned long duration_millis = 0; // Time (in milliseconds) to send SMS (irrespective of success or failure)

If I change the code to....
    sprintf(info,"CheckAndSendSMS. Sim SMS. FAIL <%ld>ms. Sig str <%d>.<%d>",duration_millis,sig_stren,sig_stren);
    sprintf(info,"CheckAndSendSMS. Sim SMS. FAIL <%ld>ms. Sig str <%d>",duration_millis,sig_stren);
It now works!

Since the error was with the display of sig_stren I assumed that this was where the problem lay. I figured (incorrectly) that since duration_millis was displaying OK the code for it must also be OK. That'll learn me!


30  Using Arduino / Programming Questions / Trivial code – strange behavior….. on: February 03, 2011, 06:14:52 am

I've got some very basic coding here that isn't doing what I was expecting, have I missed something?

Here's the code, basically I'm displaying some error information after sending an SMS...
    Serial.print("sig_stren <");Serial.print(sig_stren);Serial.println(">.");
     sprintf(info,"CheckAndSendSMS. Sim SMS. FAIL <%d>ms. Sig str <%d>",duration_millis,sig_stren);
     sprintf(info,"CheckAndSendSMS. Sim SMS. FAIL <%d>ms. Sig str <%d>.<%d>",duration_millis,sig_stren,sig_stren);

And here's the output....
sig_stren <14>.
CheckAndSendSMS. Sim SMS. FAIL <2316>ms. Sig str <0>
CheckAndSendSMS. Sim SMS. FAIL <2316>ms. Sig str <0>.<14>
In the first use of sprintf I would expect sig_stren to be displayed within the 2nd set of chevrons, instead I get zero.
In the second use of sprintf I would expect in to be displayed twice, but it only gets displayed the 2nd time.

Whats going on?
Pages: 1 [2] 3 4 ... 6