![]() |
Need help with arduino to i2c on roborio!
Hi everyone!
This season, our team will be using an led strip with an arduino so we can control individual lights :) . We then want to connect our arduino to our roborio so we can control the arduino from our java code. We've done a lot of research but we can't figure out how to write the code for this. :mad: :confused: For example, if we want the strip of led lights to be rainbow in autonomous, we know how to do that with the arduino code, but once we connect the arduino to the roborio (i2c port, right? :confused: ), what code would we write in eclipse to trigger the arduino? Everything we've looked at has used DigitalModule which seems to not be used this year. Thanks for the help! :) |
Re: Need help with arduino to i2c on roborio!
Instead of using the i2c you could use an analog output from the roboRio into the arduino. On the roboRio you would output 5v during auto and 0v during teleop. Then the arudino would output rainbow when it has a 5v input and it could change when it receives 0v.
|
Re: Need help with arduino to i2c on roborio!
I realize that this example is in LabVIEW but similar APIs should be available in Java. Hopefully this will give you a push in the right direction.
AndyMark released some example code that drives a touch-screen shield on the RIOduino (the REV Robotics Arduino-compatible MXP board). The screen code won't be of interest, but the last part of their example shows how they communicate between the roboRIO and the RIOduino through the I2C port. Take a look at the example under the "Files & Documents" tab on the RIOduino with 2.8" Touchscreen (am-2999) bundle page. Again, their example is in LabVIEW, but the same APIs should exist in Java. Hope this helps! -David |
Re: Need help with arduino to i2c on roborio!
I'm a lazy coder but, for a super quick turnaround, you might use a few digital IO on the roborio to interact with the arduino and have a few pins on the arduino set to input. when the arduino reads a pin is high it would change the LED modes.
on the arduino, if pin 2 is High, Blue LED's blink... Etc. you could use 4 DIO's and then use them like binary to multiply your LED modes. or use 1 pwm and use pulsein(); on the arduino and you could have 180 modes... we did something similar with a pot as input for our driver-station board last year. |
Re: Need help with arduino to i2c on roborio!
This I2C tutorial will still work on a roboRIO, if you make a couple changes. Mainly, your robotInit() method just needs to have this:
Code:
public void robotInit() { |
Re: Need help with arduino to i2c on roborio!
Quote:
|
Re: Need help with arduino to i2c on roborio!
Quote:
|
Re: Need help with arduino to i2c on roborio!
Quote:
|
Re: Need help with arduino to i2c on roborio!
Quote:
|
Re: Need help with arduino to i2c on roborio!
Quote:
|
Re: Need help with arduino to i2c on roborio!
I saw this post awhile back and had come across a forum in the past that ensured that USB serial communication between the Raspberry Pi and Arduino is possible so I thought that it would be easy to setup a serial connection via USB. I looked at the online documentation for the WPILib SerialPort implementation and saw that documentation mentions "Driver for the RS-232 serial port on the RoboRIO".
Not being discouraged I tried some open source USB serial libraries and met failure with both of them. I figured I'll share my experience. RXTX, 64 bit precompiled binaries for Windows, was attempted, compiled, and transferred to the RoboRio, but once there it ran into runtime failure as something about the library was not available for some reason. The next library tried was java-simple-serial-connector or jSSC. This library looked promising as something quite simple with only one single jar file to add as a library in Eclipse. Unfortunately, as a WPILib project it fails to build, but has no problem as a Java application. Not sure what the issue is with that. I returned to searching forums for some means of reading serial from USB and came across this post again. I decided to look at the code for SerialPort and I'm seeing that the option to read from USB appears to indeed exist as an option which I'm writing code for right now to test with, but ran out of time for the day. I'm hoping this is the solution and that it helps someone else. "usbSerialPort = new SerialPort(9600, Port.kUSB);" Some code example to work with for communicating between Arduino and a Pi, modify for Java, is http://www.bitsharr.com/rtxu6LvK |
Re: Need help with arduino to i2c on roborio!
Tested out the code today with high hopes, but it ended up throwing an error at the point that the call to SerialPort's USB device was made. The catch of the error proved to be fruitless as the returned error was the empty string. The code to inspect will be available in today's Github commit if someone wishes to take a look on their own. https://github.com/FRC-3277/2015Recy...dBasedRefactor
For now I'm going to test with I2C to read and as a last resort I believe RS-232 is available, but if that depends on the SerialPort library it may be a better idea to re-write the Arduino code library in Java and avoid that class if its buggy. |
Re: Need help with arduino to i2c on roborio!
My team got the Arduino communicating with the roborio over I2C using the following code on the roborio
Code:
static I2C Wire = new I2C(Port.kOnboard, 4);Code:
#include <Wire.h> |
Re: Need help with arduino to i2c on roborio!
Quote:
|
Re: Need help with arduino to i2c on roborio!
Quote:
|
| All times are GMT -5. The time now is 08:18 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi