Pages: [1]   Go Down
Author Topic: Stepping through a sketch  (Read 1808 times)
0 Members and 1 Guest are viewing this topic.
Buena Vista, CO
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a way to single step through your code as the program executes in the Arduino? I am trying to understand how to use the Sparkfun expander board by running the code at http;//code.google.com/p/I2c-dio-pcf8575c/. I can not find any simpler examples that do both input and output. It would be easier to figure out by single stepping and watching variables. I'm new to c++ and still struggling to understand it all.  I need 5 digital inputs and 13 digital outputs for my application so the expander is ideal. At least one word needs to combine inputs and outputs to get to that number. Is this possible? Otherwise I'll do 8 outputs with the expander and the rest directly on the Duemilanove. I just wanted my project to be cleaner by having all connections to same place.

Jim
Logged

8000ft above the average

PDX
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No there is no way to step through the code on your Arduino in the Arduino environment.

You can use the analog pins as digital I/O on the Arduino though, which gives you a total of 20 digital I/O pins, 18 if you want to use serial. So you should even need an expander board for this project.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26631
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The alternative to stepping is sprinkling your code with debug prints.
Don't go overboard, though, or you'll run out of RAM. (there are ways around this, though, involving PROGMEM)
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Buena Vista, CO
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was hoping to use the serial pins for a future add -on, the is why the expander seemed so useful. Actually the best solution would be a simpler example of how to use the expander, but that might be too much to hope for.
Jim
Logged

8000ft above the average

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14048
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The alternative to stepping is sprinkling your code with debug prints.
Don't go overboard, though, or you'll run out of RAM. (there are ways around this, though, involving PROGMEM)

Besides debug statements you might use a step() function to hold the program, furthermore consider to dump the vars under scrutiny in the step() function .  (works for global vars only I know)

Code:
void setup()
{
  Serial.begin(115200);
  // ...
}

void loop()
{
  // some code
  step(1); 
  // some code
  step(2);
  // some code
  step(3);
// etc
}

void step(int place)
{
  // dump vars here
  Serial.print ("debug: "); Serial.println (place, DEC);
  // dump relevant vars
  while (Serial.Available() == 0);
  Serial.Read();
}
Instead of Serial.Available() an digitalRead() could be used to hold the code
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PDX
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I made a typo earlier, you shouldn't need the expander for this project, even if you want to use serial.
If you want to use this project to get to know the expander, that's another situation, though the expander only has 16 I/O pins, and by your description you need 18.

I can't get your google code link to work, so I can't help you with that code. I looked at the sparkfun page (this is the one that uses the 8575 chip correct?), their examples are pretty close to worthless though. Have you looked at the chips data sheet yet? If not this would be a good place to start, give us a link and we can take a look at it also.

Just a question, what do mean by "At least one word needs to combine inputs and outputs to get to that number."
Logged

NZ
Offline Offline
Sr. Member
****
Karma: 0
Posts: 390
Turtle in a hard shell
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@egdinger
I think he means that he needs to make 1 of the ports on the expander do both input and output.

From his comment above "I need 5 digital inputs and 13 digital outputs ". Each port on the expander has 8 IO, so he needs to configure 1 of the ports to have 5 inputs and 3 outputs, and the other port to be entirely outputs. That said, he is still 2 outputs short, as 13 + 5 != 16.

That is my take on it anyway. I have used the Microchip range of IO expanders and they work great, I havent used the ones mentioned. the MCP23017 and MCP23S17 (I2c and SPI versions).

James
Logged

Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Besides debug statements you might use a step() function to hold the program, furthermore consider to dump the vars under scrutiny in the step() function .  (works for global vars only I know)

Yep, I second this.  Sometimes I do a hardware version, where I wait for a button press in the 'step()' and use status LED's or an LCD readout to tell me what I'm looking for.

Also...  MCP23018 is awesome.  Highly recommend it.
Logged


Buena Vista, CO
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My bad, I need 11 output and 5 inputs, which is 16 total. Sorry "old age strikes again". Yes, I need to mix I and O in one byte to get the required ports.

Jim
Logged

8000ft above the average

NZ
Offline Offline
Sr. Member
****
Karma: 0
Posts: 390
Turtle in a hard shell
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also...  MCP23018 is awesome.  Highly recommend it.

Oooo havent seen the 23018 before...
Oh its capable of a higher bus speed, is that the only difference? Arduino cant do that anyway.
And they are cheap (both 23017 and 23018). <$2US a chip.
Logged

Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like it.  I don't mean to say the MCP23017 is NOT awesome.  018 is the only one I have experience with.
Logged


Pages: [1]   Go Up
Jump to: