commit 9e3c8ca05d41861366b946a60e112145fa3298e1 Author: Jake Date: Sun Jul 20 16:43:07 2025 +0800 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f1c8ed --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/files/ \ No newline at end of file diff --git a/code_notepad.py b/code_notepad.py new file mode 100644 index 0000000..c627fa5 --- /dev/null +++ b/code_notepad.py @@ -0,0 +1,127 @@ +import board +import pwmio +import time + +motorIN1 = pwmio.PWMOut(board.GP8, frequency=1000, duty_cycle=0) +motorIN2 = pwmio.PWMOut(board.GP9, frequency=1000, duty_cycle=0) + + +# DRIVE FORWARD +motorIN1.duty_cycle = 65535 # This is the maximum value +motorIN2.duty_cycle = 0 # This is the minimum value +time.sleep(1) + +# DRIVE BACKWARD +motorIN1.duty_cycle = 0 +motorIN2.duty_cycle = 65535 +time.sleep(1) + +# STOP +motorIN1.duty_cycle = 0 +motorIN2.duty_cycle = 0 + + + + +import board +import pwmio +import time + +# Initialize motor PWM pins +motorIN1 = pwmio.PWMOut(board.GP8, frequency=1000, duty_cycle=0) +motorIN2 = pwmio.PWMOut(board.GP9, frequency=1000, duty_cycle=0) + +def motor(power): + # Make sure power is never greater than 100 or less than -100 + if power > 100: + power = 100 + elif power < -100: + power = -100 + + # Convert 0-100 value, to 0 to 65535 + duty = abs(power) * 65535 // 100 + + # Apply power to a motor pin, depending on if its greater or less than 0 + if power > 0: + motorIN1.duty_cycle = duty + motorIN2.duty_cycle = 0 + elif power < 0: + motorIN1.duty_cycle = 0 + motorIN2.duty_cycle = duty + else: + motorIN1.duty_cycle = 0 + motorIN2.duty_cycle = 0 + +# TESTS +motor(100) # FULL FORWARD +time.sleep(3) +motor(-100) # FULL REVERSE +time.sleep(3) + +# Start at FULL REVERSE and slowly change from -100 to 100 +for i in range(-100, 100): + motor(i) + print(i) + time.sleep(0.1) + + + + + + + + + + + +import board +import time +import motor + +left_motor = motor.Motor(board.GP8, board.GP9) + +# TESTS +left_motor.move(100) # FULL FORWARD +time.sleep(2) +left_motor.move(-100) # FULL REVERSE +time.sleep(2) +left_motor.move(0) + +# Start at FULL REVERSE and slowly change from -100 to 100 +for i in range(-100, 100): + left_motor.move(i) + print(i) + time.sleep(0.1) + + + +import pwmio + +class Motor: + def __init__(self, in1_pin, in2_pin, frequency=1000): + # Set up PWM outputs on the specified pins + self.in1 = pwmio.PWMOut(in1_pin, frequency=frequency, duty_cycle=0) + self.in2 = pwmio.PWMOut(in2_pin, frequency=frequency, duty_cycle=0) + + def move(self, power): + # Constrain power to -100 to 100 + if power > 100: + power = 100 + elif power < -100: + power = -100 + + # Scale to duty cycle + duty = abs(power) * 65535 // 100 + + if power > 0: + self.in1.duty_cycle = duty + self.in2.duty_cycle = 0 + elif power < 0: + self.in1.duty_cycle = 0 + self.in2.duty_cycle = duty + else: + self.in1.duty_cycle = 0 + self.in2.duty_cycle = 0 + + + diff --git a/images/001.png b/images/001.png new file mode 100644 index 0000000..ff6d416 Binary files /dev/null and b/images/001.png differ diff --git a/images/color_sensor_instructions_chalk.png b/images/color_sensor_instructions_chalk.png new file mode 100644 index 0000000..2d3f04c Binary files /dev/null and b/images/color_sensor_instructions_chalk.png differ diff --git a/images/motor_instructions.png b/images/motor_instructions.png new file mode 100644 index 0000000..b59f37a Binary files /dev/null and b/images/motor_instructions.png differ diff --git a/images/motor_instructions_chalk.png b/images/motor_instructions_chalk.png new file mode 100644 index 0000000..781bdc6 Binary files /dev/null and b/images/motor_instructions_chalk.png differ diff --git a/images/mu_editor.jpg b/images/mu_editor.jpg new file mode 100644 index 0000000..dbf496e Binary files /dev/null and b/images/mu_editor.jpg differ diff --git a/images/mu_editor_serialmode.jpg b/images/mu_editor_serialmode.jpg new file mode 100644 index 0000000..fa4888b Binary files /dev/null and b/images/mu_editor_serialmode.jpg differ diff --git a/images/muxer_instructions_chalk.png b/images/muxer_instructions_chalk.png new file mode 100644 index 0000000..910e020 Binary files /dev/null and b/images/muxer_instructions_chalk.png differ diff --git a/images/neopixel_instructions_chalk.png b/images/neopixel_instructions_chalk.png new file mode 100644 index 0000000..b5d8c1e Binary files /dev/null and b/images/neopixel_instructions_chalk.png differ diff --git a/images/oled_example.jpg b/images/oled_example.jpg new file mode 100644 index 0000000..c45a967 Binary files /dev/null and b/images/oled_example.jpg differ diff --git a/images/oled_instructions_chalk.png b/images/oled_instructions_chalk.png new file mode 100644 index 0000000..27641ea Binary files /dev/null and b/images/oled_instructions_chalk.png differ diff --git a/images/rp2040.jpg b/images/rp2040.jpg new file mode 100644 index 0000000..973766d Binary files /dev/null and b/images/rp2040.jpg differ diff --git a/images/sonar_instructions_chalk.png b/images/sonar_instructions_chalk.png new file mode 100644 index 0000000..ff8f2dd Binary files /dev/null and b/images/sonar_instructions_chalk.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..00c0f02 --- /dev/null +++ b/index.html @@ -0,0 +1,1018 @@ + + + + + + + Responsive Robot Lessons + + + + + + + + + + + + +
+
+ + + + + + + + + + +
+
+ + +
+ + +
+

