This is a library for an Arduino-compatible controller that interfaces with the Pololu Qik dual serial motor controllers. It makes it easy to control two brushed DC motors with a simple serial interface.
The Qik controllers can be purchased on Pololu's website. Before continuing, careful reading of the product page as well as the user's guide (2s9v1 or 2s12v10 or 2s15v9 is recommended.
The example programs require the appropriate set of connections to be made with wires between the Arduino and the Qik:
Arduino - Qik 2s9v1
--------------------------
5V - VCC
GND - GND
Digital Pin 2 - TX
Digital Pin 3 - RX
Digital Pin 4 - RESET
Arduino - Qik 2s12v10 or Qik 2s15v9
-----------------------------------------
GND - GND
Digital Pin 2 - TX
Digital Pin 3 - RX
Digital Pin 4 - RESET
Do not connect the 5V output on the Arduino to the 5V output on the Qik 2s12v10 or Qik 2s15v9!
Note: If you are using an Arduino variant that does not use an ATmega328P or ATmega168 (such as a Mega or Leonardo), the default pin assignments will not work for you and will need to be changed. Please see the Arduino SoftwareSerial Library reference for more information.
If you are using version 1.6.2 or later of the Arduino software (IDE), you can use the Library Manager to install this library:
- In the Arduino IDE, open the "Sketch" menu, select "Include Library", then "Manage Libraries...".
- Search for "PololuQik".
- Click the PololuQik entry in the list.
- Click "Install".
If this does not work, you can manually install the library:
- Download the latest release archive from GitHub and decompress it.
- Rename the folder "qik-arduino-xxxx" to "PololuQik".
- Drag the "PololuQik" folder into the "libraries" directory inside your Arduino sketchbook directory. You can view your sketchbook location by opening the "File" menu and selecting "Preferences" in the Arduino IDE. If there is not already a "libraries" folder in that location, you should make the folder yourself.
- After installing the library, restart the Arduino IDE.
Several example sketches are available that show how to use the library. You can access them from the Arduino IDE by opening the "File" menu, selecting "Examples", and then selecting "PololuQik". If you cannot find these examples, the library was probably installed incorrectly and you should retry the installation instructions above.
Each of these programs ramps motor 1 from stopped to full speed forward, ramps down to full speed reverse, and back to stopped. Then, it does the same with the other motor. For the Qik 2s12v10 and Qik 2s15v9, both motors' current readings are sent over serial and can be seen with the serial monitor.
Each of these programs reads and displays the configuration parameters
of the Qik. They can also be used to change the configuration
parameters by uncommenting and editing the appropriate calls to
setConfigShowResult()
.
The configuration parameters are stored in non-volatile memory that is rated for a limited number of erase/write cycles, so they are not intended to be written frequently. (Once set, these parameters will retain their values even if the Qik is powered off.) If you need to change the parameters, we recommend that you run the configuration program once to set them and then load your final program on your Arduino, which should assume that the parameters have already been set correctly. See the comments at the top of the configuration programs and the user's guides for more details.
This library defines a PololuQik
base class that implements commands
common to both versions of the Qik. Three derived classes,
PololuQik2s9v1
, PololuQik2s12v10
and PololuQik2s15v9
, handle
commands specific to each version.
The PololuQik
class is itself derived from the SoftwareSerial
class,
so you can use SoftwareSerial
member functions (like write()
and
listen()
) for direct access to the serial interface used to
communicate with the Qik.
The library does not implement any serial communication timeouts, so your sketch will hang if the Qik is not connected properly or does not respond as expected. It uses the compact protocol, not the Pololu protocol, so it cannot be used to control multiple Qiks daisy-chained together on the same serial line.
-
PololuQik(unsigned char receivePin, unsigned char transmitPin, unsigned char resetPin)
Constructor; sets pins as specified. The receive and transmit pins are specified from the perspective of the Arduino (so the receive pin should be connected to the TX pin on the Qik and the transmit pin should be connected to the RX pin on the Qik). -
void init(long speed = 9600)
Resets the Qik and initializes serial communication with it at the specified baud rate (defaults to 9600 bps if unspecified). -
char getFirmwareVersion()
Returns an ASCII byte that represents the version of the firmware running on the Qik. -
byte getErrors()
Returns a byte that indicates any errors that have been detected since the errors were last read. See the user's guides for the meaning of each bit. -
byte getConfigurationParameter(byte parameter)
Returns the current value of the specified configuration parameter. -
byte setConfigurationParameter(byte parameter, byte value)
Sets the specified configuration parameter to the specified value. -
void setM0Speed(int speed)
Sets speed and direction for motor M0.speed
should be between -127 and 127 in 7-bit mode or -255 and 255 in 8-bit mode. Positive values correspond to motor current flowing from the + pin to the - pin. Negative values correspond to motor current flowing from the - pin to the + pin. -
void setM1Speed(int speed)
Sets speed and direction for motor M1. -
void setSpeeds(int m0Speed, int m1Speed)
Sets speed and direction for both motors.
void setM0Coast()
Sets motor M0 to coast.void setM1Coast()
Sets motor M1 to coast.void setCoasts()
Sets both motors to coast.
void setM0Brake(unsigned char brake)
Sets brake for motor M0.brake
should be between 0 and 127. 0 corresponds to full coast, and 127 corresponds to full brake.void setM1Brake(unsigned char brake)
Sets brake for motor M1.void setBrakes(unsigned char m0Brake, unsigned char m1Brake)
Sets brake for both motors.unsigned char getM0Current()
Returns raw current reading from motor M0.unsigned char getM1Current()
Returns raw current reading from motor M1.unsigned int getM0CurrentMilliamps()
Returns current reading from motor M0 in milliamps.unsigned int getM1CurrentMilliamps()
Returns current reading from motor M1 in milliamps.unsigned char getM0Speed()
Returns the present target motor speed for motor M0.unsigned char getM1Speed()
Returns the present target motor speed for motor M1.
- 2.1.0 (2021-10-21): Add Qik 2s15v9 version
- 2.0.0 (2016-08-16): Updated library to work with the Arduino Library Manager.
- 1.1.1 (2016-06-08): Made SoftwareSerial include to be a system header include (thanks Dippyskoodlez).
- 1.1.0 (2013-05-22): Added calls to
SoftwareSerial::listen()
for better behavior when using multiplePololuQik
instances. - 1.0.0 (2012-05-07): Original release.