forked from SolidGeek/VescUart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
212 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Name: setCurrent.ino | ||
Created: 19-08-2018 | ||
Author: SolidGeek | ||
Description: This is a very simple example of how to set the current for the motor | ||
*/ | ||
|
||
#include <VescUart.h> | ||
|
||
/** Initiate VescUart class */ | ||
VescUart UART; | ||
|
||
float current = 1.0; /** The current in amps */ | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
/** Setup UART port (Serial1 on Atmega32u4) */ | ||
Serial1.begin(19200); | ||
|
||
while (!Serial1) {;} | ||
|
||
/** Define which ports to use as UART */ | ||
UART.setSerialPort(&Serial1); | ||
} | ||
|
||
void loop() { | ||
|
||
/** Call the function setCurrent() to set the motor current */ | ||
UART.setCurrent(current); | ||
|
||
// UART.setBrakeCurrent(current); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Name: setNunchuckValues.ino | ||
Created: 19-08-2018 | ||
Author: SolidGeek | ||
Description: Use the serial monitor to set the speed/brake and enable cruise control with the nunchuck values. | ||
This example is made using a Arduino Micro (Atmega32u4) that has a HardwareSerial port (Serial1) seperated from the Serial port. | ||
A Arduino Nano or Uno that only has one Serial port will not be able to get the commands over the Serial monitor. | ||
*/ | ||
|
||
#include <VescUart.h> | ||
|
||
/** Initiate VescUart class */ | ||
VescUart UART; | ||
|
||
void setup() { | ||
|
||
/** Setup Serial port to enter commands */ | ||
Serial.begin(9600); | ||
|
||
/** Setup UART port (Serial1 on Atmega32u4) */ | ||
Serial1.begin(19200); | ||
|
||
while (!Serial1) {;} | ||
|
||
/** Define which ports to use as UART */ | ||
UART.setSerialPort(&Serial1); | ||
} | ||
|
||
String command; | ||
int throttle = 127; | ||
|
||
void loop() { | ||
|
||
if (Serial.available()) { | ||
|
||
command = Serial.readStringUntil('\n'); | ||
|
||
if (command.equals("cruise")) { | ||
|
||
/** The lowerButton is used to set cruise control */ | ||
UART.nunchuck.lowerButton = true; | ||
|
||
} | ||
else if (command.equals("nocruise")) { | ||
|
||
/** The lowerButton is used to set cruise control */ | ||
UART.nunchuck.lowerButton = false; | ||
|
||
}else { | ||
|
||
throttle = command.toInt(); | ||
|
||
if ( throttle >= 0 && throttle <= 255) { | ||
|
||
/** The valueY is used to control the speed, where 127 is the middle = no current */ | ||
UART.nunchuck.valueY = throttle; | ||
Serial.println(throttle); | ||
|
||
} else { | ||
|
||
throttle = 127; | ||
Serial.println("Unvalid throttle value"); | ||
|
||
} | ||
} | ||
} | ||
|
||
/** Call the function setNunchuckValues to send the current nunchuck values to the VESC */ | ||
UART.setNunchuckValues(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters