Close

New motors, and the port expansion

A project log for Cubetto Clone

I would like to build a re-engineered Cubetto clone for my son.

KonkavKonkav 03/25/2018 at 22:580 Comments

Few posts earlier, I wrote about the 28BYJ-48 steppers in transit from China. I got them earlier, and was testing them in the past few days. While driving one motor directly from ESP8266 pins made results in no time, for two motors it would need 8 pins. All that an ESP has. I wasn't comfortable with it, and thought about expanding the ports with MCP23017. Unfortunately all the stepper libraries works only with native pins, and that meant writing the stepping program from scratch. Fortunately it is not so complicated, so I have somewhat a working prototype.

At the moment, it looks good. But there is something weird. Having the I2C communication on 100kHz or 400kHz, does not influence the communication time. I am debuging it like this:

ptime = micros();
Wire.beginTransmission(MCP);
Wire.write(GPIOA);
Wire.write(B10101010);
Serial.println(Wire.endTransmission());
atm = micros();
Serial.println(atm - ptime);

This is giving me 350-400 microsec., no matter what I2C speed I use. I did find out how to speed it up, by raising CPU clock from 80MHz to 160MHz, but it gave me speedup of about 50us only. I find it too slow, I was hoping to have an I2C communication time in the domain of 100-150us. Searching around the 23017 datasheet, I came across the sequential and byte mode, and the address auto increment. I was trying to not close the I2C communication, but to make a restart with:

Wire.endTransmission(false)

But. If after the above, I issue a simple:

Wire.write(B10101010)
Wire.endTransmission(false)

I get no data transferred to MCP. No matter what, if there is no beginTransmission, write(address), write(data) and then endTransmission, I get no data transferred to MCP, and if I include all this, then the restart ('endTransmission(false)') does not matter for the run time.

Really it doesn't matter too much, this stepper is not too fast, there is enough time, but I am curious, so I want to find out. But at the moment, it is working nicely, the motors are spinning, and I am trying to make a chassis for them, to test their usability for driving the robot.

Discussions