Any Arduino file that you'd like to use with your RVR+/RVR must start with
to bring in all of the SDK commands, and contain
in the setup function, in order to open the connection to RVR+/RVR.
Callbacks are one of the pillars of communicating with RVR+/RVR; they allow you to ask RVR+/RVR to send you information, instead of you just sending out commands to the RVR+/RVR. In cases where you are expecting a response from RVR+/RVR (like if you are using a callback), you'll need to use rvr.poll(); in your loop function; otherwise you won't hear anything back.
For some examples, check out the Power and System sections of our Arduino SDK page.
Controls make it easier for you to communicate with the RVR+/RVR using Arduino code by creating commands that already have references to some of the byte-level commands, so that you aren't having to dig through the code behind the scenes of the Sphero Arduino SDK. If you're curious about those, you can find them in the src directory of the zip file you download from our GitHub repo.
You have to cast enums and bitmasks when you use them: eg. (1 << static_cast<uint8_t>(LEDs::rightHeadlightRed))
The 1 << before the casting is called "bit shifting" and is really only necessary for setting the LEDs, becuse the first parameter is like a bitmask, but acually uses an enum. You don't have to dig too deep into this "why", but we wanted to make a note so that you know this is something you need to do when working with the LEDs.
The type that you cast your enum or bitmask to will usually be uint8, but you can look at structs.h (in the src directory of the zip file you download from our GitHub repo)(for enums) or look at the parameter that uses the bitmask (for bitmasks) to find the type.
What Commands/Parameters to Use Bitmasks With
One of the nuances of using the Sphero SDK with Arduino is that there are some (bitmask) flags that need to be input into some of the commands:
DriveFlags: use it for the flags input parameter of the driveWithHeading command
GyroMaxFlags: enableGyroMaxNotify enables an async that has a flags response parameter. flags is a uint8_t but you can look at the bitmask to figure out what it means (e.g. if it returns a flags value of 2 that translates to maxMinusX)
LocatorFlags: use it for the flags input parameter of the setLocatorFlags command
If this is your first time using your Arduino with your RVR, you'll want to make sure that, in your Arduino IDE, you Choose Arduino/Genuino Uno as your Board and the USB port you are actually utilizing as your Port.
When the file is ready, plug in your Arduino and click "Upload"!
To connect your Arduino to your RVR+/RVR, you just need to plug it into RVR's USB port, which will allow for the transfer of information, in addition to powering your Arduino. Unfortunately, because you'll be using the USB port on the RVR+/RVR to connect to the Arduino, you'll be unable to also physically connect your Arduino to your computer.
To alleviate this, Arduino's Software Serial Library allows you to connect your computer to the Arduino via an alternate cable while the RVR+/RVR is taking up the USB connection (though it can be a challenge to set up). If you are interested in implementing Arduino's SoftwareSerial library, jump over to our guide on the topic!