ArduinoGeneral

Arduino Uno, Problem with Serial1 without USB connected

userHead marc.rupprath 2020-09-18 16:18:57 752 Views1 Replies
Hello all,
i have a strange beaviour with serial1 on arduino uno.
I am not using serial (attached to USB) at all , unfortunately my serial1 communication using plainprotocol.lib
is not working without USB on df wirelass gamepad attached.

See code below:

#include <Arduino.h>
#include <PlainProtocol.h>
#include "OneButton.h"
#include <Arduino_FreeRTOS.h>

void TaskGreenLed( void *pvParameters );

// # Product name: Wireless Joystick v2.2 for Arduino
// # Product SKU : DFR0182
// # Code Version: 2.0

// # Description:
// # The sketch for using the gamepad and print the button state and the analog values of the gamepad
// # to computer screen using serial monitor


String Buttons[17] = {"J2","J1","","S2","S1","UP","LEFT","DOWN","RIGHT","1","4","2","3","RZ1","RZ2","LZ1","LZ2"};
String JoystickName[4] = {"RX","RY","LX","LY"};
// Buttons Nmes

int buttonState[17];
int joystickState[4];
int AnalogButton[2];

int inputCommand = 0;

#define shackMotorPin 2
#define UBRR1H true

PlainProtocol GamepadData(Serial1, 9600);

OneButton StartButton(3, true);
OneButton SelectButton(4, true);
OneButton UpButton(5, true);
OneButton LeftButton(6, true);
OneButton DownButton(7, true);
OneButton RightButton(8, true);
OneButton Button_1(9, true);
OneButton Button_4(10, true);
OneButton Button_2(11, true);
OneButton Button_3(12, true);
OneButton Button_RZ1(13, true);
OneButton Button_RZ2(14, true);
OneButton Button_LZ1(15, true);
OneButton Button_LZ2(16, true);



void TaskGreenLed(void *pvParameters)
{
pinMode(17, OUTPUT);
while(1)
{
digitalWrite(17, HIGH);
vTaskDelay( 200 / portTICK_PERIOD_MS );
digitalWrite(17, LOW);
vTaskDelay( 200 / portTICK_PERIOD_MS );
}
}


void InitIO()
{
for(int i = 0; i < 17; i++ )
pinMode(i, INPUT);
pinMode(shackMotorPin,OUTPUT);
digitalWrite(shackMotorPin,LOW); // Stop shacking of the gamepad
}

void DataUpdate()
{

for(int i = 2; i < 17; i++ ) buttonState = digitalRead(i);
buttonState[0] = analogRead(0);
buttonState[1] = analogRead(1);
for(int i = 0; i < 4; i++ ) joystickState = analogRead(i);
for(int i = 4; i < 6; i++ ) AnalogButton[i-4] = analogRead(i);

}



// Up Buttom
void UpButtonPressed()
{
GamepadData.write("UP",2000); //set the speed to 100
}

void UpButtonUnPressed()
{
GamepadData.write("UP",1000); //set the speed to 100
}



// Down Button
void DownButtonPressed()
{
GamepadData.write("DOWN",2000); //set the speed to 100
}

void DownButtonUnPressed()
{
GamepadData.write("DOWN",1000); //set the speed to 100
}

/*******************************BaseDrive**************************/
//Left - drive on

void LeftButtonPressed()
{
GamepadData.write("BaseDrive",2000); //set the speed to 100
}

//Left - drive off
void LeftButtonUnPressed()
{
GamepadData.write("BaseDrive",1500); //set the speed to 100
}

// Right - drive on
void RightButtonPressed()
{
GamepadData.write("BaseDrive",1000); //set the speed to 100
}

// Right - drive off
void RightButtonUnPressed()
{
GamepadData.write("BaseDrive",1500); //set the speed to 100
}

/****************BaseDrive - End **************************/

void setup()
{
xTaskCreate(TaskGreenLed ,"TaskGreenLed",128,NULL,1,NULL);
Serial1.begin(9600);
GamepadData.init();
InitIO();
UpButton.attachLongPressStart(UpButtonPressed);
UpButton.attachLongPressStop(UpButtonUnPressed);
UpButton.setPressTicks(10);

DownButton.attachLongPressStart(DownButtonPressed);
DownButton.attachLongPressStop(DownButtonUnPressed);
DownButton.setPressTicks(10);

LeftButton.attachLongPressStart(LeftButtonPressed);
LeftButton.attachLongPressStop(LeftButtonUnPressed);
LeftButton.setPressTicks(10);

RightButton.attachLongPressStart(RightButtonPressed);
RightButton.attachLongPressStop(RightButtonUnPressed);
RightButton.setPressTicks(10);


}

void loop()
{

UpButton.tick();
DownButton.tick();
LeftButton.tick();
RightButton.tick();
delay(100);

}

Wonder why there is a debencency between Hardare Serial1 and USB (Serial) ?!
2020-09-18 17:22:39 Problem seems to be solved:
I have a Wireless Gamepad and uses the XBEE socket.
During development XBEE module us outside, connection thrue xbee serial pins is made with wires.

Until XBEE modules has been inserted into socket problem no longer exists.
userHeadPic marc.rupprath