Sphero Public SDK

Sphero Public SDK

  • Getting Started
  • How To
  • Documentation
  • Get the Code
  • Samples
  • Troubleshooting
  • FAQs

Setting Up Arduino UNO

ℹ️
note

The Arduino SDK is no longer being actively developed. We've left the links here for anyone who would like to continue to use it anyway.

Check out our Raspberry Pi Python SDK for all the latest RVR+/RVR features.

Getting Your Arduino Uno Ready to Roll

Download the IDE

Arduino has their own IDE (which you can download here) for working with their "C/C++esque" language. They have both a desktop version and a web version of their IDE, so you can work in whatever environment makes you feel most comfortable!

To learn more about Arduino's library and all the commands therein, check out their docs.

Creating RVR+/RVR Files

When creating Arduino files to be used with your RVR+/RVR, you can build on top of the Arduino library using our Arduino SDK. Any Arduino file that you'd like to use with your RVR+/RVR must start with

#include <SpheroRVR.h>

to bring in all of the SDK commands, and contain

rvr.configUART(&Serial);

in the setup function, in order to open the connection to RVR+/RVR.

Callbacks

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 How To page.

Controls

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.

Bitmasks and Enums

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

Arduino Settings

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.

All Done!

When the file is ready, plug in your Arduino and click "Upload"!

Connecting to RVR+/RVR

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!

  • Getting Your Arduino Uno Ready to Roll
    • Download the IDE
    • Creating RVR+/RVR Files
    • Connecting to RVR+/RVR
Sphero Public SDK

Wanna stay informed about Public SDK efforts and releases?

Sphero
Public SDK LicenseAbout Sphero Public SDKSphero.comSphero EDU
Community
Sphero CommunityThingiverseTwitterInstagramFacebook
More
RedditLinkedInGitHubStar
Copyright © 2022 Sphero