Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 20:28 25 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMite: Nunchuk controller

Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 06:08pm 16 Apr 2024
Copy link to clipboard 
Print this post

Hi folks (especially @Volhout),

For completeness I'm trying to add PicoMite Wii Nunchuk support to my controller library. Unlike the Wii Classic, support for the Nunchuk isn't provided through the firmware (though presumably it could be*) but @Volhout posted some MMBasic I2C code here.

* But please hold off and let me have my fun first Peter.

What I don't understand is what this code is doing with GP3 ... is this one of the pins allocated via OPTION SYSTEM I2C ? If so then there doesn't seem to be any way (parameter to MM.INFO) to determine this dynamically and thus the code is tied to a specific setting of this OPTION ?

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 06:11pm 16 Apr 2024
Copy link to clipboard 
Print this post

... there doesn't seem to be a call to I2C OPEN either.

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4226
Posted: 07:42pm 16 Apr 2024
Copy link to clipboard 
Print this post

Hi Tom,

Gp3 is connected to the nunchuck connector, and is pulled high then a connector is inserted..
The VGA basic V2 board by Mixtel90 features this connection.
Since it is the only board I have with a nunchuck connection, I supported it.

I2C is connected to system I2C, set in the OPTIONS.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6784
Posted: 08:32pm 16 Apr 2024
Copy link to clipboard 
Print this post

That trick with GP3 is a way to make sure the controller plug is plugged in the correct way up. It's not a standard connection (and isn't present on any other boards AFAIK) but should work with all WII-compatible controllers.

There won't be an I2C OPEN if it's already open as system I2C.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 09:19am 17 Apr 2024
Copy link to clipboard 
Print this post

Thanks guys, that explains the GP3 mystery. I'm using a PicoGAME 1.4 with a hacked together Nunchuk->D-SUB 9 cable* connecting the Classic/Nunchuk to Port A.

* Easy to do in concept, a complete bleeding faff to splice together the cables in practice, mine is held together by dodgy soldering and prayer.

It works with the firmware's Classic controller support but I have yet to succeed with the Nunchuk and @Volhout's code.

Speaking of which on the 5th line of that code this confuses me:

Const WII=&h52    'I2C device address


I though the I2C device address of a Wii controller was &hA4; not that changing it to that magically makes it work .

Best wishes,

Tom
Edited 2024-04-17 19:22 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3801
Posted: 10:38am 17 Apr 2024
Copy link to clipboard 
Print this post

I2C are 7-bit. The 8th is read/write I gather.

Sounds like the 8th is bit 0.

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9111
Posted: 11:10am 17 Apr 2024
Copy link to clipboard 
Print this post

From the manual

  Quote  7-Bit Addressing
The standard addresses used in these commands are 7-bit addresses (without the read/write bit). MMBasic will
add the read/write bit and manipulate it accordingly during transfers.
Some vendors provide 8-bit addresses which include the read/write bit. You can determine if this is the case
because they will provide one address for writing to the slave device and another for reading from the slave. In
these situations you should only use the top seven bits of the address. For example: If the read address is 9B
(hex) and the write address is 9A (hex) then using only the top seven bits will give you an address of 4D (hex).
Another indicator that a vendor is using 8-bit addresses instead of 7-bit addresses is to check the address range.
All 7-bit addresses should be in the range of 08 to 77 (hex). If your slave address is greater than this range then
probably your vendor has provided an 8-bit address.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4226
Posted: 11:50am 17 Apr 2024
Copy link to clipboard 
Print this post

Hi Tom,

Peter already explained. 7 bit address is 0x52, 8bit address would be 0xA4.

Find attached info on nunchuck, and circuit diagram of the board I used, including the connection to GP3.
Note that Mick did a smart move to connect 3.3V power to the nunchuck to the ID pin and used the power pin at the connector to detect the nunchuck is connected.
Inside the nunchuck the power pin and ID pin are wired together.
By making Micks change, there is no harm done if you put the connector in reversed (upside down). Without a housing that block the upside down pluging, you might blow up the nunchuck.

MiniVGA2.zip

Volhout
Edited 2024-04-17 21:51 by Volhout
PicomiteVGA PETSCII ROBOTS
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 12:36pm 17 Apr 2024
Copy link to clipboard 
Print this post

Thanks everyone.

  Volhout said  Without a housing that block the upside down pluging, you might blow up the nunchuck.


Not an issue for me, I spliced together one end of a Wii extension cable (with male housing) and a 9-pin Atari cable (with female housing). It works with the firmware's Classic Controller support so that strongly suggests I didn't mess it up.

* Note that unlike the CMM2 the PicoMite does not appear to check the attached controller is actually a Classic (i.e. that it has id 0xA4200101) so you can attach a Nunchuk (id 0xA4200100), read it with DEVICE WII and get (spurious) output.

* Also since Peter apparently has an eye on this thread, note that there are some debug style messages being generated when errors occur in cmd_Classic(), e.g. "Wii device not connected<N>" where N is 1..4.

Obviously I'm doing something wrong (probably something simple/fundamental) so more poking is required this evening.

Best wishes,

Tom
Edited 2024-04-17 22:44 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4226
Posted: 03:03pm 17 Apr 2024
Copy link to clipboard 
Print this post

Tom,

I have absolutely no experience with Peter's implementation of the classic, I just worked with the I2C commands in my code. But I noticed the PicoGame 1.4 has 10k pullups on the board at GP0 and GP1, and OPTION SYSTEM I2C sets up the I2C connection for 400kHz default.

It may be needed to change the 10k resistors to 2.2k (-or- add 3.3k pullups inside the extension cable which will give you 2.5k combined with the 10k inside the PicoGame).

Otherwise specify "SLOW" in the OPTION SYSTEM I2C sda,scl,SLOW

Regards,

Volhout
Edited 2024-04-18 01:06 by Volhout
PicomiteVGA PETSCII ROBOTS
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 09:59am 18 Apr 2024
Copy link to clipboard 
Print this post

Hi @Volhout,

I've got it working .

  Volhout said  ... But I noticed the PicoGame 1.4 has 10k pullups on the board at GP0 and GP1, and OPTION SYSTEM I2C sets up the I2C connection for 400kHz default ...


None of this turned out to be significant, I didn't think it would because as I said the Classic controller (via the firmware) was working fine with this hardware setup.

Issues were:

1. The highlighted line was causing the initial id read to return the wrong value:
Sub init_no_enc
  I2C write WII,0,2,&h40,&h00 ' <--------
  Pause 10
  I2C write WII,0,2,&hF0,&h55
  I2C write WII,0,2,&hFB,&h00
End Sub


This doesn't surprise me as this is the sequence to initialise the Nunchuk with encryption, which you immediately follow with the lines to initialise it with no encryption ... I think you are meant to do either one or the other.

2. My PicoGAME hardware arrangement had SYSTEM I2C on *I2C2* (GP26/GP27). Once I figured out what the resulting MMBasic error message meant I updated all the calls.

3. I was incorrectly treating the X & Y values from the accelerometer as if they were the X & Y values from the joystick - D'Oh !

4. The Nunchuk interface returns the values of the two buttons as inverted which I don't think your example code accounts for.

Anyway, sorted now, thank you!

Best wishes,

Tom
Edited 2024-04-18 20:32 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4226
Posted: 12:13pm 18 Apr 2024
Copy link to clipboard 
Print this post

Hi Tom,

I must have misunderstood the function of

I2C write WII,0,2,&h40,&h00

I thought it would initialize the gyro's and analog joystick, and put encryption on as well. If you can do without, fine...

Regards,

Volhout
PicomiteVGA PETSCII ROBOTS
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024