Arduino RF NES Controllers
by BambooEngineer in Circuits > Arduino
1116 Views, 5 Favorites, 0 Comments
Arduino RF NES Controllers
Introduction-
Sooooooo for a future project I want wireless controllers instead of the simplistic 'wired' + I've always wanted to get into RF design stuff. NES controllers seemed really nice and basic to use for this since this was my first time using RF modules. Also Only 4 Buttons are needed for my future project so it turned out really nice.
Knowledge Needed-
Gotta know what your doing with Arduino Libraries
PARTS-
2x Arduino Uno(Optional, used for RF Reciever but you could use another board)Extra one for breadboarding transmitter)
https://www.amazon.com/KEYESTUDIO-Board-Compatible...
Arduino Nano
https://www.amazon.com/ELEGOO-Arduino-ATmega328P-W...
RF Modules
https://www.amazon.com/ATmega328P-Microcontroller-...
NES Controllers
https://www.amazon.com/Mekela-Controller-Joystick-...
Breadboards
https://www.amazon.com/Elegoo-EL-CP-003-Breadboard...
Jumper Wire
https://www.amazon.com/Nano-Stranded-Flexible-Insu...
LEDs&Resistors(Optional, I chose to use LEDs to show me everything was working in the end)
https://www.amazon.com/Miuzei-Resistors-Assortment...
TOOLS NEEDED-
Soldering Iron
Hot Glue Gun(Recommended)
Screw Driver or Something else to open NES Controllers
Wire Cutters (Cutting and Stripping the Jumper Wire)
Pencil or Pen to wrap the Jumper Wire around to make an Antenna
TESTING THE RF MODULES ON BREADBOARDs
Head over to RadioHead's website. Install the Library and look over the functions in the RH_ASK section to understand the code better.
http://www.airspayce.com/mikem/arduino/RadioHead/i...
Plug in your Arduino Boards and Upload the code below. Make one Arduino the receiver and the other the transmitter. Once they both have the uploaded code, wire them up on breadboards.
RF ANTENNAS-
Take jumper wire(Solid core)
Roll on a pencil or pen and get about 8 to 10 turns (For Receiver)
then solder to the back of the Module's BOTTOM RIGHT corner. There should be spot to solder.
Take the same type of wire and make it 4x the length as the receivers antenna then solder to the transmitter Module
There should be a hole to solder through in the front TOP RIGHT
BREADBOARD WIRING-
Data pins for both modules should be going to digital pin 2 of the Arduinos!
Observe the Serial monitor on the Receiver Arduino
(You could change the pins for them to go to with the RH_ASK driver() function. Its on the Radiohead site.)
Credits to Antony Cartwright for this modified library example code!
RECIEVER TEST CODE-
#include
#include // Not actually used but needed to compile
RH_ASK driver(2000, 2, 9, 10);
void setup() {
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop() {
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)){
int i;
String str = "";
for(int i = 0; i< buflen; i++){
str += (char)buf[i];
}
Serial.println(str);
}
}
TRANSMITTER TEST CODE-
#include
#include // Not actually used but needed to compile
RH_ASK driver(2000, 9, 2, 10);
void setup() {
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop() {
const char *msg = "hello";
driver.send((uint8_t *)msg, strlen(msg)); driver.waitPacketSent(); delay(200);
}
Disassembling NES Controllers and Making Sure the NANO Fits
Grab your screwdriver and open up the controller. Take a look at the PCB. Look at the button circuitry and spot the places to scrape and solder.
Plan where to put the Nano board. If you want to make the Nano's USB port accessible your gonna have to cut a little bit of the controller's casing. Then once your happy with the position of the Nano HOT GLUE it in place.
Wiring NES Controllers and RF TRANSMITTER to the NANO
Look at the Transmitter code to REALLY know where everything is wired on the Nano board.
After scrapping a button output trace to expose the copper, just be careful not to accidentally rip the wire off after soldering, which would rip the copper traces off.
Scrape carefully and solder precisely then hot glue. Make sure the position of the wire does not fall under the button material (The 'rubber like' things under the Actual physical buttons)
I ONLY WIRED TO 4 BUTTONS CAUSE I ONLY NEEDED 4 BUTTONS
I just soldered the transmitter to where it was plugged into when it was on breadboard,
HOT GLUE IT WHERE EVER YOU WANT ON THE CONTROLLER
I wasn't able to put it on the inside then have the antenna just stick out cause the NANO was on the inside already.....
The antenna used in the pic is from an RC car controller. Jumper wire still works the same.
PLAYER 2 CONTROLLER-
So I wired the Nano's Ground to the second controller circuit board through the second controllers cable going into the player 1 controller(Controller with Nano is player 1). Then wired the rest to the button output traces which fed to the Nano analog/digital pins just like player 1.
SOFTWARE FOR RF TRANSMITTER CONTROLLER
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK driver(2000, 9, 2, 10);
int inputY = A7;
int inputy = 6; // LOWERCASE = P2 PINS
int inputA = 3; // UPPERCASE = P1 PINS
int inputa = 7;
int inputZ = 4;
int inputz = 8;
int inputB = 5;
int inputb = 9;
int val = 0;
int Val = 0;
int vaL = 0;
int vAl = 0;
int aa = 0;
int bb = 0;
int cc = 0;
int vv = 0;
void setup() {
Serial.begin(9600); // Debugging only
if (!driver.init()){
Serial.println("init failed");}
pinMode(inputY, INPUT_PULLUP); // P1 PINS
pinMode(inputA, INPUT_PULLUP);
pinMode(inputZ, INPUT_PULLUP);
pinMode(inputB, INPUT_PULLUP);
pinMode(6,INPUT_PULLUP); // P2 PINS
pinMode(7,INPUT_PULLUP);
pinMode(8,INPUT_PULLUP);
pinMode(9,INPUT_PULLUP); }
void loop() {
const char *a = "A"; // Different CHAR types for each Button
const char *msg = "Y";
const char *b = "B";
const char *Z = "Z";
val = digitalRead(inputy); // Reads LOW inputs from Buttons
Val = digitalRead(inputa); // P2 inputs
vAl = digitalRead(inputz);
vaL = digitalRead(inputb);
aa = analogRead(inputY); // P1 inputs
bb = digitalRead(inputA);
cc = digitalRead(inputZ);
vv = digitalRead(inputB);
if(val == LOW || aa <= 130){
driver.send((uint8_t *)a, strlen(a));
driver.waitPacketSent();
delay(200); }
if(Val == LOW || bb == LOW){
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200); }
if(vAl == LOW || cc == LOW){ // Statements for each button when pressed
driver.send((uint8_t *)Z, strlen(Z));
driver.waitPacketSent();
delay(200); }
if(vaL == LOW || vv == LOW){ // Statements for each button when pressed
driver.send((uint8_t *)b, strlen(b));
driver.waitPacketSent();
delay(200); }
}
Casing for RF TRANSMITTER
So i took the casing the modules came in, in the mail, and sawed it in half then gorilla glued it over the transmitter.
I wanted a casing that would show the transmitter, A CLEAR CASING, and its kinda strong so it turned out good.
RF RECIEVER CODE
Breadboard according to the code, wire up some LEDs to the OUTPUT pins!
#include <RH_ASK.h>
#include <SPI.h>// Not actually used but needed to compile
RH_ASK driver(2000, 2, 9, 10); // ESP8266 or ESP32: do not use pin 11 or 2
void setup() {
Serial.begin(9600); // Debugging only
if (!driver.init()){
Serial.println("init failed");}
pinMode(7, OUTPUT); // P1 6-9
pinMode(6, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT); // P2 9-13
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT); }
void loop() {
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) {
int i;
String str = "";
for(int i = 0; i < buflen; i++){
str += (char)buf[i]; }
Serial.println(str); // Simple if statements for Reciever to OUTPUT depending on the RF Data messages
if(str == "Y"){
digitalWrite(6, HIGH);
delay(50);
digitalWrite(6, LOW); }
else{
digitalWrite(6, LOW); }
if(str == "A"){
digitalWrite(7, HIGH);
delay(50);
digitalWrite(7, LOW); }
else{
digitalWrite(7, LOW); }
if(str == "Z"){
digitalWrite(8, HIGH);
delay(50);
digitalWrite(8, LOW); }
else{
digitalWrite(8, LOW); }
if(str == "B"){
digitalWrite(9, HIGH);
delay(50);
digitalWrite(9, LOW); }
else{
digitalWrite(9, LOW); }
}
}
Using for a Project
Modify the code and experiment !