Thursday 9 October 2014

Testing Arduino Code

There are a couple of ways that you can test your Arduino code, not least of which is compiling your sketch and then uploading it to your microprocessor and making sure it runs OK … however, that doesn’t help in revealing any problems in the code.

If there are major problems then, sure, the IDE will whine and you’ll hear about it. But what if there’s a silent problem in your code that you can’t necessarily find sooner?

I’m currently looking at using a C language IDE (CodeLite) as a testing ground for my code. I haven’t gone too far yet, so there are likely to be some issues (for instance, the byte data type is missing in GCC … apparently, so I’m using the char data type instead).

My thinking is that I should be able to use the C IDE to reveal any problems in my code by sending the data that I want to monitor to stdout and use stepping to inspect the values and variables as it goes along.

Other things to consider … a standard C application starts with int main() rather than void setup() and you have to explicitly define and call the loop() function, oh there are other differences that I’m sure to find along the way, but for simply testing function blocks to make sure that the data that my function is sending (and to a lesser extent, the function structure and flow), can be inspected discretely.

Playing with my Shift Register code, I created the following main.c file

code_grab

and then I ran the code …

cmd_grab

showing that the values being passed are correct.

I can also create a couple of different functions that do the same so that I can then have a look at them from an efficiency, memory and timing perspective to decide on which way is the best for my application.

Anyway, it’s all learning, poking and prodding. I’m not sure how others approach testing their Arduino code … but then, I’m a software tester by profession.

No comments:

Post a Comment

Paypal Donations

Donations to help me to keep up the lunacy are greatly appreciated, but NOT mandatory.