Skip to content

CytronTechnologies/CytronMakerSumo

Repository files navigation

Cytron Maker Sumo Library

This is Arduino Library for Cytron Maker Mini Sumo Controller (MAKER-MSUMO).



Installation

  1. Open the Arduino IDE, select Sketch -> Include Library -> Manage Libraries....
  2. Search for Cytron Maker Sumo Library.
  3. Click Install to install the library.
  4. Restart the Arduino IDE.
  5. Examples can be opened in Arduino IDE from File -> Examples -> Cytron Maker Sumo Library.



Predefined Pin Constants

These pin constants are predefined in the library.

  • Opponent Sensors: OPP_FC, OPP_FL, OPP_FR, OPP_L, OPP_R
  • Edge Sensors: EDGE_L, EDGE_R
  • Start Button: START
  • Potentiometer: POT
  • Programmable LED: LED
  • General Purpose Input/Output: GPIO1, GPIO2

Example Code:

void setup() {
  MakerSumo.begin();
  
  // Wait until start button is pressed.
  while (digitalRead(START) == HIGH);
}

void loop() {
  digitalWrite(LED, HIGH);
  delay(300);
  
  digitalWrite(LED, LOW);
  delay(300);
}



Library Functions

These functions are provided in the library:



MakerSumo.begin()

Initialize the I/O pins of the controller.
Must be called once before using other library functions.

Syntax:
void MakerSumo.begin(void);

Parameters:
None

Returns:
None

Example Code:

void setup() {
  MakerSumo.begin();
}

MakerSumo.readDipSwitch()

Read the value of the DIP Switch.
Each switch position represents 1 bit (SW1 = MSB, SW3 = LSB).

Syntax:
int MakerSumo.readDipSwitch(void);

Parameters:
None

Returns:
Value of the DIP Switch (0 to 7).

------------------------------------
| SW1 | SW2 | SW3 | Returned Value |
------------------------------------
|  0  |  0  |  0  |        0       |
------------------------------------
|  0  |  0  |  1  |        1       |
------------------------------------
|  0  |  1  |  0  |        2       |
------------------------------------
|  0  |  1  |  1  |        3       |
------------------------------------
|  1  |  0  |  0  |        4       |
------------------------------------
|  1  |  0  |  1  |        5       |
------------------------------------
|  1  |  1  |  0  |        6       |
------------------------------------
|  1  |  1  |  1  |        7       |
------------------------------------

*SW: 0 = OFF    1 = ON

Example Code:

void setup() {
  MakerSumo.begin();
  Serial.begin(115200);
  
  int mode = MakerSumo.readDipSwitch();
  println(mode);
}

MakerSumo.readBatteryVoltage()

Read the battery voltage.

Syntax:
float MakerSumo.readBatteryVoltage(void);

Parameters:
None

Returns:
Battery voltage in volt.

Example Code:

void setup() {
  MakerSumo.begin();
  Serial.begin(115200);
  
  float batteryVoltage = MakerSumo.readBatteryVoltage();
  println(batteryVoltage);
}

MakerSumo.stop()

Stop the robot.

Syntax:
void MakerSumo.stop(void);

Parameters:
None

Returns:
None

Example Code:

void setup() {
  MakerSumo.begin();
  MakerSumo.stop();
}

MakerSumo.moveForward()

Control the robot to move forward.
Left motor rotates counter-clockwise.
Right motor rotates clockwise.

Syntax:
void MakerSumo.moveForward(int speed);

Parameters:

  • speed - How fast the robot moves (0 to 255).

Returns:
None

Example Code:

void setup() {
  MakerSumo.begin();
  MakerSumo.moveForward(128);
}

MakerSumo.moveBackward()

Control the robot to move backward.
Left motor rotates clockwise.
Right motor rotates counter-clockwise.

Syntax:
void MakerSumo.moveBackward(int speed);

Parameters:

  • speed - How fast the robot moves (0 to 255).

Returns:
None

Example Code:

void setup() {
  MakerSumo.begin();
  MakerSumo.moveBackward(128);
}

MakerSumo.turnLeft()

Control the robot to turn left.
Left motor and right motor rotate clockwise.

Syntax:
void MakerSumo.turnLeft(int speed);

Parameters:

  • speed - How fast the robot turns (0 to 255).

Returns:
None

Example Code:

void setup() {
  MakerSumo.begin();
  MakerSumo.turnLeft(50);
}

