Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N64 need a delay between begin() and read() #22

Closed
Danjovic opened this issue Jul 17, 2019 · 7 comments
Closed

N64 need a delay between begin() and read() #22

Danjovic opened this issue Jul 17, 2019 · 7 comments

Comments

@Danjovic
Copy link

I was always getting and error while running N64Controller.ino example.
While troubleshooting the code I have found that if you went too fast between sending the initialization command (0x00) on begin() function to sending a request 0x01 on read() function the controller does not answer to the request.
The standard example code takes 23us from end of answer to command 0x00 to begin of command 0x01.
I have modified the example (see code below) and experimented some delay values and checked the output using a saleae logic analyzer.

void loop()
{
    N64Controller.begin();
    delayMicroseconds(100);  // Added delay
  // Try to read the controller data
  if (N64Controller.read())
  {
    // Print Controller information

with the added delay I still had issues while the total time was under 80us.

Then I suggest you to add such a delay right before returning on CN64Controller::begin(void) function or at least mention that issue in documentation.

@NicoHood
Copy link
Owner

Thanks for that suggestion!
I try to fix it soon.

@NicoHood
Copy link
Owner

NicoHood commented Sep 8, 2019

Sorry for the late reply.

I've checked the code, but it does not contain a begin() function at all. So Why did you add it? Is it even required? Or do you just need some delay inside the loop? What if you move the begin() to the end of the setup) function?

@Danjovic
Copy link
Author

Hi
The begin() method is inside the CN64Controller class (in N64API.h) . Such method is called implicitly by the read() method when the property 'Connected' is not true.
My N64 controller refuses to answer without a short delay between the initialization (gc_init() ) and the first read (n64_read() ). I think the controller need that time to properly initialize itself.
The loop() worked fine without much delay between consecutive readings.
To make the library built-in example work I just added a call to .begin() method followed by a delayMicroseconds(100) on the arduino setup()

@NicoHood
Copy link
Owner

@JonnyHaystack Can you maybe help here? I guess you are currently more into the code than me...

@JonnyHaystack
Copy link
Contributor

Not sure why this would be a problem sorry. I don't have a setup for testing with an N64 controller either

@Skuzee
Copy link

Skuzee commented Feb 25, 2021

My N64 controller is not recognized/initialized without adding a delay after begin() is called. Specifically in file: N64API.hpp, in the read function, between lines 81&82

bool CN64Controller::read(void)
{
    // Check if the controller was initialized
    if (!connected())
    {
        // Try to init the controller
        if (!begin())
        {
            return false;
        }
	delayMicroseconds(100);
    }

(I would fork and edit it, but I already have my own version of this library and git gets confusing for me.)

@NicoHood
Copy link
Owner

NicoHood commented Mar 6, 2021

Thank you guys! I've fixed the issue now. Please check that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants