# Software

## Overview

Welcome to the Software Onboarding for the 2025-2026 school year!

## Goals

- Learning 
    - How do we write software in SCR?
    - How does a microcontroller control hardware?
- practical 
    - Writing Arduino/ C++ code
    - Managing software dependencies
    - Reading software documentation

## Downloads

**Arduino:**

Go [here](https://web.archive.org/web/20250912193054/https://www.arduino.cc/en/software/) and download the version of the arduino IDE for your operating system (Windows, OSX, linux).

[![](https://web.archive.org/web/20250912193054im_/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/scaled-1680-/image-1755190920456.png)](https://web.archive.org/web/20250912193054/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/image-1755190920456.png)

**Pico board support:**

We'll be using the Raspberry Pi Pico 2 for onboarding. To develop on the pico, you need to add an additional board manager URL to the Arduino IDE.

Go [here](https://web.archive.org/web/20250912193054/https://github.com/earlephilhower/arduino-pico) and scroll to the **installation** section. Follow the short directions there.

[![](https://web.archive.org/web/20250912193054im_/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/scaled-1680-/image-1755191035848.png)](https://web.archive.org/web/20250912193054/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/image-1755191035848.png)

[![](https://web.archive.org/web/20250912193054im_/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/scaled-1680-/image-1755191065835.png)](https://web.archive.org/web/20250912193054/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/image-1755191065835.png)

In the boards manager tab, search for these two libraries and **install** them

[![](https://web.archive.org/web/20250912193054im_/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/scaled-1680-/image-1755192255242.png)](https://web.archive.org/web/20250912193054/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/image-1755192255242.png)

## Compilation

**Select the Pico 2:**

Use the Arduino IDE to select the Pico 2 as the compilation target.

[![](https://web.archive.org/web/20250912193054im_/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/scaled-1680-/image-1755192324815.png)](https://web.archive.org/web/20250912193054/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/image-1755192324815.png)

Connect the Pico 2 to your computer using a micro-usb cable. You should see this drop down turn **bold**.

[![](https://web.archive.org/web/20250912193054im_/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/scaled-1680-/image-1755192471761.png)](https://web.archive.org/web/20250912193054/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/image-1755192471761.png)

**Verifying Source Code:**

Copy this skeleton code into an arduino sketch file.

```c++
#define LED1_PIN 13
#define LED2_PIN 14
#define LED3_PIN 15

#define IR1_PIN 0
#define IR2_PIN 1
#define IR3_PIN 2
#define IR4_PIN 3
#define IR5_PIN 4

#define MOTOR2_IN3 18
#define MOTOR2_IN4 19

#define MOTOR1_IN1 20
#define MOTOR1_IN2 21

#define SERVO_PIN 22

Servo payloadServo;

void driveForward() {
  // right motor
  digitalWrite(MOTOR1_IN1, HIGH); 
  digitalWrite(MOTOR1_IN2, LOW);

  // left motor
  digitalWrite(MOTOR2_IN3, HIGH);
  digitalWrite(MOTOR2_IN4, LOW);
}

void dumpPayload(Servo servo) {
  servo.write(180);
}

void setup() {
  // IR Pin Setup
  pinMode(IR1_PIN, INPUT);
  pinMode(IR2_PIN, INPUT);
  pinMode(IR3_PIN, INPUT);
  pinMode(IR4_PIN, INPUT);
  pinMode(IR5_PIN, INPUT);
  
  // LED Setup
  pinMode(LED1_PIN, OUTPUT);
  pinMode(LED2_PIN, OUTPUT);
  pinMode(LED3_PIN, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);

  // Motor setup
  pinMode(MOTOR1_IN1, OUTPUT);
  pinMode(MOTOR1_IN2, OUTPUT);

  pinMode(MOTOR2_IN3, OUTPUT);
  pinMode(MOTOR2_IN4, OUTPUT);

  // Servo setup
  pinMode(SERVO_PIN, 22);
  payloadServo.attach(SERVO_PIN);
}

void loop() {
  // put your main code here, to run repeatedly:
  driveForward();
  delay(500);
  dumpPayload();
  delay(500);
}

```

This file contains `#define`s for the Pico 2's inputs and outputs as well as a function to drive both motors forward.

Edit the `setup()` function and add the line

`digitalWrite(LED1_PIN, HIGH);`

Click the check mark at the top left of the IDE to check for compilation errors. If your program compiles correctly you should see this output.

[![](https://web.archive.org/web/20250912193054im_/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/scaled-1680-/image-1755192857560.png)](https://web.archive.org/web/20250912193054/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/image-1755192857560.png)

**Flashing Pico 2:**

Click the arrow at the top left of the IDE to flash the Pico 2. If flashing doesn't work, you may need to unplug the Pico 2 and hold the BOOTSEL button while reconnecting the micro-usb cable.

If your flash is successful, you should see this output, and LED1 should be turned on.

[![](https://web.archive.org/web/20250912193054im_/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/scaled-1680-/image-1755193492543.png)](https://web.archive.org/web/20250912193054/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/image-1755193492543.png)

[![](https://web.archive.org/web/20250912193054im_/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/scaled-1680-/image-1755194024811.png)](https://web.archive.org/web/20250912193054/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/image-1755194024811.png)

## Useful Documentation

**Motor Driver:**

You shouldn't need more than this truth table, but if you'd like to read the full documentation you can do that [here](https://web.archive.org/web/20250912193054/https://www.ti.com/lit/ds/symlink/drv8421.pdf?ts=1755179802802).

[![](https://web.archive.org/web/20250912193054im_/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/scaled-1680-/image-1755195517843.png)](https://web.archive.org/web/20250912193054/https://wiki.soonerrobotics.org/uploads/images/gallery/2025-08/image-1755195517843.png)

**Arduino:**

[Arduino API](https://web.archive.org/web/20250912193054/https://docs.arduino.cc/learn/programming/reference/), [Servos](https://web.archive.org/web/20250912193054/https://docs.arduino.cc/tutorials/generic/basic-servo-control), [Search](https://web.archive.org/web/20250912193054/https://docs.arduino.cc/)