|
|
|
|
@ -30,10 +30,17 @@
|
|
|
|
|
// // #define DEBUG_SERIAL_USART3
|
|
|
|
|
// *******************************************************************
|
|
|
|
|
|
|
|
|
|
#define VERSION_TAG "v test 0.2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ########################## DEFINES ##########################
|
|
|
|
|
#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 HOVER_SERIAL_BAUD 115200 // [-] 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 START_FRAME 0xAAAA // [-] Start frme definition for reliable serial communication
|
|
|
|
|
// #define START_FRAME 0xAAAA // [-] Start frme definition for reliable serial communication
|
|
|
|
|
#define START_FRAME 0xABCD // [-] Start frme definition for reliable serial communication
|
|
|
|
|
|
|
|
|
|
#define TIME_SEND 25 // [ms] Sending time interval
|
|
|
|
|
#define SPEED_MAX_TEST 300 // [-] Maximum speed for testing
|
|
|
|
|
//#define DEBUG_RX // [-] Debug received data. Prints all bytes to serial (comment-out to disable)
|
|
|
|
|
@ -92,13 +99,20 @@ int motor_test_direction = 1;
|
|
|
|
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
|
|
|
|
|
// Connect to a Nunchuk
|
|
|
|
|
Nunchuk nchuk;
|
|
|
|
|
HardwareSerial Serial1(PA_10, PA_9);
|
|
|
|
|
|
|
|
|
|
// ########################## SETUP ##########################
|
|
|
|
|
void setup()
|
|
|
|
|
{
|
|
|
|
|
Serial.begin(SERIAL_BAUD);
|
|
|
|
|
if (Serial) {
|
|
|
|
|
Serial.println(VERSION_TAG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nchuk.begin();
|
|
|
|
|
while (!nchuk.connect()) {
|
|
|
|
|
Serial.println("nunchuck not connected");
|
|
|
|
|
delay(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)
|
|
|
|
|
// Clear the buffer
|
|
|
|
|
@ -112,8 +126,8 @@ void setup()
|
|
|
|
|
(strlen("Hoverboard Serial") * 6)) / 2), 0);
|
|
|
|
|
display.println("Hoverboard Serial");
|
|
|
|
|
display.setCursor(int
|
|
|
|
|
((display.width() -(strlen("v STM32 0.1") *6))/2), 8);
|
|
|
|
|
display.println("v STM32 0.1");
|
|
|
|
|
((display.width() -(strlen(VERSION_TAG) *6))/2), 8);
|
|
|
|
|
display.println(VERSION_TAG);
|
|
|
|
|
/*
|
|
|
|
|
display.print("Nunchuk ");
|
|
|
|
|
nchuk.connect()? display.print("") : display.print("not ");
|
|
|
|
|
@ -126,10 +140,6 @@ void setup()
|
|
|
|
|
Serial1.begin(HOVER_SERIAL_BAUD); // RX, TX from arduino to TX RX on hoverboard board. ! be carreful 3v3
|
|
|
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
|
|
|
|
|
|
|
|
Serial.begin(SERIAL_BAUD);
|
|
|
|
|
if (Serial) {
|
|
|
|
|
Serial.println("Hoverboard Serial v STM32 0.1");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ########################## SEND ##########################
|
|
|
|
|
@ -236,18 +246,18 @@ void Nunchuk_control()
|
|
|
|
|
int old_cursorX, old_cursorY;
|
|
|
|
|
|
|
|
|
|
if (!nchuk.update()) {
|
|
|
|
|
nchuk.reconnect();
|
|
|
|
|
nchuk.connect();
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,-1000,1000); // y - axis
|
|
|
|
|
|
|
|
|
|
Serial.print("X : "); Serial.println(nchuk.joyX());
|
|
|
|
|
Serial.print("Y : "); Serial.println(nchuk.joyY());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
display.setCursor(0, 40);
|
|
|
|
|
display.setTextSize(1); // Draw 1X-scale text
|
|
|
|
|
display.setTextColor(SSD1306_WHITE);
|
|
|
|
|
@ -265,12 +275,13 @@ int old_cursorX, old_cursorY;
|
|
|
|
|
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();
|
|
|
|
|
*/
|
|
|
|
|
Send(cmd1, cmd2);
|
|
|
|
|
|
|
|
|
|
Send(cmd1, cmd2);
|
|
|
|
|
// Send(0, cmd2);
|
|
|
|
|
}
|
|
|
|
|
// ########################## nunchuk ##########################
|
|
|
|
|
|
|
|
|
|
@ -280,7 +291,7 @@ void Nunchuk_display()
|
|
|
|
|
if (Serial) {
|
|
|
|
|
Serial.println("Controller disconnected!");
|
|
|
|
|
}
|
|
|
|
|
nchuk.reconnect();
|
|
|
|
|
nchuk.connect();
|
|
|
|
|
} else {
|
|
|
|
|
if (Serial) {
|
|
|
|
|
// Read a button (on/off, C and Z)
|
|
|
|
|
@ -342,7 +353,7 @@ char text[22];
|
|
|
|
|
display.drawPixel(x_d,y_d,SSD1306_WHITE);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
nchuk.reconnect();
|
|
|
|
|
nchuk.connect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -359,7 +370,7 @@ void loop(void)
|
|
|
|
|
unsigned long timeNow = millis();
|
|
|
|
|
|
|
|
|
|
// Check for new received data
|
|
|
|
|
// Receive();
|
|
|
|
|
Receive();
|
|
|
|
|
|
|
|
|
|
if (iTimeSend > timeNow)
|
|
|
|
|
return;
|
|
|
|
|
|