sketchbook
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
Uno_N64_Controller_Pak_Reader.ino File Reference

Nintendo 64 Controller Pak Reader for Arduino (Uno+SD Card) More...

#include <SdFat.h>

Macros

#define ENABLE_SD
 
#define EEPROM_SIZE_EMULATED   8
 
#define chipSelectPin   10
 
#define N64_PIN   2
 
#define N64_HIGH   DDRD &= ~0x04
 
#define N64_LOW   DDRD |= 0x04
 
#define N64_QUERY   (PIND & 0x04)
 

Functions

void setup ()
 
template<class T >
int EEPROM_writeAnything (int ee, const T &value)
 Emulate EEPROM write function with help of storage on SD. More...
 
template<class T >
int EEPROM_readAnything (int ee, T &value)
 Emulate EEPROM read function with help of storage on SD. More...
 
void N64_send (unsigned char *buffer, char length)
 
void N64_stop ()
 
void N64_get (word bitcount)
 
void get_button ()
 
void readBlock (word myAddress)
 read 32bytes from controller pak More...
 
void readMPK ()
 reads the MPK file to the sd card More...
 
void loop ()
 

Variables

SdFat sd
 
SdFile myFile
 
char N64_raw_dump [257]
 
byte myBlock [33]
 
int foldern
 
char fileName [26]
 
unsigned long writeErrors
 
int incomingByte
 
byte sdBuffer [32]
 
String rawStr = ""
 
struct {
   char   stick_x
 
   char   stick_y
 
N64_status
 
String button = "N/A"
 

Detailed Description

Nintendo 64 Controller Pak Reader for Arduino (Uno+SD Card)

Author
sanni, drtrigon
Date
2018-04-24
Version
V1C
See Also
https://github.com/sanni/cartreader/issues/16
https://github.com/sanni/cartreader/blob/master/Cart_Reader/N64.ino
http://www.instructables.com/id/Use-an-Arduino-with-an-N64-controller/
* SD lib:
*   https://github.com/greiman/SdFat
* Needs EEPROMAnything.h copied into sketch folder:
*   https://github.com/sanni/cartreader/blob/master/Cart_Reader/EEPROMAnything.h
* DIY SD Card interface/adapter:
*   http://www.instructables.com/id/Cheap-DIY-SD-card-breadboard-socket/
*   http://www.bot-thoughts.com/2010/02/logging-data-to-sd-cards.html
*   https://www.arduino.cc/en/Reference/SDCardNotes
* Inspect (check/test) MPK data read:
*   https://github.com/bryc/mempak
*   https://rawgit.com/bryc/mempak/master/index.html
*
* Pinout:
*   https://github.com/sanni/cartreader/issues/16#issuecomment-383758731
*   N64 - view on controller connector:
*     _____
*    /     \    1: GND        -> Arduino GND
*   | 1 2 3 |   2: DATA       -> Arduino Pin 2
*   |_______|   3: VCC (3.3V) -> Arduino 3.3V
*   (contacts start after about 5mm inside the hole)
*   SD Card:    1: CS         -> Arduino Pin 10
*               2: DI/MOSI    -> Arduino Pin 11
*               3: VSS/GND    -> Arduino GND
*               4: VDD/+3.3V  -> Arduino 3.3V
*               5: SCK/CLK    -> Arduino Pin 13
*               7: DO/MISO    -> Arduino Pin 12
*     Format: use https://github.com/greiman/SdFat/blob/master/examples/SdFormatter/SdFormatter.ino
*
* Can also be used for reading WITHOUT SD Card:
*   1. uncomment "#define ENABLE_SD" below, then compile/upload the code to an Arduino Uno
*   2. $ sudo miniterm.py /dev/ttyACM0 | tee n64-controllerpak-01.log
*        in the menu chose '0' to dump to console
*   3. open .log in text-editor (e.g. kate) and remove all lines except
*        the ones containing the hex dump and store as it .hex - needs to be 1024 lines
*   4. $ xxd -r -p n64-controllerpak-01.hex n64-controllerpak-01.mpk
*   5. $ ls -la n64-controllerpak-01.mpk
*        check size needs to be 32768 and compare the .hex with .mpk using e.g. mc
*        finally inspect it on: https://rawgit.com/bryc/mempak/master/index.html
*
* Thanks to:
* Andrew Brown/Peter Den Hartog - N64 send/get functions
* Shaun Taylor - address/data CRC functions
* 

Macro Definition Documentation

#define chipSelectPin   10
#define EEPROM_SIZE_EMULATED   8
#define ENABLE_SD
#define N64_HIGH   DDRD &= ~0x04
#define N64_LOW   DDRD |= 0x04
#define N64_PIN   2
#define N64_QUERY   (PIND & 0x04)

Function Documentation

template<class T >
int EEPROM_readAnything ( int  ee,
T value 
)

Emulate EEPROM read function with help of storage on SD.

template<class T >
int EEPROM_writeAnything ( int  ee,
const T value 
)

Emulate EEPROM write function with help of storage on SD.

void get_button ( )
void loop ( void  )

OneWirePJON device status update function.

Returns
(void)
void N64_get ( word  bitcount)
void N64_send ( unsigned char *  buffer,
char  length 
)
void N64_stop ( )
void readBlock ( word  myAddress)

read 32bytes from controller pak

void readMPK ( )

reads the MPK file to the sd card

void setup ( void  )

Arduino IDE: put your setup code here, to run once.

Variable Documentation

String button = "N/A"
char fileName[26]
int foldern
int incomingByte
byte myBlock[33]
SdFile myFile
char N64_raw_dump[257]
struct { ... } N64_status
String rawStr = ""
SdFat sd
byte sdBuffer[32]
char stick_x
char stick_y
unsigned long writeErrors