Setting up our Circuitpython toolchain

+ +
+ + +
+

Step 1: Setting up the IDE

+

There are many IDEs that we can use to program CircuitPython robot, we can even just use a text + editor.

+

However we'll be using one called "Mu Editor". So let's begin by downloading it.

+

Download

+ +

You can also get it from the Mu website, https://codewith.mu/en/

+
+
+ +
+ + +
+

Step 2: Install Circuitpython on board

+
    +
  1. Download the CircuitPython firmware UF2 file for the RP2040 Zero here.
  2. +
  3. Connect your RP2040 Zero to your computer using a USB cable.
  4. +
  5. Hold down the BOOT button, press and release the RST button.
  6. +
  7. A new USB drive appears in your file explorer called RPI-RP2.
  8. +
  9. Drag the downloaded CircuitPython firmware file into the RPI-RP2 drive.
  10. +
  11. The firmware will install, and after a moment, the drive should be called CIRCUITPY. +
  12. +
  13. Open the drive and examine the different files in there. The "code.py" file is our main + file, but we won't open it here.
  14. +
  15. Open the MU Editor, and we can start coding!
  16. +
+
+
+ Robot moving further +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..fb26522 --- /dev/null +++ b/styles.css @@ -0,0 +1,45 @@ +/* styles.css */ +h2 { + font-weight: 800 !important; + /* Bold */ + font-size: 1.2rem; + /* Slightly larger than default */ + margin-bottom: 0.5rem; + /* Optional: space below */ +} + +h3 { + font-weight: 600 !important; + /* Bold */ + font-size: 1.1rem; + /* Slightly larger than default */ + margin-bottom: 0.5rem; + /* Optional: space below */ +} + +code { + color: rgb(0, 178, 0); +} + + +/* Optional: underline active tab */ +.tab-btn.active { + border-bottom: 2px solid #2563eb; + /* Tailwind blue-600 */ + color: #2563eb; + font-weight: 600; +} + +a { + color: #2563eb !important; /* Tailwind blue-600 hex */ + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +ol li { + line-height: 2; + padding-left: 0.5rem; /* ensures indentation */ +}