Wifi DC motor controller?
A few days ago I was talked on G+ by my friend Mauro Manco with an idea that was a bit weird at first: we all have heard about ESP8266 SoC that can bring Wifi happiness to out Arduino projects for a few dollars.
What Mauro suggested is that this same unit might handle the servo code I have written for an Arduino. That was in part possible by the release of an SDK that allow us to program it the same way as a regular Arduino, so code-wise, programs are compatible. In a few attempts Mauro managed to get my code to compile happily for the ESP. But he wanted me to try it out so he was as kind as sending me a NodeMCU board to my home so I could give it a try.
It just arrived at noon and I could not resist to give it a try, as usual not without some minor problems. The first one was that the NodeMCU did not show up as a serial port in my Macbook. I tried installing the CH340 driver to no avail. After using a magnifying lenses I realised that the USB to serial adapter on my board it was really a Prolific CP2102 chip instead. So just after another driver install, this time the right one, the board showed up in my computer as a serial port and I was able to compile, upload and test the mandatory Blink example :-) all from the familiar Arduino IDE.
Next step was to check whether or not the processor was up to the task of a time-critical interrupt code. I connected the encoder inputs to the module and set my motor at full speed. And I capture some samples of the motor position each second, as shown below:
It seemed it was working ok, but to be sure I needed to do the math, and I prefer the computer to do that for me.
What Mauro suggested is that this same unit might handle the servo code I have written for an Arduino. That was in part possible by the release of an SDK that allow us to program it the same way as a regular Arduino, so code-wise, programs are compatible. In a few attempts Mauro managed to get my code to compile happily for the ESP. But he wanted me to try it out so he was as kind as sending me a NodeMCU board to my home so I could give it a try.
It just arrived at noon and I could not resist to give it a try, as usual not without some minor problems. The first one was that the NodeMCU did not show up as a serial port in my Macbook. I tried installing the CH340 driver to no avail. After using a magnifying lenses I realised that the USB to serial adapter on my board it was really a Prolific CP2102 chip instead. So just after another driver install, this time the right one, the board showed up in my computer as a serial port and I was able to compile, upload and test the mandatory Blink example :-) all from the familiar Arduino IDE.
Next step was to check whether or not the processor was up to the task of a time-critical interrupt code. I connected the encoder inputs to the module and set my motor at full speed. And I capture some samples of the motor position each second, as shown below:
It seemed it was working ok, but to be sure I needed to do the math, and I prefer the computer to do that for me.
So I could see the motor was running at around 3700 RPM, which was consistent with the no load speed at 12V supply. So my guess is that interrupts are not lost here as that was the worst case scenario for this motor.
Please note that the business till now is just a change from the b-bit 16 Mhz Atmel 328 or 32u4 processor to the ESP's 32-bit SoC 80Mhz processor. As it was expected the system is clearly much faster and it can handle speeds the Arduino might not reach.
But the next step was to replace the Serial I/O of my program for a TCP communication over wifi so the motor controller could be configured and/or commanded wirelessly. So I did some changes and get it more or less working through wifi using telnet program on the computer side. Still some tidying may be needed but it seems to work ok (EEPROM is not working though it gives no error).
If you use the serial terminal on the ESP side, you will see it prints the IP address it obtains once it logs to your wifi network.
For controlling a motor for a dolly you might want to use your cellphone to create a temporary wifi network so you can send the commands to the motor with your desired timing wirelessly no matter where you are (if you build the program for that I will love to have a copy :-)
Comments