expected primary-expression before 'dataPin'

it is the code

#include <PS2Keyboard.h>
#include <SD.h>
#include "PS2Keyboard.h"

#define DATA_PIN 2                                                             //define data pin of the keyboard

PS2Keyboard keyboard;
File myFile;                                                                              // variable required to hold the file descriptor
const int chipSelect = 10;                                                     // the pin number which is need to write on SD card
byte dat;
char c;

void setup()
{
pinMode(10, OUTPUT);     
Serial.begin(9600);                                                        // initialize the serial port at baud rate 9600
Serial.print("Initializing SD card...");                                  


while(!SD.begin(chipSelect));                                              // initialize the SD card
Serial.println("card initialized."); 

keyboard.begin(uint8_t dataPin);                                                   // initialize the PS2 keyboard
Serial.println("keyboard initialized.");   

}

void loop()
{
if(keyboard.available())
{
  dat = keyboard.read();
  c = dat;   

    while(!(myFile = SD.open("new.txt", FILE_WRITE)));                         // open a file for writing
  myFile.print(c);                                                                                            // write the string into the file
  myFile.close();       
  
  Serial.println(c);
}  
else;
}

and this the wrong

C:\Users\Zomber\Documents\Arduino\sketch_jul15a\sketch_jul15a.ino: In function 'void setup()':

sketch_jul15a:23: error: expected primary-expression before 'dataPin'

keyboard.begin(uint8_t dataPin); // initialize the PS2 keyboard

^

exit status 1
expected primary-expression before 'dataPin'

You cannot, as far as I know, declare a variable in the parameter list of a function and in any case what will its value be ? Declare dataPin and give it a value before trying to use the variable

Sorry, but I'm new in what is arduino programming could explain better because I did not quite understand what he meant. Thank you

Take the uint8_t out of the indicated line. Next it will probably still not compile as, as far as I can see, you do not have dataPin but you have DATA_PIN.

new wrong :frowning:

C:\Users\Zomber\Documents\Arduino\sketch_jul15a\sketch_jul15a.ino: In function 'void setup()':

sketch_jul15a:23: error: no matching function for call to 'PS2Keyboard::begin(int)'

keyboard.begin(DATA_PIN); // initialize the PS2 keyboard

^

C:\Users\Zomber\Documents\Arduino\sketch_jul15a\sketch_jul15a.ino:23:25: note: candidate is:

In file included from C:\Users\Zomber\Documents\Arduino\sketch_jul15a\sketch_jul15a.ino:1:0:

C:\Users\Zomber\Documents\Arduino\libraries\PS2Keyboard/PS2Keyboard.h:206:17: note: static void PS2Keyboard::begin(uint8_t, uint8_t, const PS2Keymap_t&)

static void begin(uint8_t dataPin, uint8_t irq_pin, const PS2Keymap_t &map = PS2Keymap_US);

^

C:\Users\Zomber\Documents\Arduino\libraries\PS2Keyboard/PS2Keyboard.h:206:17: note: candidate expects 3 arguments, 1 provided

exit status 1
no matching function for call to 'PS2Keyboard::begin(int)'

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

Which Arduino board are you using ?

UKHeliBob:
Which Arduino board are you using ?

arduino UNO
I try to make a keylogger but the micro SD does not receive the pulsations and the new file is not created.

#include <PS2Keyboard.h>
#include <SD.h>
#include "PS2Keyboard.h"

Are you hedging your bets by trying to include the library from two different places ?
Where exactly are the library files located on your PC ?

UKHeliBob:

#include <PS2Keyboard.h>

#include <SD.h>
#include "PS2Keyboard.h"



Are you hedging your bets by trying to include the library from two different places ?
Where exactly are the library files located on your PC ?

The SD library comes by default but the ps2 keyboard is in documents

First and used this code

#include <PS2Keyboard.h>
#include <SD.h>


const int DataPin = 2;
const int IRQpin =  3; 
const int chipSelect = 10;
File myFile;

PS2Keyboard keyboard;

void setup()
{
 Serial.begin(9600);

 pinMode(10, OUTPUT);  

 while(!SD.begin(chipSelect));
//  initialize the SD card


// keyboard.begin(const int&, const int&);

}

void loop()
{
 if(keyboard.available())
 {
   char c = keyboard.read();

   while(!(myFile = SD.open("new.txt", FILE_WRITE)));

   myFile.print(c);
   myFile.close();
 }

 else;
}

Compiles correctly but does not intercept data

Hi,
Please read post #5 about post your code and code tags.

Where did you get the PS2 library from?

Have you tried the PS2 keyboard in code that just serial.prints to the monitor, so you know you have the PS2 keyboard connection working?

Tom... :slight_smile:

Compiles correctly but does not intercept data

No surprise there because you have commented out the keyboard.begin() line

UKHeliBob:
No surprise there because you have commented out the keyboard.begin() line

In this case would be the most recommendable?

Zomber:
In this case would be the most recommendable?

Use the keyboard.begin() function with the number of the data pin as its parameter.