Skip to content

Instantly share code, notes, and snippets.

@rjehangir
Created December 22, 2015 21:16
Show Gist options
  • Save rjehangir/ecdf2e56a43e769ee0cd to your computer and use it in GitHub Desktop.
Save rjehangir/ecdf2e56a43e769ee0cd to your computer and use it in GitHub Desktop.
/* Blue Robotics Example Code
-------------------------------
Title: Multiple ESC Control via I2C (Arduino)
Description: This example code demonstrates the I2C communication capability
of the Blue Robotics "BlueESC". Motor speed commands are sent via I2C and
voltage, current, rpm, and temperature data is returned.
The code is designed for the Arduino Uno board and can be compiled and
uploaded via the Arduino 1.0+ software.
-------------------------------
The MIT License (MIT)
Copyright (c) 2015 Blue Robotics Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-------------------------------*/
#include <Wire.h>
#include "Arduino_I2C_ESC.h"
#define ESC_ADDRESS_0 0x29
#define ESC_ADDRESS_1 (0x29+1)
Arduino_I2C_ESC motor0(ESC_ADDRESS_0);
Arduino_I2C_ESC motor1(ESC_ADDRESS_1);
int signal;
void setup() {
Serial.begin(57600);
Serial.println("Starting");
Wire.begin();
}
void loop() {
if ( Serial.available() > 0 ) {
signal = Serial.parseInt();
}
motor0.set(signal);
motor1.set(signal);
motor0.update();
motor1.update();
Serial.print("#0 ESC: ");
if(motor0.isAlive()) Serial.print("OK\t\t");
else Serial.print("NA\t\t");
Serial.print(signal);Serial.print(" \t\t");
Serial.print(motor0.rpm());Serial.print(" RPM\t\t");
Serial.print(motor0.voltage());Serial.print(" V\t\t");
Serial.print(motor0.current());Serial.print(" A\t\t");
Serial.print(motor0.temperature());Serial.print(" `C");
Serial.println();
Serial.print("#1 ESC: ");
if(motor1.isAlive()) Serial.print("OK\t\t");
else Serial.print("NA\t\t");
Serial.print(signal);Serial.print(" \t\t");
Serial.print(motor1.rpm());Serial.print(" RPM\t\t");
Serial.print(motor1.voltage());Serial.print(" V\t\t");
Serial.print(motor1.current());Serial.print(" A\t\t");
Serial.print(motor1.temperature());Serial.print(" `C");
Serial.println();
delay(250); // Update at roughly 4 hz for the demo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment