PyMODI is a python API for MODI controls. MODI modules are electronic modules that operates using controller area network protocol. You can easily control the electronic modules using PyMODI package. Use PyMODI to make your own MODI creation or copy some of the creations listed above. There are various adaptations of PyMODI in areas such as gaming, machine learning, and education!
Play Galaga with PyMODI! This creation offers a fully immersive gaming experience of controlling the Galaga Jetplane using MODI gyro module. Check out the source code here!
Play Dodge with PyMODI! The creation provides a TUI game which you have to control a character with a gyro module to avoid falling boxes. Source code can be found here.
Control computer mouse with PyMODI. With gyro module and button module, you can control mouse input! Source code lives here :)
Copy whatever color you want! The combination of MODI environment module and machine learning allows this creation to copy the rgb data of any color you want. You can check out the source code here.
Control MODI car using PyMODI over BLE(Bluetooth Low Engergy)! Check out the source code.
Show us your creativity by making new PyMODI creations! Include your work under examples folder appropriately then send us PR! Notable ones will be added to this creation list :)
Module classification | Setup Module |
---|---|
Module Description | Network modules are available either wired or wirelessly. Wired connections connect the PC to the network module using USB. Wireless connections are used to connect to Bluetooth or Wi-Fi or to connect to mobile devices. |
Main Function |
1. Module to PC 2. Module to Smartphone Connection Mode (MODI Play Application) 3. Module-to-module connection mode |
Module Size | 23.8*47.8*16.1(mm) |
Module Weight | 12g |
Network Spec | BLE Version 4.1v Wi-Fi Network standby 802.11n(2.4GHz),up to 150 Mbps |
Module Terminal | Micro-B USB port X1 Magnetic connector X3 |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'network'
network = bundle.networks[0]
"""
Before proceed further, ensure that you have paired the network module with your
mobile device using MODI Play, through BLE connection.
"""
# Returns whether MODI Play button is pressed, True if pressed
network_button_pressed = network.button_pressed
print('network_button_pressed:', network_button_pressed)
# Returns MODI Play dial value in range 0~100
network_dial = network.dial
print('network_dial:', network_dial)
# 'up' , 'down' , 'left' , 'right', and None if not pressed
network_joystick = network.joystick
print('network_joystick:', network_joystick)
# Returns MODI Play left slider value in range 0~100
network_left_slider = network.left_slider
print('network_left_slider:', network_left_slider)
# Returns MODI Play right slider value
network_right_slider = network.right_slider
print('network_right_slider:', network_right_slider)
# Returns True if MODI Play timer is up
network_timer = network.timer
print('network_timer:', network_timer)
# Turns on MODI Play buzzer
network.buzzer_on()
# Turn on the buzzer during 2 sec
time.sleep(2)
# Turns off MODI Play buzzer
network.buzzer_off()
# Takes a picture with MODI Play camera
network.take_picture()
Module classification | Input Module |
---|---|
Module Description | The button module detects the button is pressed. You can see the status of a single click, a double click, and a pressed state. You can use the toggle to keep the status ON or OFF. |
Main Function |
1. One-click detection 2. Double-click detection 3. Detects conditions pressed 4. Switch state whenever pressed (ON/OFF) |
Module Size | 23.8*47.8*16.1(mm) |
Module Weight | 12g |
Connection Terminal | Magnetic connector X4 |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'button'
button = bundle.buttons[0]
# Returns True when the button is pressed and False when the button is released
button_clicked = button.clicked
print('button_clicked:', button_clicked)
# Returns True when the button is double clicked
button_double_clicked = button.double_clicked
print('button_double_clicked:', button_double_clicked)
# Returns True when the button is pressed
button_pressed = button.pressed
print('button_pressed:', button_pressed)
# Returns bool each time the button is toggled. The value changes when the button is pressed
button_toggled = button.toggled
print('button_toggled:', button_toggled)
Module classification | Input Module |
---|---|
Module Description | The dial module uses the rotation of the module handle. Measures the angle of rotation or the rate of rotation. |
Main Function |
1. Rotation Angle Measurement 2. Rotation Speed Measurement |
Module Size | 23.8*23.8*24.0(mm) |
Module Weight | 13g |
Connection Terminal | Magnetic connector X4 |
Sensor Specifications | Operating range 0° to 235° (± 5°) |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'dial'
dial = bundle.dials[0]
# Returns the angle of the dial in the range of 0 to 100
dial_degree = dial.degree
print('dial_degree:', dial_degree)
# Returns the turnspeed of the dial in the range of -100 to 100
dial_turnspeed = dial.turnspeed
print('dial_turnspeed:', dial_turnspeed)
Module classification | Input Module |
---|---|
Module Description | The environment module uses semiconductor sensors to detect ambient physical changes and colors. Measure the ambient physical change values: temperature, humidity, illumination, and three primary colors (R,G,B) for color detection. |
Main Function |
1. Temperature measurement 2. Humidity Measurement 3. Brightness Measurement 4. RGB Measurement |
Module Size | 23.8*23.8*16.1(mm) |
Module Weight | 12g |
Connection Terminal | Magnetic connector X4 |
Sensor Specifications |
Temperature -10℃ to 85℃ Humidity 0 to 90% RH Brightness 0 to 40,000 Lux Color 0 to 40,000 Lux *Some values may be marked as % due to low sensitivity. *Products and sensors are attached to each other, requiring the proper distance between the object and the module being measured. |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'env'
env = bundle.envs[0]
# Returns the brightness value in the range of 0 to 100
env_brightness = env.brightness
print('env_brightness:', env_brightness)
# Returns the current humidity in the range of 0 to 100
env_humidity = env.humidity
print('env_humidity:', env_humidity)
# Returns the current temperature in the range of 0 to 100
env_temperature = env.temperature
print('env_temperature:', env_temperature)
# Returns the red value of the light in the range of 0 to 100
env_red = env.red
print('env_red:', env_red)
# Returns the green value of the light in the range of 0 to 100
env_green = env.green
print('env_green:', env_green)
# Returns the blue value of the light in the range of 0 to 100
env_blue = env.blue
print('env_blue:', env_blue)
Module classification | Input Module |
---|---|
Module Description | The gyro module uses geomagnetic gravity acceleration. Measure the tilt angle, vibration rate, and acceleration and angular velocity for each axis of the sensor in the module. |
Main Function |
1. Rotation angle measurement (Roll, Pitch, Yaw) 2. Acceleration measurements (X, Y, Z codeinates) 3. Angular velocity measurement(X, Y, Z codeinates) 4. Vibrations measurement |
Module Size | 23.8*23.8*16.1(mm) |
Module Weight | 12g |
Connection Terminal | Magnetic connector X4 |
Sensor Specifications |
measurable ranges (X, Y, Z): -180° to 180° (± 5°) In the case of the Z axis, due to the nature of the sensor, the magnetic field can cause errors. |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'gyro'
gyro = bundle.gyros[0]
# Returns the pitch value in the range of -180 to 180
gyro_pitch = gyro.pitch
print('gyro_pitch:', gyro_pitch)
# Returns the roll value in the range of -180 to 180
gyro_roll = gyro.roll
print('gyro_roll:', gyro_roll)
# Returns the yaw value in the range of -180 to 180
gyro_yaw = gyro.yaw
print('gyro_yaw:', gyro_yaw)
# Returns the angular velocity with respect to x axis in the range of -100 to 100
gyro_angular_vel_x = gyro.angular_vel_x
print('gyro_angular_vel_x:', gyro_angular_vel_x)
# Returns the angular velocity with respect to y axis in the range of -100 to 100
gyro_angular_vel_y = gyro.angular_vel_y
print('gyro_angular_vel_y:', gyro_angular_vel_y)
# Returns the angular velocity with respect to z axis in the range of -100 to 100
gyro_angular_vel_z = gyro.angular_vel_z
print('gyro_angular_vel_z :', gyro_angular_vel_z)
# Returns the acceleration to x axis in the range of -100 to 100
gyro_acceleration_x = gyro.acceleration_x
print('gyro_acceleration_x:', gyro_acceleration_x)
# Returns the acceleration to y axis in the range of -100 to 100
gyro_acceleration_y = gyro.acceleration_y
print('gyro_acceleration_y :', gyro_acceleration_y)
# Returns the acceleration to z axis in the range of -100 to 100
gyro_acceleration_z = gyro.acceleration_z
print('gyro_acceleration_z:', gyro_acceleration_z)
# Returns the magnitude of vibration in the range of 0 to 100
gyro_vibration = gyro.vibration
print('gyro_vibration:', gyro_vibration)
Module classification | Input Module |
---|---|
Module Description | The ir module detects how much infrared radiation is reflected back from the module. Measures proximity based on the amount of reflected infrared light. |
Main Function |
1. Proximity Measurement |
Module Size | 23.8*23.8*21.5(mm) |
Module Weight | 12g |
Connection Terminal | Magnetic connector X2 |
Sensor Specifications |
Within a measurable range of approximately 4 to 30 cm (based on white paper). *Due to the nature of the light, depending on the curvature, reflectivity, and color of the reflecting surface The measurements may be differently. |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'ir'
ir = bundle.irs[0]
# Returns the proximity value in the range of 0 to 100
ir_proximity = ir.proximity
print('ir_proximity:', ir_proximity)
Module classification | Input Module |
---|---|
Module Description | The mic module uses sound-induced air pressure changes. Measures the size or frequency of surrounding sounds. |
Main Function |
1. Sound Size Measurement 2. Sound Frequency Measurements |
Module Size | 23.8*23.8*16.4(mm) |
Module Weight | 11g |
Connection Terminal | Magnetic connector X4 |
Sensor Specifications |
measurable volume 0 to 100% measurable frequency from 50 to 400 Hz |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'mic'
mic = bundle.mics[0]
# Returns the frequency of the input sound
mic_frequency = mic.frequency
print('mic_frequency:', mic_frequency)
# Returns the volume of the input sound in the range of 0 to 100
mic_volume = mic.volume
print('mic_volume:', mic_volume)
Module classification | Input Module |
---|---|
Module Description | Ultrasonic modules use ultrasonic waves above 20 kHz that cannot be heard by humans. The distance is calculated by measuring the time the high frequency sound emitted by the module is reflected back to the object. |
Main Function |
1. Distance measurement |
Module Size | 23.8*47.8*18.3(mm) |
Module Weight | 18g |
Connection Terminal | Magnetic connector X3 |
Sensor Specifications |
Measureable range 50 to 450 cm *Since it is a radial sensor, measuring distances perpendicular to the sensor, but interfering with the measurement by objects that are obstructed can cause errors within the distance you want to measure. *Error may occur when measuring distances of objects small enough to be undetectable. |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'ultrasonic'
ultrasonic = bundle.ultrasonics[0]
# Returns the distance to the object in the range of 0 to 100
ultrasonic_distance = ultrasonic.distance
print('ultrasonic_distance:', ultrasonic_distance)
Module classification | Output Module |
---|---|
Module Description | The display module communicates various information to the user, such as pictures and letters, to the screen. You can display your drawings, letters, or module information on the screen. |
Main Function |
1. Picture representation in pixels 2. Information representation of linked modules |
Module Size | 23.8*23.8*16.1(mm) |
Module Weight | 12g |
Connection Terminal | Magnetic connector X3 |
Output range |
64 * 48 pixel |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'display'
display = bundle.displays[0]
# Sets the text of the display module
display.text = 'Hello MODI!'
"""
Show a variable on position (pos_x, pos_y) of the screen.
The range of pos_x, pos_y is 0 to 255.
Parameters:
variable: number to show on the screen
position_x(pos_x): vertical position of the number
position_y(pos_y): horizontal position of the number
"""
pos_x = 20
pos_y = 30
display.show_variable(0, pos_x, pos_y)
# Clears the screen of display module
display.clear()
Module classification | Output Module |
---|---|
Module Description |
LED modules are semiconductor devices that turn electrical signals into light. The combination of the three primary colors of light, R, G, and B, produces 65,000 different colors of light. |
Main Function |
1. Four color representations (red, green, blue, white, and off) 2. 65,000 color representations through red, green, and blue combinations |
Module Size | 23.8*23.8*16.1(mm) |
Module Weight | 11g |
Connection Terminal | Magnetic connector X4 |
Sensor Specifications |
Brightness (R, G, B) 180, 50, 120 mcd (based on 2.5V) *DO NOT light LEDs directly on human eyes as this may damage vision. |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'led'
led = bundle.leds[0]
# Sets the red component of the light. The range of component is 0 to 100
led.red = 100
# Sets the green component of the light. The range of component is 0 to 100
led.green = 100
# Sets the blue component of the light. The range of component is 0 to 100
led.blue = 100
# Sets the rgb components of the light. The range of components is 0 to 100
led.rgb = 10, 0, 60
# Turns on the led to maximum brightness
led.turn_on()
# Turns off the led
led.turn_off()
Module classification | Output Module |
---|---|
Module Description | The motor controller module is a module that sends an electrical signal to the motor module for rotational motion. You can set the speed, angle, and torque at which the motor rotates. |
Main Function |
1. Rotation angle output 2. Speed Output 3. Print out a torque |
Module Size | 23.8*23.8*16.1(mm) |
Module Weight | 12g |
Connection Terminal |
Magnetic connector X3 6-pin Port X2 |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'motor'
motor = bundle.motors[0]
# Sets the degree of motors on both channel. The range of degree is 0 to 100
motor.degree = 30, 90
# Sets the degree of motors on channel I. The range of degree is 0 to 100
motor.first_degree = 30
# Sets the degree of motors on channel II. The range of degree is 0 to 100
motor.second_degree = 90
# Sets the speed of motors on both channel. The range of speed is -100 to 100
# If the current speed of the motors is -, it rotates in reverse
motor.speed = 50, 100
# Sets the speed of motors on channel I. The range of speed is -100 to 100
motor.first_speed = 50
# Sets the speed of motors on channel II. The range of speed is -100 to 100
motor.second_speed = 10
Module classification | Output Module |
---|---|
Module Description | The speaker module converts the electrical signal into a sound signal. You can use the piano keyboard UI to select a note or enter the desired frequency directly to make a sound. |
Main Function |
1. Sound output corresponding to frequency |
Module Size | 23.8*23.8*16.1(mm) |
Module Weight | 12g |
Connection Terminal | Magnetic connector X4 |
Sensor Specifications | Outputable frequency 17 to 10,000 Hz |
import modi
import time
# To connect a bundle of the MODI modules, instantiate a MODI object
bundle = modi.MODI()
# Stores the module use by the variable named 'speaker'
speaker = bundle.speakers[0]
# Sets the frequency and volume of the sound. The range of the volume is 0 to 100
# Plays the sound with frequency 220Hz and volume 100
speaker.tune = 220, 100
# Sets the frequency of the sound
speaker.frequency = 550
# Sets the volume of the sound. The range of the volume is 0 to 100
speaker.volume = 100
# Turns off the sound
speaker.turn_off()