MakerSumo.turnRight()

Control the robot to turn right.
Left motor and right motor rotate counter-clockwise.

Syntax:
void MakerSumo.turnRight(int speed);

Parameters:

  • speed - How fast the robot turns (0 to 255).

Returns:
None

Example Code:

void setup() {
  MakerSumo.begin();
  MakerSumo.turnRight(50);
}

MakerSumo.setMotorSpeed()

Set the speed for each motor independently.

Syntax:
void setMotorSpeed(int side, int speed);

Parameters:

  • side - Which motor (MOTOR_L or MOTOR_R)?
  • speed - Motor speed (-255 to 255, negative = reverse).

Returns:
None

Example Code:

void setup() {
  MakerSumo.begin();
  MakerSumo.setMotorSpeed(MOTOR_L, 50);
}

MakerSumo.setServoPosition()

Control the servo position.

Syntax:
void MakerSumo.setServoPosition(int position);

Parameters:

  • position - Servo position in degrees (0 to 180).

Returns:
None

Example Code:

void setup() {
  MakerSumo.begin();
  MakerSumo.setServoPosition(90);
}

MakerSumo.playMelody()

Play melody through the piezo buzzer.
Only return after finish playing.
This function is modified from Arduino Example - toneMelody.

Syntax:
void MakerSumo.playMelody(const int *pitch, const int *duration, int length);

Parameters:

  • pitch - Array of notes in the melody.
    Available Notes:
    NOTE_B0,
    NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_DS1, NOTE_E1, NOTE_F1, NOTE_FS1, NOTE_G1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1,
    NOTE_C2, NOTE_CS2, NOTE_D2, NOTE_DS2, NOTE_E2, NOTE_F2, NOTE_FS2, NOTE_G2, NOTE_GS2, NOTE_A2, NOTE_AS2, NOTE_B2,
    NOTE_C3, NOTE_CS3, NOTE_D3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3, NOTE_G3, NOTE_GS3, NOTE_A3, NOTE_AS3, NOTE_B3,
    NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4,
    NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5,
    NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6, NOTE_B6,
    NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7,
    NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8
    
  • duration - Array of duration for each notes (4 = quarter note, 8 = eighth note, etc).
  • length - Number of notes in the melody.

Returns:
None

Example Code:

// Note in the melody:
int melodyPitch[] = {NOTE_E5, NOTE_E5, 0, NOTE_E5, 0, NOTE_C5, NOTE_E5, 0, NOTE_G5};

// Note durations: 4 = quarter note, 8 = eighth note, etc.
int melodyDuration[] = {10, 10, 10, 10, 10, 10, 10, 10, 10};

void setup() {
  MakerSumo.begin();
  MakerSumo.playMelody(melodyPitch, melodyDuration, 9);
}

MakerSumo.calibrateEdgeSensors()

Calibrate the edge sensors.
Sweep both edge sensors across the white edge and black background.
Press START button once done. Threshold will be calculated and saved to EEPROM.

Syntax:
void MakerSumo.calibrateEdgeSensors(void);

Parameters:
None

Returns:
None

Example Code:

void setup() {
  MakerSumo.begin();
  MakerSumo.calibrateEdgeSensors();
}

MakerSumo.readEdgeSensorThreshold()

Read the calibrated threshold for edge sensor.
If the sensors are not calibrated before, a default value will be returned.

Syntax:
int MakerSumo.readEdgeSensorThreshold(int side);

Parameters:

  • side - Which side of edge sensor (EDGE_L or EDGE_R).

Returns:
The threshold of the edge sensor.

Example Code:

void setup() {
  MakerSumo.begin();
  Serial.begin(115200);
  
  int leftEdgeThreshold = MakerSumo.readEdgeSensorThreshold(EDGE_L);
  println(leftEdgeThreshold);
}

MakerSumo.isEdgeDetected()

Check if the edge is detected.
Edge sensor value is compared with the valibrated threshold in EEPROM.
If the sensor is not calibrated before, a default value will be used instead.

Syntax:
bool MakerSumo.isEdgeDetected(int side);

Parameters:

  • side - Which side of edge sensor (EDGE_L or EDGE_R).

Returns:
True if edge is detected. False otherwise.

Example Code:

void setup() {
  MakerSumo.begin();
  Serial.begin(115200);
  
  bool rightEdgeDetected = MakerSumo.isEdgeDetected(EDGE_R);
  println(rightEdgeDetected);
}