Porting Arduino Serial (PS2) Keyboard Library

The words “bar code scanner” in my last post are linked to the one that I purchased.

You’re definitely correct on PROGMEM being an issue. Looking forward to collaborating - please let me help out in anyway possible.

Ok so i hacked them together already :wink:

Did you install spark-cli? That’s the fastest way to send you the files and test to see how it goes!!

If it works, i will ask the other Elites on how to add in the conditional statement for spark and it should be published as a modified library :slight_smile:

2 Likes

Ha! That was impressively fast. I had been using the web IDE and do not have spark-cli installed yet but it seems straight forward. What information do you need to send it? I’ll get it installed this evening.

Thanks so much again.

It’s just more convenient to compile via the command line instead of copy and pasting into the web ide during development.

makes it much faster!

Just installed spark-cli. The accepting xCode terms/conditions was holding me up for a moment (using a Mac), but once I accepted the agreement all went smoothly. I am ready to go but have a limited comprehension of what is possible with spark-cli vs. the web IDE - I’ll read up on this. In the near term, what are the next steps using spark-cli?

The spark-cli github repo has some usage instructions you can take a look!

Here’s the link: https://dl.dropboxusercontent.com/u/36134145/PS2Keyboard.zip

once you have spark-cli working,

  1. Login to spark-cli using spark login

  2. Once done, cd to the directory that you unzipped the file

  3. Use this command spark flash CORE_NAME PS2Keyboard. be sure to change your own core name :wink:

I used one example code to test if i could compile successfully so do modify it before compiling and test on your core.

Hope it works!!

1 Like

I really can’t thank you enough for all the help so far. So I have read up on spark-cli and have attempted to flash the library/modified example code to the core but I am running into an issue that is causing the spark core LED to breath green. The result in terminal is I want to make sure I understand the components in the zip file as I think I am likely making a mistake here. The files that need to be compiled to assemble the library are PS2Keyboard.h, int_pins.h, and PS2Keyboard.cpp. The final component should be a simple example sketch that allows the serial monitor to display bar codes that have been translated through the library, in this case, test.ino. Am I missing anything so far? I tried isolating these files in a directory and flashing them to the core using spark-cli, but this failed. Does another file in the unzipped folder must serve a purpose that I don’t understand yet?

I also tried copying the contents of the .h, .cpp, and example sketch to the web IDE and was unable to compile them, receiving the following error:

In file included from ../inc/spark_wiring.h:29:0, 
from ../inc/application.h:29,
from bc_reader.cpp:30:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning  "Defaulting to Release Build"
^    
bc_reader.cpp:44:22: fatal error: int_pins.h: No such file or directory 
#include "Arduino.h" // for attachInterrupt, FALLING
^   
compilation terminated.
make: *** [bc_reader.o] Error 1
Error: Could not compile. Please review your code.

Do you see what I might be missing in order to achieve a successful compilation?

Are you in one directory above the PS2keyboard folder?

Eg. I have the PS2keyboard folder in desktop. So in my terminal it shows

KEN-MBP:desktop kennethlimcp$ spark compile PS2keyboard
Including:
PS2keyboard/PS2Keyboard.cpp
PS2keyboard/PS2Keyboard.h
PS2keyboard/int_pins.h
PS2keyboard/test.ino
attempting to compile firmware 
pushing file: PS2keyboard/PS2Keyboard.cpp
pushing file: PS2keyboard/PS2Keyboard.h
pushing file: PS2keyboard/int_pins.h
pushing file: PS2keyboard/test.ino
Memory use: 
   text	   data	    bss	    dec	    hex	filename
  78096	   1228	  11932	  91256	  16478	/spark/compile_server/shared/workspace/3_compile-server2/core-firmware/build/b13a23d22fa1c1d9967001d7c43fbb05918821c1100a164c934308c60d0c.elf

grabbing binary from: https://api.spark.io/v1/binaries/546aa19c0030fc0a2a309ab4
saved firmware to /Users/kennethlimcp/Desktop/firmware_1416274329875.bin
Compiled firmware downloaded.
KEN-MBP:desktop kennethlimcp$ 

You need to modify the 2 Pins in the test.ino to suit your setup and test

Ha! Success - I was in the correct directory and had changed the pins, but was still not able to compile. I reset the core, exited the web IDE and the Spark Dev desktop app and was able to compile/flash successfully. Thanks for all the help troubleshooting. As you mentioned, I now need to design a way to test and store the bar codes. I’ve read about a method the bring data to a google spreadsheet which I think will suit my needs nicely for now. In terms of actually ascertaining the data, do you know a good resource I could use learn the best ways to accomplish this? I have been looking for information on the spark core’s IRQ pins and whether or not the data would be available in the serial monitor. Any tips on what to search for to learn about this?

@btheye, the Spark documentation is a good place to find the info on interrupt pins:

http://docs.spark.io/firmware/#interrupts-attachinterrupt

:smile:

1 Like

Does the code work? I will publish it and have it on the Web IDE library so others can use it :slight_smile:

It compiles fine but are you able to output to the serial?

1 Like

I haven’t been able to output yet, but I am not sure that the problem is with the code. Should it work with no action at all from my end? In other words, should I be able to push the button on the bar code reader and see the output in the serial monitor? When I attempt to view the serial monitor I receive the following:

ben-theyes-mbp:library bentheye$ spark serial list
Found 1 core(s) connected via serial: 
1:    /dev/cu.usbmodem621

ben-theyes-mbp:library bentheye$ spark serial monitor
Opening serial monitor for com port: "/dev/cu.usbmodem621"

Whoops, that’s the second result on Google, I don’t know how I missed it. Apologies for that, must need another cup of coffee.

I came across an this post 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?

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 :wink:

1 Like

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?

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

No, just the scanner

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