|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#16
|
||||
|
||||
|
Re: CRIO ARDUINO INTERFACE
Quote:
I think using Git is better for version control, but that's just me. Cheers -Tanner |
|
#17
|
||||
|
||||
|
Re: CRIO ARDUINO INTERFACE
Personally, I like bazaar.
|
|
#18
|
|||||
|
|||||
|
Re: CRIO ARDUINO INTERFACE
Quote:
. I was also thinking of hosting other projects of mine on Google Code.But that's just me. Back on topic: Project Hosting? Where? Any improvements? |
|
#19
|
||||
|
||||
|
Re: CRIO ARDUINO INTERFACE
Ya'll are welcome to choose whichever system/site as I'm just a contributor at this point, but I probably will not be able to contribute to code if it is hosted by Google (job prevents me from getting a Google account which is what you need afaik). I can do GitHub (hence my suggestion), but it's a bit different and slightly complicated, so it could be a bit tough to learn. There's a lot of good resources out there about it though.
-Tanner |
|
#20
|
|||||
|
|||||
|
Re: CRIO ARDUINO INTERFACE
I have no problem learning github, if Robotes2414 chooses it. I'm just happy to contribute
|
|
#21
|
|||||
|
|||||
|
Re: CRIO ARDUINO INTERFACE
I have written several changes to the code while on vacation in the Philippines,
I wish I could post it, but I have no WiFi and the internet cafe I am currently typing this from has a no USB drive policy Changes: Digital comms I2C comms I have also started writing a library for the arduino. If you already have written one, I can stop. I will post them when i return stateside on the 23rd. |
|
#22
|
||||
|
||||
|
Re: CRIO ARDUINO INTERFACE
I haven't worked on it, ive been too busy with finals, as kanye said, go nuts go ape $h1+
|
|
#23
|
|||||
|
|||||
|
Re: CRIO ARDUINO INTERFACE
Here's what I have done over the last few weeks:
I commented some parts. I highlighted the comment with the list of changes. I have created the methods, but nothing in them yet... Code:
package com.shadowh511.mayor.utils;
import edu.wpi.first.wpilibj.SerialPort;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DigitalOutput;
import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.DigitalModule;
/**
* Arduino
* @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
*/
/*
**Changes by jeremypg399:*************************************************
* -I2C Constructor
* -Digital Constructor
* -Added methods:
* boolean isIdle() //Returns true if no data is being sent/recieved
* boolean isValid() //Returns True if comms work
* boolean digitalRead(int pin) //Same as in the Arduino language
* void setLed(boolean state) //Sets the onboard LED
* void digitalWrite(int pin, boolean state) //Same as in the Arduino Language
* void analogWrite(int pin) //Same as in the Arduino Language
* int analogRead(int pin) //Same as in the Arduino Language
* -Created variables to accomodate above changes
*
* Everything I have added pin-wise was considering All Arduino boards with
* analog pins 0-5(I2C on pins 4, 5), Digital pins 0-13(Serial on 0 and 1, led on 13)
* Some tweaking will be necessary in order to use the Arduino Mega
*/
private SerialPort serial;
private DigitalInput digIn;
private DigitalOutput digOut;
private I2C I2C;
public int m_I2CAddress;
public int m_digInChannel;
public int m_digOutChannel;
private CommsMode m_commsMode;
private final int TRANS_PULSE_LENGTH = 30;
private byte[] buffer =
{0, 0, 0, 0, 0, 0, 0};
private boolean[] pinConfigs = //An array storing the configurations of pins
{false, false, false, false, //Default is output
false, false, false, false, //True-Input, False-Output
false, false, false }; //Digital Pins 2-12(Pin 0 Reserverd
//for serial, pin 13 reserved for LED)
private boolean[] analogPinConfigs = //An array for the config's of analog pins
{true, true, true, //True-AnalogIn DigitalIn, False-kI2C DigitalOut
true, true, true }; //Pins 4 and 5 will be configured as outputs
//if using kI2C
/**
* Constructor
* @param comms the CommsMode
* @param in If kSerial, Baud Rate, if kI2C, Address on bus
*/
public Arduino(CommsMode comms, int in) {
if(comms.equals(CommsMode.kSerial)) {
try {
if(in > 100) {
System.out.println("Invalid Baud Rate--Are you sure you " +
"want to use serial?");
} else {
serial = new SerialPort(in);
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);
m_commsMode = CommsMode.kSerial;
if(e.equals("h")) {
System.out.println("Arduino communications locked in");
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else if(comms.equals(CommsMode.kI2C)) {
I2C = new I2C(DigitalModule.getInstance
(DigitalModule.getDefaultDigitalModule()), in);
this.m_I2CAddress = in;
this.I2C.write(in, 0);
if(this.I2C.read(m_I2CAddress, 1, buffer)) {
System.out.println("Error. No reply from Arduino. ");
} else {
System.out.println("Arduino Communications locked in");
}
} else if(comms.equals(null)) {
System.out.println("Invalid Communications Mode");
}
}
/**
* Constructor.
* @param comms The CommsMode, kDigital
* @param inChannel The Digital input channel to use
* @param outChannel The digital output channel to use
*/
public Arduino(CommsMode comms, int inChannel, int outChannel) {
if(comms.equals(CommsMode.kDigital)) {
digIn = new DigitalInput(inChannel);
digOut = new DigitalOutput(outChannel);
m_commsMode = comms;
} else {
System.out.println("Invalid Communications Mode");
}
}
/**
* Constructor.
* Defaults to Serial at 115200 Baud
*/
public Arduino() {
m_commsMode = CommsMode.kSerial;
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 static class CommsMode {
public final int value;
static final int kDigital_val = 1;
static final int kAnalog_val = 2;
static final int kI2C_val = 3;
static final int kSerial_val = 4;
public static final CommsMode kDigital = new CommsMode(kDigital_val);
public static final CommsMode kAnalog = new CommsMode(kAnalog_val);
public static final CommsMode kI2C = new CommsMode(kI2C_val);
public static final CommsMode kSerial = new CommsMode(kSerial_val);
private CommsMode(int value) {
this.value = value;
}
}
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 stringToInt(this.getData());
} catch (Exception e) {
System.out.println("something went wrong, " + e.getMessage());
return 0;
}
}
/**
* Used to check if the Arduino is not communicating at that given instance.
* @return True if the Arduino is not communicating, else false.
*/
public boolean isIdle() {
if(m_commsMode.equals(CommsMode.kDigital)) {
return false;
} else if(m_commsMode.equals(CommsMode.kSerial)) {
return false;
} else if(m_commsMode.equals(CommsMode.kI2C)) {
return false;
} else {
return false;
}
}
/**
* Sends data and waits for a response. Used to check if the arduino is
* still on and/or connected
* @return True if the Arduino responds, else false
*/
public boolean isValid() {
if(m_commsMode.equals(CommsMode.kDigital)) {
return false;
} else if(m_commsMode.equals(CommsMode.kSerial)) {
return false;
} else if(m_commsMode.equals(CommsMode.kI2C)) {
return false;
} else {
return false;
}
}
/**
* Toggles the onboard LED conneected to pin 13
* @param state
*/
public void setLed(boolean state) {
if(m_commsMode.equals(CommsMode.kDigital)) {
} else if(m_commsMode.equals(CommsMode.kSerial)) {
} else if(m_commsMode.equals(CommsMode.kI2C)) {
}
}
/**
* Toggles a digital pin designated as an output
* Does nothing if the pin has been configured as an input
* @param pin the digital pin to toggle
* @param state The state to write it to
*/
public void digitalWrite(int pin, boolean state) {
if(m_commsMode.equals(CommsMode.kDigital)) {
} else if(m_commsMode.equals(CommsMode.kSerial)) {
} else if(m_commsMode.equals(CommsMode.kI2C)) {
}
}
/**
* Gets the state of the digital input.
* Does nothing if the pin has been configured as an input
* @param pin The pin to query
* @return A boolean dependent on the digital input
*/
public boolean digitalRead(int pin) {
if(m_commsMode.equals(CommsMode.kDigital)) {
} else if(m_commsMode.equals(CommsMode.kSerial)) {
} else if(m_commsMode.equals(CommsMode.kI2C)) {
}
}
/**
* Writes a PWM wave to a pin. Must be a PWM pin.
* If a non PWM pin is given, or if the pin has been configured as an input,
* nothing will happen
* @param pin
*/
public void analogWrite(int pin) {
if(m_commsMode.equals(CommsMode.kDigital)) {
} else if(m_commsMode.equals(CommsMode.kSerial)) {
} else if(m_commsMode.equals(CommsMode.kI2C)) {
}
}
/**
* Gets the analog input on pins 0-5.
* @param pin The analog pin to query
* @return The int read by the Arduino (0-1023)
*/
public int analogRead(int pin) {
if(m_commsMode.equals(CommsMode.kDigital)) {
} else if(m_commsMode.equals(CommsMode.kSerial)) {
} else if(m_commsMode.equals(CommsMode.kI2C)) {
}
}
private int stringToInt(String data) {
}
}
Apologies for not being specific, but I don't remember numbers ![]() Last edited by Jeremy Germita : 06-23-2010 at 09:54 AM. |
|
#24
|
||||
|
||||
|
Re: CRIO ARDUINO INTERFACE
it says you can't use any custom circuits to do command signals, but as far as, say, an LCD goes were good.
|
|
#25
|
|||||
|
|||||
|
Re: CRIO ARDUINO INTERFACE
Can someone point me to the pinout of the I2C Port on the Digital Sidecar?
I'm making some cables, but I have no access to a robot until school starts. I believe it is a 4 or 5 pin Male header on the Digital Sidecar. Much appreciated, Jeremy |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Controlling Arduino through Labview | eitang | NI LabVIEW | 10 | 12-06-2010 01:20 AM |
| SPI interface for cRIO in C++?? | Dale | Programming | 4 | 01-18-2010 08:15 PM |
| Reimaging the cRio Issues there are no cRio devices on the subnet | Stuart | FRC Control System | 2 | 02-25-2009 11:41 PM |
| Using an Arduino as a robot controller (2010 and beyond?) | Leav | Control System | 14 | 02-13-2009 10:35 PM |
| Vex/Arduino Serial Port Help | weinbergmath | Programming | 2 | 05-30-2008 08:43 PM |