Go to Post As guests in the city, we should make an effort to do some fundraising for the folks affected by the storm. Any ideas out there? - Jon236 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 17-05-2010, 11:00
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
CRIO ARDUINO INTERFACE

Hey, i got bored and wrote this:

Code:
package com.shadowh511.mayor.utils;

import edu.wpi.first.wpilibj.SerialPort;

/**
 *
 * @author Team 2412
 */
public class Arduino {
    /*
     * Hopefully, i will be able to have an arduino be hooked up to the robot
     * and communicate with the serial port.  I can use this to do many things,
     * such as maintain a LCD screen and display data on it to help the electrical
     * and mechanical teams figure out what went wrong.
     *
     * In all realism, it will most likely just be a fun cool thing for me to
     * play with :D
     */
    private SerialPort serial;

    public Arduino() {
        try {
            serial = new SerialPort(115200);
            this.serial.disableTermination();
            this.serial.print("h");
            System.out.println("Arduino Starting, waiting 0.5 seconds to get data");
            String e = this.getData();
            edu.wpi.first.wpilibj.Timer.delay(0.125);

            if(e.equals("h")) {
                System.out.println("Arduino communications locked in");
            }
        }
        catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
        }
    }

    public String getData() {
        try {
            return this.serial.readString();
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return null;
        }
    }

    public boolean sendData(byte[] buffer) throws Exception {
        try {
            int count = buffer.length;
            this.serial.write(buffer, count);
            return true;
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return false;
        }
    }
    
    public boolean printf(String data) {
        try {
            this.serial.print(data);
            return true;
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return false;
        }
    }

    public String requestData() {
        try {
            this.serial.print("r");
            return this.serial.readString();
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return null;
        }
    }

    public int requestData(String request) {
        try {
            this.serial.print(request);
            return NumberUtils.stringToInt(this.getData());
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return 0;
        }
    }
}

Hook up an arduino to the serial port and have it run a program that toggles pin number 13. Bind a button to sending h and a button to sending l. have fun pushing the buttons, you just made a polyglot robot!
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling Arduino through Labview eitang NI LabVIEW 10 06-12-2010 01:20
SPI interface for cRIO in C++?? Dale Programming 4 18-01-2010 20:15
Reimaging the cRio Issues there are no cRio devices on the subnet Stuart FRC Control System 2 25-02-2009 23:41
Using an Arduino as a robot controller (2010 and beyond?) Leav Control System 14 13-02-2009 22:35
Vex/Arduino Serial Port Help weinbergmath Programming 2 30-05-2008 20:43


All times are GMT -5. The time now is 08:51.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi