Giter VIP home page Giter VIP logo

ftc-neodriver's Introduction

FTC NeoDriver

This repository contains driver software for use with the Adafruit NeoDriver - I2C to NeoPixel Driver Board in conjunction with the FIRST Tech Challenge Control System

Wiring up the Hardware

You will need:

NeoDriver Wiring

  1. Connect the NeoDriver board to one of the I2C ports on the Control Hub. The NeoDriver needs a JST SH (STEMMA QT) connector and the Control Hub expects a JST PH connector. Make note of which I2C port you plugged it into; you'll need to select the same one in Hardware Config.
  2. Connect 5V power from the Control Hub aux ports to the NeoDriver. This is what will provide power to light the NeoPixel strand; the I2C port cannot provide enough current.
  3. Connect the NeoPixel strand to the NeoDriver screw terminals, GND, 5V, and Data

Installing the Library

NOTE: These instructions will change a bit once there is a release of the library

For the moment, until the library is published to Maven Central add a new repository entry to your build.dependencies.gradle file:

repositories {
    mavenCentral()
    google() // Needed for androidx
    maven {
        url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
    }
}

Then add a new line to the dependencies section in build.dependencies.gradle:

dependencies {
    implementation 'org.firstinspires.ftc:Inspection:9.0.0'
    implementation 'org.firstinspires.ftc:Blocks:9.0.0'
    implementation 'org.firstinspires.ftc:Tfod:9.0.0'
    implementation 'org.firstinspires.ftc:RobotCore:9.0.0'
    implementation 'org.firstinspires.ftc:RobotServer:9.0.0'
    implementation 'org.firstinspires.ftc:OnBotJava:9.0.0'
    implementation 'org.firstinspires.ftc:Hardware:9.0.0'
    implementation 'org.firstinspires.ftc:FtcCommon:9.0.0'
    implementation 'org.firstinspires.ftc:Vision:9.0.0'
    implementation 'org.firstinspires.ftc:gameAssets-CenterStage:1.0.0'
    implementation 'org.tensorflow:tensorflow-lite-task-vision:0.4.3'
    runtimeOnly 'org.tensorflow:tensorflow-lite:2.12.0'
    implementation 'androidx.appcompat:appcompat:1.2.0'

    implementation 'com.w8wjb.ftc:ftc-neodriver:1.0-SNAPSHOT'
}

Configuring in Hardware Map

Important

You will need to download a project containing the library at least once before the Adafruit NeoDriver option will appear in Hardware Config

  1. On a connected Driver Station, edit the robot configuration file
  2. Choose the I2C port that you connected the NeoDriver to

I2C port selection

  1. Assuming the driver library has been downloaded, you should now see an option labeled "Adafruit NeoDriver"

Adafruit NeoDriver option

  1. Assign a name to the device and exit, saving the config when prompted

Adafruit NeoDriver device entry

API Usage

Initilization

In the initialization section of your OpMode, you will need to retrieve the device from the hardwareMap and configure how many pixels exist on your NeoPixel strand

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.w8wjb.ftc.AdafruitNeoDriver;


@Autonomous
public class NeoPixelTest extends OpMode {

    private static final int NUM_PIXELS = 30;

    AdafruitNeoDriver neopixels;

    @Override
    public void init() {

        neopixels = hardwareMap.get(AdafruitNeoDriver.class, "neopixels");
        neopixels.setNumberOfPixels(NUM_PIXELS);

    }

}

Setting NeoPixel colors

Pixel colors can be set individually, using an RGB integer. The Android SDK provides a useful utility class, android.graphics.Color, for construcing and manipulating this color data.

int color = Color.rgb(74, 230, 255);
neopixels.setPixelColor(0, color);

Pixel colors can also be set individually, using a hex color code:

neopixels.setPixelColor(0, "#4AE61A");

If you would like to set a block of pixels, it is possible to use an array:

neopixels.setPixelColors(new int[] {
        Color.rgb(255,0,0),
        Color.rgb(0,255,0),
        Color.rgb(0,0,255)
});

When setting pixels in bulk, the first index in the array always corresponds to the first pixel in the strand.

There is also a convenience fill method to set the entire strand to one color:

if (gamepad1.a) {
    // Signal purple pixel
    neopixels.fill(Color.rgb(207, 145, 255));
} else if (gamepad1.b) {
    // Signal green pixel
    neopixels.fill(Color.rgb(69, 255, 58));
} else if (gamepad1.x) {
    // Signal yellow pixel
    neopixels.fill(Color.rgb(255, 240, 64));
} else {
    // Lights off
    neopixels.fill(0);
}

Sending Data to the Strand

Once the pixel colors have been set, it is criticl to call show() to send the data to the NeoPixel strand:

int color = Color.rgb(74, 230, 255);
neopixels.setPixelColor(0, color);
neopixels.show();

ftc-neodriver's People

Contributors

calkestis avatar cmacfarl avatar w8wjb avatar

Stargazers

Team 9933 FTC avatar  avatar Maximilian Shabatayev avatar  avatar

Watchers

 avatar

Forkers

mtz-robotics

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.