Go Down

Topic: N64 Controller: Done reasearch, need a pros help (Read 6470 times) previous topic - next topic

Waffle

I'm guessing on the controller side you could use read in the data from the controller (it comes out as 4 bytes) and you can just send these 4 bytes across the rf transmitter.

dashdanw

heres the source code from the rf solution, it seems like there is some brief code for sending the data packets out but nothing we probably couldnt eek in.

Let me know if you think this looks like a possibility?

Code: [Select]

// Maurice Ribble
// 8-30-2009
// http://www.glacialwanderer.com/hobbyrobotics
// Used Arduino 0017
// This is a simple test app for some cheap RF transmitter and receiver hardware.
// RF Transmitter: http://www.sparkfun.com/commerce/product_info.php?products_id=8945
// RF Receiver: http://www.sparkfun.com/commerce/product_info.php?products_id=8948

// This says whether you are building the transmistor or reciever.
// Only one of these should be defined.
//#define TRANSMITTER
#define RECEIVER

// Arduino digital pins
#define BUTTON_PIN  2
#define LED_PIN     13

// Button hardware is setup so the button goes LOW when pressed
#define BUTTON_PRESSED LOW
#define BUTTON_NOT_PRESSED HIGH

void setup()
{
 pinMode(BUTTON_PIN, INPUT);
 pinMode(LED_PIN, OUTPUT);
 digitalWrite(LED_PIN, LOW);

 Serial.begin(1200);  // Hardware supports up to 2400, but 1200 gives longer range
}

#ifdef TRANSMITTER
void loop()
{
 static int prev_button = BUTTON_NOT_PRESSED;  // Previous button press value
 int        cur_button;                        // Current button press value

 cur_button = digitalRead(BUTTON_PIN);

 if ((prev_button == BUTTON_NOT_PRESSED) && (cur_button == BUTTON_PRESSED))
 {
   writeUInt(271); // Put any number you want to send here (71 is just a test)
 }

 delay(50); // Debounce button
 prev_button = cur_button;
}
#endif //TRANSMITTER

#ifdef RECEIVER
void loop()
{
 boolean light_led = false;

 if (readUInt(true) == 271) // Check to see if we got the 71 test number
 {
   light_led = true;
 }
 
 if (light_led)
 {
   digitalWrite(LED_PIN, HIGH);
   delay(1000);
   digitalWrite(LED_PIN, LOW);
 }
}
#endif //RECEIVER


thats the code for both the reciever and the transmitter....

dashdanw

#62
Jan 16, 2010, 07:01 pm Last Edit: Jan 16, 2010, 09:13 pm by dashdanw Reason: 1
also heres the error checking code, although i think this is just applicable to the reciever (besides the identifier that get sent before and after each packet)

Code: [Select]
// Maurice Ribble
// 8-30-2009
// http://www.glacialwanderer.com/hobbyrobotics
// Used Arduino 0017
// This does does some error checking to try to make sure the receiver on this one way RF
//  serial link doesn't repond to garbage

#define NETWORK_SIG_SIZE 3

#define VAL_SIZE         2
#define CHECKSUM_SIZE    1
#define PACKET_SIZE      (NETWORK_SIG_SIZE + VAL_SIZE + CHECKSUM_SIZE)

// The network address byte and can be change if you want to run different devices in proximity to each other without interfearance
#define NET_ADDR 5

const byte g_network_sig[NETWORK_SIG_SIZE] = {0x8F, 0xAA, NET_ADDR};  // Few bytes used to initiate a transfer

// Sends an unsigned int over the RF network
void writeUInt(unsigned int val)
{
 byte checksum = (val/256) ^ (val&0xFF);
 Serial.write(0xF0);  // This gets reciever in sync with transmitter
 Serial.write(g_network_sig, NETWORK_SIG_SIZE);
 Serial.write((byte*)&val, VAL_SIZE);
 Serial.write(checksum); //CHECKSUM_SIZE
}

// Receives an unsigned int over the RF network
unsigned int readUInt(bool wait)
{
 int pos = 0;          // Position in the network signature
 unsigned int val;     // Value of the unsigned int
 byte c = 0;           // Current byte
 
 if((Serial.available() < PACKET_SIZE) && (wait == false))
 {
   return 0xFFFF;
 }
 
 while(pos < NETWORK_SIG_SIZE)
 {
   while(Serial.available() == 0); // Wait until something is avalible
   c = Serial.read();

   if (c == g_network_sig[pos])
   {
     if (pos == NETWORK_SIG_SIZE-1)
     {
       byte checksum;

       while(Serial.available() < VAL_SIZE + CHECKSUM_SIZE); // Wait until something is avalible
       val      =  Serial.read();
       val      += ((unsigned int)Serial.read())*256;
       checksum =  Serial.read();
       
       if (checksum != ((val/256) ^ (val&0xFF)))
       {
         // Checksum failed
         pos = -1;
       }
     }
     ++pos;
   }
   else if (c == g_network_sig[0])
   {
     pos = 1;
   }
   else
   {
     pos = 0;
     if (!wait)
     {
       return 0xFFFF;
     }
   }
 }
 return val;
}



dashdanw

also im thinking....if this rf setup runs on 315mhz solid, then how would you incorperate multiple controllers?

Waffle

I think that interfacing with the RF transmitter/receiver is done using Serial so it shouldn't be a problem, you can send anything you like. If you wanted multiple controllers, you could send a number (one for each controller) as an identifier along with the controller data and have the receiver split it apart.

dashdanw

ill need to probably alter the nop delays to add the numbers ahead and the hash and all that.

Waffle

You wouldn't need to. You would have the MCU at the transmitter end read from the controller, using the existing code and once that is done, send it wirelessly over with the id, error checking, etc. Because it's done in two stages, you don't need to adjust the delays.

dashdanw

thanks waffle, ill start trying to parse the code into your existing code, ill let you know how i do....

dashdanw

im thinking it might just be easiest to write out to the rf transmitter as you would a serial port without the signal verification, even if the data is corrupted several times consecutively it wont be enough to effect an entire frame of the game....i think..anyways gotta put it to the test somehow....

dashdanw

sweeeeeeet sweeeeet VICTORY! got the controller working! built this:

from an atmega328 and instructions from this instructables:http://www.instructables.com/id/Build-Your-Own-Arduino/step2/Setting-Up-Power/

also i can now, thanks to that schematic, hook up a rechargable battery, all i need to do now is work out which components can be removed from the setup when i make the arduino standalone, unfortunately sparkfun fuddled up my order and left a few 28 pin dip sockets out so no perminant soldering can commence till they come. In the meantime im going to work on the RF reciever/transmitter

dashdanw

sorry for the GIGANTIC image...damn [img] tags wont let me resize :P

fraser

Hey dashdanw, congratulations on the controller!  

I'm trying to do something similar, so for all the rest of us out here on the webs would you mind describing how you got it working in the end?  Did you use the code from Instructables and XBee in your end project?  Or did you send it over RF using serial communication?  

Again, congrats, and so curious how you got it all working in the end!  And don't worry, I'll never complain about too many details, lay 'em on...  Thanks!

Go Up