SukkoPera / PsxNewLib

Playstation controller interface library for Arduino
GNU General Public License v3.0
130 stars 28 forks source link

Trying for most part of 2 days to get this working #14

Closed L10N37 closed 3 years ago

L10N37 commented 3 years ago

I spent a few hours trying to get the original PS2x working - I noticed no one mentions the 3.3v logic and runs 5v.. I've used a 1K and 2K resistor on all lines - I couldn't get my official controllers analogue mode LED to light on 3.3v so I'm using an LDO 3.3v regulator on the 5v line. That seems to let the analogue button turn the LED on at least. I have 10k pull up on pin one (data) , I have another USB port on a 9v step cable on an input jack split off to power Pin 3 for rumble. The unused Pin 9 is on a pullup resistor (because I've tried everything).

I mean at least I was able to figure out it was the DATA line causing your version of the library to print in the serial monitor that i'm pushing every button at once... otherwise it doesn't detect a controller.

Using Arduino UNO R3 - successfully hacked up an SD card breakout board earlier and was able to read / write to FAT32 card by using the same resistors to convert necessary lines etc without a guide - definitely sure the arduino isn't the issue.

Any pointers here? Tried genuine controllers / aftermarket controllers... PS1 / PS2

L10N37 commented 3 years ago

2K -> GND 1K -> signal lines to arduino board Centre of resistors (where 2k meets 1k) to controller pins= reduce high 5v to 3.33v (on paper)

I've now switched them to 1k pullups from ~10k (tried 5 as well) Now I just get "ready"

SukkoPera commented 3 years ago
  1. Use 1k pull-up on the CLK, DAT and CMD lines. "Pull-up" means resistors go between each of those pins and +3.3V.
  2. You can ignore ACK for the moment.
  3. You can also ignore the Rumble power.
  4. Make sure the Arduino pins you're using match those defined in the sketch.
  5. Use an external LDO to produce the 3.3V, don't use a voltage divider. The onboard Arduino regulator should be sufficient for a single controller.

On a side note, I don't think anything in my library says Ready. They should rather go Controller found...

L10N37 commented 3 years ago

The "ready" is from your HW SPI and bitbang examples for the condition have controller = false. I've attached 1k pull up to the those 3 lines, I didn't think data would need it as it's usually already 'INPUT_PULLUP' and clock and CMD outputs idle high. Now I don't get anything on the screen.

Keeping in mind I'm an absolute beginner, I've been able to at least get a response in the terminal with my own code using SPI.h library.. if I send it anything during the monitor, I receive a '1' if a controller is plugged in and powered on, and a zero if anything else. It's not exactly what I wanted (trying to send 0x01 0x42 initialisation and receive controller type in hex) but after all the playing around I've done, it's at least "something". This is using digital read on the data line after a read pulse just before or just after the SPI transaction ends. I will try and learn some more later.

Still baffled on why yours and the original library aren't working - I'm using the standard SPI in map for UNO, D10:D13 but this video [https://www.youtube.com/watch?v=aC_moW2T7e4] seems to think otherwise... I haven't tried that as it doesn't make sense!

here's my code anyways, maybe you could help out. I am only trying to learn how to read button states to capture a START+SELECT combo then { do stuff }

include

define ATTENTION 10 /* PULL LOW with clock AND SEND '0X01' DOWN 'COMMAND' TO RECEIVE CONTROLLER ID

                          LOW DURING TRANSMISSION / SPI COMMUNICATION, HIGH END OF TRANSMISSION{SPI: LIKE CS)  https://www.sparkfun.com/spi_signal_names */

define DATA 11 //DATA FROM CONTROLLER TO CONSOLE (SPI: LIKE MISI)

define COMMAND 12 //DATA FROM CONSOLE TO CONTROLLER (SPI: LIKE MISO)

define CLOCK 13 // CLOCK TO PIN 13, NORMALLY HIGH, 250KHZ FOR PSX

define PSX_Controller PORTB

const int SEND_READ_PULSE = (0B011000); //ATTENTION LOW, CLOCK, LOW & SEND START COMMAND, SHOULD RECEIVE CONTROLLER ID (PORTB maps to Arduino digital pins 8 to 13) const int IDLE_PULSE = (0B111100); //SPI knows to pull ATT low but this adds clock const int START_COMMAND = (0x01, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); volatile int controller_type = 0; //variable to store controller type int read_latch = 0; //variable for latching read mode between idle pulse int idle_latch = 0; //variable for latching idle mode between read pulse int looptime = 0; //debug

void setup() {

Serial.begin (115200); //set the serial transmission baud rate for communicating with the serial monitor // SET CS AS OUTPUT AND REST HIGH pinMode (ATTENTION, OUTPUT); digitalWrite (ATTENTION, HIGH); // //set att to rest high pinMode (DATA, INPUT_PULLUP); //SET DATA LINE AS INPUT FROM CONTROLLER TO ARDUINO pinMode (COMMAND, OUTPUT); //SET COMMAND LINE AS OUTPUT FROM ARDUINO TO CONTROLLER pinMode (COMMAND, HIGH); //SET COMMAND TO REST HIGH pinMode (CLOCK, OUTPUT); //SET CLOCK AS AN OUTPUT FROM ARDUINO TO CONTROLLER digitalWrite (CLOCK, HIGH); //SET CLOCK TO REST HIGH digitalWrite (8, LOW); //unused pins in PSX_Controller set to low digitalWrite (9, LOW); //** //SPI.begin; // doing this manually with register states

}

void loop() { delay (850); Serial.print ("Cycles: "); Serial.println (++looptime);

// == == == == = serial monitor stuff == == == == == == if (Serial.available() > 0) { Serial.print ("Controller Type: "); Serial.println(controller_type, HEX); } //== == == == == == == == == == == == == == == ==

if (idle_latch == 1) { read_latch = 0; //PSX_Controller = IDLE_PULSE; //shift (port B) SPI register into idle / resting mode }

if (read_latch == 1) { idle_latch = 0; PSX_Controller = SEND_READ_PULSE; //shift (port b) SPI register into read mode

}

delay (50);

SPI.beginTransaction(SPISettings(250000, LSBFIRST, SPI_MODE3)); // 250khz / least significant bit first / SPI mode 3 delay (50); read_latch = 1; SPI.transfer (START_COMMAND, 8); //SEND 8 initiation bytes to controller (2 bytes 6 nulls) delay (50); controller_type = digitalRead(DATA); //read bytes on data line and store in the controller_type variable SPI.endTransaction(); //end transmission idle_latch = 1; //return to idle

}

L10N37 commented 3 years ago

From what I can tell it's just picking up the pull up resistor on data and showing 1 when the ports plugged in, or a zero when the pullups removed because the ports not plugged in as I'm powering it from a separate barrel onto the 3.3v LDO.

...I guess that's not an indication of getting anywhere with this at all

SukkoPera commented 3 years ago

Ok, the Ready is there, but it's printed unconditionally at the very start of the sketch, before the library even tries to detect anything. It's just there to show that the sketch has started.

I suggest you write a post on the Arduino forum. This is only a place to report bugs in this library. I suspect you are using the wrong pins or are not connecting the pull-ups correctly. There's not much more that can go wrong. Maybe get one of my PsxControllerShields.