|
|
|
@ -34,7 +34,7 @@
|
|
|
|
#define HOVER_SERIAL_BAUD 38400 // [-] Baud rate for HoverSerial (used to communicate with the hoverboard)
|
|
|
|
#define HOVER_SERIAL_BAUD 38400 // [-] Baud rate for HoverSerial (used to communicate with the hoverboard)
|
|
|
|
#define SERIAL_BAUD 115200 // [-] Baud rate for built-in Serial (used for the Serial Monitor)
|
|
|
|
#define SERIAL_BAUD 115200 // [-] Baud rate for built-in Serial (used for the Serial Monitor)
|
|
|
|
#define START_FRAME 0xAAAA // [-] Start frme definition for reliable serial communication
|
|
|
|
#define START_FRAME 0xAAAA // [-] Start frme definition for reliable serial communication
|
|
|
|
#define TIME_SEND 100 // [ms] Sending time interval
|
|
|
|
#define TIME_SEND 25 // [ms] Sending time interval
|
|
|
|
#define SPEED_MAX_TEST 300 // [-] Maximum speed for testing
|
|
|
|
#define SPEED_MAX_TEST 300 // [-] Maximum speed for testing
|
|
|
|
//#define DEBUG_RX // [-] Debug received data. Prints all bytes to serial (comment-out to disable)
|
|
|
|
//#define DEBUG_RX // [-] Debug received data. Prints all bytes to serial (comment-out to disable)
|
|
|
|
|
|
|
|
|
|
|
|
@ -92,6 +92,7 @@ int motor_test_direction = 1;
|
|
|
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
|
|
|
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
|
|
|
|
// Connect to a Nunchuk
|
|
|
|
// Connect to a Nunchuk
|
|
|
|
Nunchuk nchuk;
|
|
|
|
Nunchuk nchuk;
|
|
|
|
|
|
|
|
HardwareSerial Serial1(PA_10, PA_9);
|
|
|
|
|
|
|
|
|
|
|
|
// ########################## SETUP ##########################
|
|
|
|
// ########################## SETUP ##########################
|
|
|
|
void setup()
|
|
|
|
void setup()
|
|
|
|
@ -103,14 +104,16 @@ void setup()
|
|
|
|
// Clear the buffer
|
|
|
|
// Clear the buffer
|
|
|
|
display.clearDisplay();
|
|
|
|
display.clearDisplay();
|
|
|
|
display.display();
|
|
|
|
display.display();
|
|
|
|
|
|
|
|
|
|
|
|
display.setTextSize(1); // Draw 1X-scale text
|
|
|
|
display.setTextSize(1); // Draw 1X-scale text
|
|
|
|
display.setTextColor(SSD1306_WHITE);
|
|
|
|
display.setTextColor(SSD1306_WHITE);
|
|
|
|
display.setCursor(int
|
|
|
|
display.setCursor(int
|
|
|
|
((display.width() -
|
|
|
|
((display.width() -
|
|
|
|
(strlen("Hoverboard Serial") * 6)) / 2), 0);
|
|
|
|
(strlen("Hoverboard Serial") * 6)) / 2), 0);
|
|
|
|
display.println("Hoverboard Serial");
|
|
|
|
display.println("Hoverboard Serial");
|
|
|
|
display.setCursor(52, 8);
|
|
|
|
display.setCursor(int
|
|
|
|
display.println("v0.2");
|
|
|
|
((display.width() -(strlen("v STM32 0.1") *6))/2), 8);
|
|
|
|
|
|
|
|
display.println("v STM32 0.1");
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
display.print("Nunchuk ");
|
|
|
|
display.print("Nunchuk ");
|
|
|
|
nchuk.connect()? display.print("") : display.print("not ");
|
|
|
|
nchuk.connect()? display.print("") : display.print("not ");
|
|
|
|
@ -125,7 +128,7 @@ void setup()
|
|
|
|
|
|
|
|
|
|
|
|
Serial.begin(SERIAL_BAUD);
|
|
|
|
Serial.begin(SERIAL_BAUD);
|
|
|
|
if (Serial) {
|
|
|
|
if (Serial) {
|
|
|
|
Serial.println("Hoverboard Serial v1.0");
|
|
|
|
Serial.println("Hoverboard Serial v STM32 0.1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -236,9 +239,15 @@ int old_cursorX, old_cursorY;
|
|
|
|
nchuk.reconnect();
|
|
|
|
nchuk.reconnect();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd1 = map(nchuk.joyX(),0,256,150,-150); // x - axis. Nunchuck joystick readings range 30 - 230
|
|
|
|
cmd1 = map(nchuk.joyX(),0,256,150,-150); // x - axis. Nunchuck joystick readings range 30 - 230
|
|
|
|
cmd2 = map(nchuk.joyY(),0,256,-150,150); // y - axis
|
|
|
|
cmd2 = map(nchuk.joyY(),0,256,-150,150); // y - axis
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("X : "); Serial.println(nchuk.joyX());
|
|
|
|
|
|
|
|
Serial.print("Y : "); Serial.println(nchuk.joyY());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
display.setCursor(0, 40);
|
|
|
|
display.setCursor(0, 40);
|
|
|
|
display.setTextSize(1); // Draw 1X-scale text
|
|
|
|
display.setTextSize(1); // Draw 1X-scale text
|
|
|
|
display.setTextColor(SSD1306_WHITE);
|
|
|
|
display.setTextColor(SSD1306_WHITE);
|
|
|
|
@ -259,6 +268,7 @@ int old_cursorX, old_cursorY;
|
|
|
|
display.print(cmd2);
|
|
|
|
display.print(cmd2);
|
|
|
|
|
|
|
|
|
|
|
|
display.display();
|
|
|
|
display.display();
|
|
|
|
|
|
|
|
*/
|
|
|
|
Send(cmd1, cmd2);
|
|
|
|
Send(cmd1, cmd2);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -348,13 +358,14 @@ void loop(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned long timeNow = millis();
|
|
|
|
unsigned long timeNow = millis();
|
|
|
|
|
|
|
|
|
|
|
|
// Check for new received data
|
|
|
|
// Check for new received data
|
|
|
|
Receive();
|
|
|
|
// Receive();
|
|
|
|
// Nunchuk_display();
|
|
|
|
|
|
|
|
// show_dot();
|
|
|
|
|
|
|
|
// display.display();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Nunchuk_control();
|
|
|
|
if (iTimeSend > timeNow)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
iTimeSend = timeNow + TIME_SEND;
|
|
|
|
|
|
|
|
// Nunchuk_display();
|
|
|
|
|
|
|
|
Nunchuk_control();
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
// Send commands
|
|
|
|
// Send commands
|
|
|
|
if (iTimeSend > timeNow)
|
|
|
|
if (iTimeSend > timeNow)
|
|
|
|
@ -362,18 +373,6 @@ Nunchuk_control();
|
|
|
|
iTimeSend = timeNow + TIME_SEND;
|
|
|
|
iTimeSend = timeNow + TIME_SEND;
|
|
|
|
Send(0, cmd2);
|
|
|
|
Send(0, cmd2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
display.setCursor(0, 30);
|
|
|
|
|
|
|
|
display.setTextSize(1); // Draw 1X-scale text
|
|
|
|
|
|
|
|
display.setTextColor(SSD1306_WHITE);
|
|
|
|
|
|
|
|
display.print("Speed : ");
|
|
|
|
|
|
|
|
old_cursorX = display.getCursorX();
|
|
|
|
|
|
|
|
old_cursorY = display.getCursorY();
|
|
|
|
|
|
|
|
display.fillRect(old_cursorX, old_cursorY, (6 * 5), 8, SSD1306_BLACK); // erase previous display
|
|
|
|
|
|
|
|
display.setCursor(old_cursorX, old_cursorY);
|
|
|
|
|
|
|
|
display.print(cmd2);
|
|
|
|
|
|
|
|
display.display();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate test command signal
|
|
|
|
// Calculate test command signal
|
|
|
|
|
|
|
|
|
|
|
|
if (motor_test_direction == 1) cmd2 += 1;
|
|
|
|
if (motor_test_direction == 1) cmd2 += 1;
|
|
|
|
|