WEMOS D1 R2:D0 & A0 as output? (SOLVED)

Hello guys, I'm currently working a project which need to connect SD card, Camera module (OV2640 Plus) and Stepper motor (with A4988 driver) with WEMOS D1 R2.

4 I/O pins (1 for CS of camera, 1 for CS of SD, 1 for STEP pin & 1 for DIR pin of A4988 ) are needed, but through online searching, Wemos only provide limited IO pins for general purpose, because of some of the pins will be occupied by SD card and Camera pins: D1,2,5,6,7,4 & 3,
while the remaining pins that I think can be act as output pins for direction and step pin of A4988 are A0, D0, TX & RX.

I tried to use A0 & D0 as output pin with following code:

#define dirPin D0
#define  stepPin A0

const int dly = 500,
totalstep=200,
pulse=50;

void setup() {
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
}

void loop(){
    digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for(int x = 0; x < totalstep; x++) { //200*1.8 = 360
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(pulse); 
    digitalWrite(stepPin,LOW);
    delay(dly);}
    delay(1000);

    digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for(int x = 0; x < totalstep; x++) { //200*1.8 = 360
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(pulse); 
    digitalWrite(stepPin,LOW);
    delay(dly);}
}

The result was stepper only turn in one direction with the A0 & D0 pin. Multimeter showed that pin D0 alternating 2-3V while A0 is zero, which seems like D0 only allow HIGH for digitalWrite() and A0 is not working at all.

So may I know am I doing it right or it's just not suitable to use as output pin for my case?

Thank in advance.

Multimeter showed that pin D0 alternating 2-3V while A0 is zero, which seems like D0 only allow HIGH for digitalWrite() and A0 is not working at all.

A multimeter will never show you a value if you put pulses of 50µs on it (pausing for 500ms). This is a unusable way to check the IOs.

So you haven't figured out that A0 is an analog input?

On the UNO, A0 to A5 are of course, general purpose digital I/O with analog input functionality.

This isn't a UNO. :roll_eyes:

A0 is analog in only (0-1V, but the WeMOS has a voltage divider to make it take up to 3.3V or so).

D0 can be used as output just fine, as can Tx and Rx. In the latter case you do lose Serial communication. Beware of what you connect to those pins so as not to interfere with the boot and software uploads.

Do note that D0/GPIO16 is a special pin: it has an internal pull-down and does not have an interrupt available.

I suggest an SPI I/O expander. A 74hc595 might be sufficient. You could use this to interface with the motor driver for example, and any other control lines for the camera and SD card.

Paul__B:
So you haven't figured out that A0 is an analog input?

On the UNO, A0 to A5 are of course, general purpose digital I/O with analog input functionality.

This isn't a UNO. :roll_eyes:

to someone new to the chip, A0 might sound a lot like Analog Output....
there are Shift Registers like the 74hc595 that PaulRB mentioned,
and the Port Expander that uses I2C like a MCP23017 that uses the slower I2C bus
as a note there is SPIFFS that you can use for small data storage if you are just looking to save data.
not sure if there is a camera that you can control, but has it's own SD card

Thanks pylon, Paul__B, wvmarle, PaulRB and dave-in-nj for correctio/advice, I do really appreciate it!

And special thanks to PaulRB & dave-in-nj for suggesting 74hc595 SPI I/O expander, it's exactly solution for my project.

You guys are awesome!