Multiple Serial Ports

Hi,
I'm working on making a Wireless PS2 controller via wemos and an arduino Uno.
One wemos is conncted to a ps2 controller and sendings its data to another one with websocket.
The receiving Wemos is connected to an arduino so i can use UnoJoy library to emulate a HID gamepad.
I made a SoftSerial on pin 5 and 6, and a normal Serial to check if the Arduino receives Data from the soft serial.
But when i check the serial monitor on my computer, I only see the weird characters. I tried multiple Baudrates, both Serial and SoftSerial are on the same baudrate. The arduino com worked when i tried with just a simple serial loop.

It poses multiple problem not being able to read serial from arduino for debugging and check my data processing.

I followed this PS2 - WEMOS Controller | Hackaday.io, to get the communication between the 2 wemos. But since they use Vjoy and Python on the receiving PC,which doesn't really work on my pc. I have to process my data thru Arduino/UnoJoy.

Thanks for reading.

wifi_ws_server_AP_PS2__v6.ino (6.85 KB)

PS2XtoPC.ino (2.62 KB)

Serial monitor is connected to hardware serial, i.e. serial. The baud rate for Arduino serial must match that of the monitor - no exceptions. The monitor has an adjustment window in bottom right corner. No amount of fiddling with software serial will save you. Since serial and software serial have nothing to do with each other, it is quite OK to have them on different rates.

Since you are just using serial for debug, the default rate 9600 should not require changing.

Oh yea i know this, everytome i changed Baudrate, I also changed it on the Monitor, matching Baudrates and I have this problem, but it appears it only Happen on this sketch for a Reason i don't get.

OK, post the code in the proper manner, using </> code tags.

Here it is, There's no data processing for now.

#include <PS2X_lib.h>
#include "UnoJoy.h"
#include <SoftwareSerial.h>

#define PS2_DAT        13  //14    
#define PS2_CMD        11  //15
#define PS2_SEL        10  //16
#define PS2_CLK        12  //17

//#define pressures   true
#define pressures   false
//#define rumble      true
#define rumble      false

PS2X ps2x; // create PS2 Controller Class
SoftwareSerial Wemos (5,6);

int error = 0;
byte type = 0;
byte vibrate = 0;

void setup(){
  Serial.begin(57600);
  Wemos.begin(57600);
  setupUnoJoy();
  Serial.println("Serial Com Started");
  delay(1000);
}

void loop(){
  // Always be getting fresh data
  dataForController_t controllerData = getControllerData();
  setControllerData(controllerData);
  Serial.println(Wemos.read());
}

dataForController_t getControllerData(void){
  
  // Set up a place for our controller data
  //  Use the getBlankDataForController() function, since
  //  just declaring a fresh dataForController_t tends
  //  to get you one filled with junk from other, random
  //  values that were in those memory locations before
  dataForController_t controllerData = getBlankDataForController();
  // Since our buttons are all held high and
  //  pulled low when pressed, we use the "!"
  //  operator to invert the readings from the pins
  controllerData.triangleOn = !ps2x.Button(PSB_TRIANGLE);
  controllerData.circleOn = !ps2x.Button(PSB_CIRCLE);
  controllerData.squareOn = !ps2x.Button(PSB_SQUARE);
  controllerData.crossOn = !ps2x.Button(PSB_CROSS);
  controllerData.dpadUpOn = !ps2x.Button(PSB_PAD_UP);
  controllerData.dpadDownOn = !ps2x.Button(PSB_PAD_DOWN);
  controllerData.dpadLeftOn = !ps2x.Button(PSB_PAD_LEFT);
  controllerData.dpadRightOn = !ps2x.Button(PSB_PAD_RIGHT);
  controllerData.l1On = !ps2x.Button(PSB_L1);
  controllerData.r1On = !ps2x.Button(PSB_R1);
  controllerData.l2On = !ps2x.Button(PSB_L2);
  controllerData.r2On = !ps2x.Button(PSB_R2);
  controllerData.l3On = !ps2x.Button(PSB_L3);
  controllerData.r3On = !ps2x.Button(PSB_R3);
  controllerData.selectOn = !ps2x.Button(PSB_SELECT);
  controllerData.startOn = !ps2x.Button(PSB_START);
  
  // Set the analog sticks
  //  Since analogRead(pin) returns a 10 bit value,
  //  we need to perform a bit shift operation to
  //  lose the 2 least significant bits and get an
  //  8 bit number that we can use  
  controllerData.leftStickX = ps2x.Analog(PSS_LX), DEC;
  controllerData.leftStickY = ps2x.Analog(PSS_LY), DEC;
  controllerData.rightStickX = ps2x.Analog(PSS_RX), DEC;
  controllerData.rightStickY = ps2x.Analog(PSS_RY), DEC;
  // And return the data!
  return controllerData;
}

The WeMos boards I have all default to 74880 baud.
Leo..

My wemos works fine, it's the Uno that don't seem to print right. the Serial.println("Serial Com Started");" is here to check if the glitch comes from the Arduino or the data, and it's glitched as well. so it should be the arduino that's acting weird.

UnoJoy does what?

I'm surprised Wemos works at that speed, but you say it does, and it may be irrelevant to this problem. So do you see

Serial Com Started

on the monitor?

If not, what are the settings on the serial monitor panel?

If yes, I'm guessing Arduino is innocent, your monitor is correctly set, and either

  1. my concern about you running software serial at that speed is vindicated after all, or

  2. you are getting junk input.

UnoJoy lets you use a plain, unmodified Arduino Uno
to create native USB joysticks. It is a three-part system:

Drivers - Needed to re-flash the Arduino's USB communication chip
Software - The UnoJoy library for Arduino
Firmware - Code to load onto Arduino's USB communication chip

Once you changed the Uno boards USB chip it doesn't work in CDC mode anymore, only HDI like you wanted.

With a Leonardo you already get to switch into and just as important, out of HID mode.

Oh gee, that site doesn't seem to tell how to change your Uno back!

No I don't see the "Serial com Started", it displays

⸮⸮cn⸮p⸮⸮o⸮

the last part is looped so it's the data. My Monitor is set to 57600 BaudRate.

UnoJoy turns the Arduino into a HID Gamepad on the PC when i flash the 16U2 as HID, It will be using when i'm done coding it. Serial Worked with it before tho.

I have Bat files to turn it into HID or into Serial again. The Serial works with other sketches.

BAT files. To change the component on your PC. This gets richer as it goes.

Why not just get a Leo or Micro or Teensy 2.0 and you can switch dynamically since the AVR chip is the USB chip?

Nah, the bat flash just flashes the 16u2, sorry, I should have been more specific.
Well, Arduino and wemos is all I have right now.
I made it work with only Arduino, it's trying to get it Wireless that goes wrong.

PS2 > Arduino > PC : works.
PS2 > Wemos Client > Wemos Server > Arduino > PC : Serial doesn't work.

I fixed the Serial by putting my Serial.begin(56700) AFTER setupUnoJoy();
It was UnoJoy interfering with the Serial com:

void setup(){
  setupUnoJoy();
  Serial.begin(57600);
  Wemos.begin(57600);
  Serial.println("Serial Com Started");
  delay(1000);
}

Instead of :

void setup(){
  Serial.begin(57600);
  Wemos.begin(57600);
  setupUnoJoy();
  Serial.println("Serial Com Started");
  delay(1000);
}