In the mbot firmware and associated .cpp files, ports are used to assign input and output pins. What is the difference between ports and pins? I want to modify some of the mbot code but cannot find out what ports (pins) are not assigned already, or what modules I would have to lose in order to gain 3 digital output pins.
A port is collection of Pins. If you are using a port which needs to be setup in thr right way ( for example stepper driver ) all pins related to that port are setuped in the right way.
Pin = 1
Port = x pins
Thanks, Hetzandreas. That helps. So for the mbot, for example, what are the pins that are used to run the motors for the wheels? I am replacing the DC motors with very simple stepper motors to provide more accurate movements for my elementary students learning simple math and geometry by making the mbot make precise “steps” and “turns”. The two stepper motors together will only require 3 pins (digital outputs) and I would like to use the pins/port that are currently driving the DC motors.
Going into Arduino mode if you add DC motors the following code pops up:
This looks like DC motors are controlled with pins 9 and 10. I haven’t tried it but this is my guess as the number in the brackets for MeDCMotor motor_9 would relate to pin numbers in Arduino.
Thanks, NewInnovators - When I put the arduino in mbot mode (which is where I would like to use it) and check both the MakeBlock and Arduino extensions, then setting M1 digital pin 5 runs one motor (M1) and setting digital pin 6 runs the other (M2). Looking at the code for MeDCmotors, one pin is used for each motor, and a second pin reverses the motor. Setting pins 4 and 5 makes M1 run the other direction, but I have not been able to identify the pin that reverses M2. In the mbot mode, it seems unlikely that pins 9 and 10 would be used, because they are brought out on the RJ25 plug 1, and monitoring them when using the mbot motor commands shows no activity. It appears that 9, 10, 11 and 12 are not used for simple commands (although the distance sensors plug into RJ25 port 2), so I will try running the stepping motors driving the wheels with 11, 12, and 4 (or 5). Further information about this, perhaps especially from the MakeBlock staff, would be really appreciated.
i am trying to figure out the pin configuration of the Stepper drivers for the MegaPi,
in order to integrate their use into more complex arduino sketchs, but im not having any luck.
I would love to know the same
How to use pin mode for stepper motors in arduino IDE?