stepper motor drive and trellis help

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jmsturre
 
Posts: 13
Joined: Wed Jan 28, 2015 4:04 pm

stepper motor drive and trellis help

Post by jmsturre »

Hi. I'm building a robotic chess board using a trellis keypad #1616 and stepper motor driver #1438. There seems to be an issue when both are being used. The trellis works fine, but the steppers won't move, or only make <10 steps when they should be running hundreds. This problem is solved if I comment out anything referring to the trellis, making me believe there's some interference there. I'm using stackable headers on the motor driver, so the keypad and lcd screen are plugged into that. Is there any way I can get around this?
Here is my code, if that's helpful :http://BANNED.com/raw.php?i=Z9Gf0yQe

Thanks in advance for looking.

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: stepper motor drive and trellis help

Post by adafruit_support_bill »

The Trellis should not interfere with the motor controller. But you have a lot of code there. You may be running low on SRAM and experiencing a stack-crash.
There is a lot of room for optimization there - particularly in your printBoard function. Literal strings consume both Flash and SRAM - unless you instruct the compiler to keep them in Flash. There are a lot of literal strings there. 2 of which are replicated 64 times.
http://learn.adafruit.com/memories-of-an-arduino

User avatar
jmsturre
 
Posts: 13
Joined: Wed Jan 28, 2015 4:04 pm

Re: stepper motor drive and trellis help

Post by jmsturre »

Thanks for the reply, I didn't think it would be a memory problem since I was still showing plenty of room after compiling and uploading.

I'm going to dig through the link you gave me. I'm fairly new to this (as you can tell from my code) and this is the biggest programming project I've taken on yet. Do you have any tips on the code? I'd really like to compress that printboard function, but I don't know how and still make it print correctly. I won't need it after everything else is working, but it sure is nice to be able to tell the chess portion is actually working.

Any tips are great, my class hasn't taught me much about optimizing, or coding other than what I've got in my code.

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: stepper motor drive and trellis help

Post by adafruit_support_bill »

I didn't think it would be a memory problem since I was still showing plenty of room after compiling and uploading.
Flash memory usage is not the same thing as SRAM usage. The link above explains the different types of memory and how they are used.
Do you have any tips on the code? I'd really like to compress that printboard function, but I don't know how and still make it print correctly.
For one thing, you have an extra empty row and two empty columns in your board. Arrays indices are zero-based and if you write your code that way you will save some memory there. You should define your array as a 2 dimensional 8x8 array so you can address it more easily. http://www.cppforschool.com/tutorial/array2.html

The bulk of your printBoard() function could then be reduced to a nested 'for' loop, compressing nearly 400 lines to about 15 - with no repeated literal strings.

Code: Select all

for(int row = 0; row < 8; row++)
{
    for (int col = 0; col < 8; col++)
    {
        if (chessBoard[row,col] == 0) 
        {
            Serial.print("00 ");
        }
        else if (chessBoard[row,col] >= 1)
        {
            Serial.print(chessBoard[row,col]);
            Serial.print(" ");
        }
}

User avatar
jmsturre
 
Posts: 13
Joined: Wed Jan 28, 2015 4:04 pm

Re: stepper motor drive and trellis help

Post by jmsturre »

Thanks for the tip on the array! I knew there had to be a better way of doing it than what I had. I'll have to rewrite a bit, but learning a better way to write the code is always a good thing.

I'm going to keep digging, I'm sure there's a lot more I can do to tighten the code up. I feel like I'm using a lot of if's and for's and I'm missing a smoother way to use those too. I've got a lot more to learn.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”