Pages: [1]   Go Down
Author Topic: Arduino as an input for the computer?  (Read 994 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I am trying to use my arduino duemilanove as a keyboard type interface with my computer. The problem I am having is I can set the board up with digital I/Os and have the serial monitor read them as 1s or 0s but I have no idea how to write the programming to have to computer interfaced with the arduino. The reason I am doing this is for a school assignment, I am attempting to build a SNES USB controller to use with an SNES emulator that I have on my laptop, which is running Lubuntu 12.04. Any help that can be offered would be  greatly appreciated.

Note: I have the serial monitor reading the buttons as w,a,s,d...ect, but the computer still will not read them.


« Last Edit: March 29, 2013, 01:00:04 pm by blastradius » Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino Duemilanove can be a serial port.
Can you control the NES emulator with a serial port ?

The Arduino Leonardo can be a keyboard, a mouse and a serial port.
http://arduino.cc/en/Main/arduinoBoardLeonardo
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If there is a way I haven't found it. That's what I'm trying to do, either have the emulator read the serial or have the computer read it as something other than serial.   The emulator I'm using is SNES9X from the Lubuntu software center.
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps you can ask on the forum of snes9x.com if it is possible to the serial port.
If not, the Arduino Leonardo is an easy solution to the problem.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4809
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I am trying to use my arduino duemilanove as a keyboard type interface with my computer. The problem I am having is I can set the board up with digital I/Os and have the serial monitor read them as 1s or 0s but I have no idea how to write the programming to have to computer interfaced with the arduino. The reason I am doing this is for a school assignment, I am attempting to build a SNES USB controller to use with an SNES emulator that I have on my laptop, which is running Lubuntu 12.04. Any help that can be offered would be  greatly appreciated.

Note: I have the serial monitor reading the buttons as w,a,s,d...ect, but the computer still will not read them.

Have you tried to use Processing?  It's the PC side of what Arduino IDE is for Arduino. Both have setup and loop, and many etcs.
http://www.processing.org/

I just started. I ran the IDE, looked into the Libraries section and there's example programs with the Libraries. The Serial Library recognizes COM ports, my COM3 was list[2], not the code
  • .

I ran this on my UNO, compiled with IDE 0022. The SimpleWrite example makes a box with a button. When you put the cursor over the button it sends the Arduino an H otherwise it sends L. The UNO program turns pin 13 led on for 50ms when H is received, else the led will finish flashing.
If you get the right COM port, the Arduino led will be on when the cursor is over the button.

Code:
void setup()
{
  Serial.begin( 9600 );
  pinMode( 13, OUTPUT ); // pin 13 now OUTPUT LOW
}

void loop()
{
  static unsigned long flashStart = 0UL;
  static unsigned long flashLen = 50UL;

  if ( flashStart > 0UL )
  {
    if ( millis() - flashStart >= flashLen )
    {
      flashStart = 0UL;
      digitalWrite( 13, LOW );
    }
  }

  if ( Serial.available())
  {
    char ch = Serial.read();
    Serial.println( ch );

    if ( ch == 'H' ) digitalWrite( 13, HIGH );
    else digitalWrite( 13, LOW );
   
    flashStart = millis();
  }





This is the Processing sketch I ran on my PC. It uses the Processing Serial library.

Code:
/**
 * Simple Write.
 *
 * Check if the mouse is over a rectangle and writes the status to the serial port.
 * This example works with the Wiring / Arduino program that follows below.
 */


import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;        // Data received from the serial port

void setup()
{
  size(200, 200);
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[2];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  background(255);
  if (mouseOverRect() == true) {  // If mouse is over square,
    fill(204);                    // change color and
    myPort.write('H');              // send an H to indicate mouse is over square
  }
  else {                        // If mouse is not over square,
    fill(0);                      // change color and
    myPort.write('L');              // send an L otherwise
  }
  rect(50, 50, 100, 100);         // Draw a square
}

boolean mouseOverRect() { // Test if mouse is over square
  return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));
}

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Pages: [1]   Go Up
Jump to: