# Porting Arduino Serial (PS2) Keyboard Library

**URL:** <https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131>\
**Category:** Libraries\
**Created:** [November 14, 2014, 9:34pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131 "2014-11-14T21:34:48Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 20, 2014, 12:03am UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/22 "2014-11-20T00:03:12Z")

</div>

I came across an this [post](http://playground.arduino.cc/ComponentLib/BarcodeScanner) today. It made me rethink the problem here. The barcodes that I am interested in (and probably most other people) are only comprised of numbers. The code in the linked post is much simpler as it only works for numeric barcodes and might be a better approach for bar code scanners. I haven’t gotten it working yet, but it compiles without error. I would like to tweak/re-write the code here and I think I have the tools to do so, but I am missing one piece. I am not able to generate any output from my barcode scanner yet. It indicates with a beep that a bar code has been scanned but I have not been able to pull the resulting data into the serial monitor. I do not think that I have a hardware issue with the scanner, but I will confirm this over the weekend when I have access to an Arduino. Does the linked code seem like a better or worse approach that using a complete PS2Keyboard library? Does anyone see something obvious that I am missing here in terms of actually generating output from the scanner?

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [November 20, 2014, 12:15am UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/23 "2014-11-20T00:15:32Z")

</div>

I think it should work fine since Adafruit who sells the barcode scanner is also using the same library for their demo.

The important thing is to know if the port is done correctly and you can at least receive data through the spark core. Once that is established, we can safely get the other demo examples working 😉

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 20, 2014, 7:55pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/24 "2014-11-20T19:55:18Z")

</div>

Haha, makes sense. The page that is linked in my previous post shows a wiring diagram in which the data and clock wires are receiving power. This is contradictory to other pages and how I have had the scanner connected for all tests up to this point. I tested this alternate wiring setup and it caused an issue - the spark core looked normal (breathing cyan) but in spark-cli it’s status was offline after about a minute of being online and the whole time I was unable to flash anything. I want to confirm my wiring setup so we can make sure the problem is in the library.

Focus on the top half of the image below: **clock** goes to Spark Core pin **A4 (14)**; ground goes to ground; **data** goes to Spark Core pin **A5(15)**; +5V goes to a 5V step up. Are there any problems here?  
 ![](https://community.particle.io/uploads/particle/3658/3f74a2292df3c3b5.jpg)

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [November 20, 2014, 11:08pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/25 "2014-11-20T23:08:40Z")

</div>

Is the 5V step up powering the core as well?

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 20, 2014, 11:14pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/26 "2014-11-20T23:14:28Z")

</div>

No, just the scanner

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [November 20, 2014, 11:15pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/27 "2014-11-20T23:15:21Z")

</div>

Ok! If that’s the case, be sure to connect the ground of the 5V step up to the core ground as well. 🙂

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 20, 2014, 11:18pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/28 "2014-11-20T23:18:35Z")

</div>

They’re connected - the ground from the core and the ground from the step up both are linked up to the same column on the bread board

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 20, 2014, 11:22pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/29 "2014-11-20T23:22:17Z")

</div>

Do you think it would be useful to demonstrate the scanner’s viability by taking a look at the raw serial data, before it translated via the library?

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [November 20, 2014, 11:26pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/30 "2014-11-20T23:26:37Z")

</div>

I’ll see what I can do today. 🙂 it’s hard without the physical device but let’s see how far this can go!

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 20, 2014, 11:36pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/31 "2014-11-20T23:36:15Z")

</div>

I am extremely appreciative of all the help you’ve already given me. If there is any leg work you think I can accomplish on my end please instruct me. If you think it would help, you can remote access my computer to test out the device - I’m on a Mac.

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [November 20, 2014, 11:46pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/32 "2014-11-20T23:46:50Z")

</div>

What did you change this to:

```auto
const int DataPin = 8;
const int IRQpin = 5;

```

i would recommend using the following pins as they are 5V tolerant… I hope your analog pins did not blew up~

**D0, D1, D3, D4, D5, D6 and D7**

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 20, 2014, 11:50pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/33 "2014-11-20T23:50:43Z")

</div>

I have used a number of combinations - most recently D0 and D1

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [November 20, 2014, 11:53pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/34 "2014-11-20T23:53:27Z")

</div>

I’m just wondering about the pins wiring… Where did you get the image from? Also, i guess the scanner is powered up?

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 20, 2014, 11:54pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/35 "2014-11-20T23:54:20Z")

</div>

I should have specified:

```
 const int DataPin = 1;
 const int IRQpin = 0;
```

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 20, 2014, 11:58pm UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/36 "2014-11-20T23:58:14Z")

</div>

The image was from [this site](http://www.instructables.com/id/Make-a-portable-barcode-scanner-with-an-arduino-an/step4/Wire-PS2-connector-to-wave-shield/). The [library site](http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html) has another view of the same pin layout.

The scanner is powered up. It has the red light turned on when the button is pressed down and it recognizes barcodes by beeping and the light turning off.

I also changed this section of the test.ino file. The German line was originally the one that was not commented out, I changed it so that the US line was active instead.

```
const int DataPin = 1;
const int IRQpin = 0;

PS2Keyboard keyboard;

void setup() {
  keyboard.begin(DataPin, IRQpin, PS2Keymap_US);
  //keyboard.begin(DataPin, IRQpin, PS2Keymap_German);
  //keyboard.begin(DataPin, IRQpin, PS2Keymap_French);
  Serial.begin(9600);
  Serial.println("International Keyboard Test:");
}

```

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [November 21, 2014, 12:01am UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/37 "2014-11-21T00:01:18Z")

</div>

Awesome… I’m just wondering if the wiring is correct since the site doesn’t seem to be using the same scanner. (or rather i can’t figure out)

Do you have a multimeter? Can you check between the 2 ends and be sure that the Clock and Data are doing to the right pins? 😉

The library seems pretty simple and looking at it, it might be a Pull\_up setting issue (just guessing)

@btheye, can you try this updated code: [https://dl.dropboxusercontent.com/u/36134145/PS2Keyboard.zip](https://dl.dropboxusercontent.com/u/36134145/PS2Keyboard.zip)

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 21, 2014, 12:22am UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/38 "2014-11-21T00:22:08Z")

</div>

I do have a multimeter - do you mean to check the cord that links the scanner to the leads coming from the bread board? I will check all circuits to make make sure everything is correct. I have some pictures below as well. The amplifier and accompanying wires are not related to the barcode scanner, that assembly is for a load cell. Only the step up and the spark core are involved with the barcode scannner.

![](https://sea2.discourse-cdn.com/flex026/uploads/particle/3660/84d8dd59e679f982.JPG) ![](https://sea2.discourse-cdn.com/flex026/uploads/particle/3661/60b0a86122d6114d.JPG) ![](https://sea2.discourse-cdn.com/flex026/uploads/particle/3662/b2bfff8c84f87b37.JPG)

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 21, 2014, 12:43am UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/39 "2014-11-21T00:43:12Z")

</div>

All connections are good

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [November 21, 2014, 12:46am UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/40 "2014-11-21T00:46:35Z")

</div>

@btheye, can you try this updated code: [https://dl.dropboxusercontent.com/u/36134145/PS2Keyboard.zip](https://dl.dropboxusercontent.com/u/36134145/PS2Keyboard.zip)

---

<div class="post-metadata">

**Author:** ![btheye](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@btheye](https://community.particle.io/u/btheye)\
**Post date:** [November 21, 2014, 12:58am UTC](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131/41 "2014-11-21T00:58:53Z")

</div>

Just tried it a couple of times - no change

[Previous page](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131.md?page=1)

[Next page](https://community.particle.io/t/porting-arduino-serial-ps2-keyboard-library/8131.md?page=3)
