|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
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! ![]() |
|
#2
|
|||||
|
|||||
|
Re: CRIO ARDUINO INTERFACE
I like the whole idea of this!
I had an idea like this in march, but it was far more complex. Can I play around with it? I'd like to possibly help improve on this. |
|
#3
|
||||
|
||||
|
Re: CRIO ARDUINO INTERFACE
all my code is gpl'd so go at it. It doesn't reliably work ATM, so can you help me fix it please?
|
|
#4
|
|||||
|
|||||
|
Re: CRIO ARDUINO INTERFACE
I'll be glad to help. I can do some testing in starting in July.
Maybe we can have a working version by the 2011 Build Season! What seems to be the problem? Just a thought... Does your team use CAN? If yes, I think that this could interfere with that. Maybe have an alternate mode using the ADC and the DIO. Using 2 12 bit channels of the ADC, we can have a simple protocol to convert the returned int(or is it double?) into a char. Last edited by Jeremy Germita : 27-05-2010 at 18:05. Reason: Had an Idea (again for a typo) (darn my errors...) |
|
#5
|
||||
|
||||
|
Re: CRIO ARDUINO INTERFACE
This goes directly through the serial port on the Robot.
I am working on a bit of Arduino code that will let me see if the serial port is being used for anything. I think the following will work: Code:
void setup() {
Serial.begin(/*Maximum Serial Rate*/);
}
void loop() {
Serial.println(Serial.read());
}
|
|
#6
|
|||||
|
|||||
|
Re: CRIO ARDUINO INTERFACE
That sounds like a good idea. Ill post some code of the alternate comms when I get the chance.
|
|
#7
|
|||||
|
|||||
|
Re: CRIO ARDUINO INTERFACE
here is a rough idea of the constructor
Code:
public void robotInit() {
Arduino arduinoEx = new Arduino(CommsMode commsMode,int inChannel, int outChannel);
Arduino arduinoAn = new Arduino(CommsMode.kAnalog, 1); //Analog, channel 1
Arduino arduinoDig = new Arduino(CommsMode.kDigital, 7, 8); //Digital, Channels 7 and 8
Arduino arduinoSer = new Arduino(CommsMode.kSerial, baudRate); //Serial, baudRate
Arduino arduinoI2C = new Arduino(CommsMode.kI2C, 1);
}
int inChannel - Digital-the recieving pin Analog-The input pin Serial-Not Needed I2C-The address on the bus int OutChannel-Digital only- the sending pin long BaudRate - Serial Only, self explanatory I'll write something up in the library to show you how the constructors would work Last edited by Jeremy Germita : 28-05-2010 at 22:27. |
|
#8
|
|||||
|
|||||
|
Re: CRIO ARDUINO INTERFACE
About the unreliability, could you please explain this?
Is it timing? Maybe we can do something like a signal set HIGH to indicate an incomming serial transmission and vice versa for the cRio. I'm not sure about the levels of the Serial port on the cRio, but maybe the levels are different. A solution to this could be using the MAX233 level converter IC. How is the 'duino powered? Maybe your USB port has some problem. How about make a power adaptor(PD-Board to 3.5mm Barrel Jack). And maybe a filter cap to smooth out any signal problems caused by rapidly dropping voltage due to a motor starting up or similar. The regulator on the arduino can handle the 12 volts as long you aren't powering a current-hog(servos, lot's of led's, etc). If you are using the LCD as you said, maybe that is drawing abnormally large amounts of current(just a thought) Also, can we move this to PM's or email? Perferably email. PM me if yes ![]() |
|
#9
|
||||
|
||||
|
Re: CRIO ARDUINO INTERFACE
Don't move to PM's. Other people want to add an Arduino interface to the cRio. Like me. Thanks!
|
|
#10
|
||||
|
||||
|
Re: CRIO ARDUINO INTERFACE
Quote:
-Tanner |
|
#11
|
||||
|
||||
|
Re: CRIO ARDUINO INTERFACE
Well, our pm convo isn't alive anymore.
As far as the interface goes, I need people to help me test it (no changes since release 0) can someone also post a copy of the serial output of the cRIO booting? (I have no serial port ) |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |