Hello, I apologize in advance for my cluelessness, but I am trying to figure out how to run several stepper motors off of one arduino using the waveshare MCP23017 I/O extender and the ULN2003 Stepper motor driver. However, the only example code for the MCP23017 uses things like mcp.PinMode(...) and never just assigns something to a pin on the I/O extender, the way a pin is directly assigned to a stepper motor. When I try to do it, it only seems to use the pins on the arduino, and not the pins on the I/O board, even when I try using numbers greater than 13. I'm not really sure what I'm doing wrong at this point, and any help would be greatly appreciated. This is the code currently:
// Arduino stepper motor control code
#include <Wire.h>
#include "MCP23017.h"
#include <Stepper.h> // Include the header file
// change this to the number of steps on your motor
#define STEPS 160
MCP23017 mcp;
byte pin1 = 21;
byte pin2 = 22;
byte pin3 = 23;
byte pin4 = 24;
// create an instance of the stepper class using the steps and pins
Stepper stepper(STEPS, pin1, pin2, pin3, pin4);
int val = 0;
void setup() {
Serial.begin(9600);
stepper.setSpeed(200);
mcp.begin(7);
mcp.pinMode(21, OUTPUT);
mcp.pinMode(22, OUTPUT);
mcp.pinMode(23, OUTPUT);
mcp.pinMode(24, OUTPUT);
}
void loop() {
if (Serial.available()>0)
{
val = Serial.parseInt();
stepper.step(val);
Serial.println(val); //for debugging
}
}
the basic stepper motor code was working before I altered it, and the code to have an LED flash on the board also seemed to be working on its own. I just can't figure out how to combine them in some way.