3 x 4 Matrix Keypad, and the Keypad.h libary

Hi,

I'm having a strange issues using the Velleman 3x4 Matrix membrane keypad:-

Keypad

The short version is having this code

My shared code

I get a fully functional device if I compile for a core, but a tonne of errors if I complie for a photon or electron.

The raw errors are

Processing keypadbasic.ino
Checking library Keypad...
Installing library Keypad 3.2.0 to lib/Keypad ...
Library Keypad 3.2.0 installed.
make -C ../modules/photon/user-part all
make[1]: Entering directory '/firmware/modules/photon/user-part'
make -C ../../../user
make[2]: Entering directory '/firmware/user'
Building cpp file: src/keypadbasic.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-6-msrc/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -DSPARK_PLATFORM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=6 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=0.7.0 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../services/inc -I../communication/src -I../hal/inc -I../hal/shared -I../hal/src/photon -I../hal/src/stm32f2xx -I../hal/src/stm32 -I../hal/src/photon/api -I../hal/src/photon/include -I../hal/src/photon/wiced/security/BESL/host/WICED/ -I../hal/src/photon/wiced/security/BESL/include -I../hal/src/photon/wiced/security/BESL -I../hal/src/photon/wiced/security/BESL/crypto -I../hal/src/photon/wiced/WWD/include/ -I../hal/src/photon/wiced/platform/include/ -I../hal/src/photon/wiced/platform/GCC/ -I../hal/src/photon/wiced/security/BESL/supplicant/ -I../hal/src/photon/libraries/crypto -I../platform/shared/inc -I../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F2xx/CMSIS/Include -I../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../dynalib/inc -Isrc -I./libraries -Ilib/Keypad/src -I. -MD -MP -MF ../build/target/user/platform-6-msrc/keypadbasic.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DBOOTLOADER_SDK_3_3_0_PARTICLE -DPARTICLE_DCT_COMPATIBILITY -DSPARK_PLATFORM_NET=BCM9WCDUSI09 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=5 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,207 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY=""app"" -fno-exceptions -fno-rtti -fcheck-new -std=gnu++11 -c -o ../build/target/user/platform-6-msrc/keypadbasic.o src/keypadbasic.cpp

Building cpp file: lib/Keypad/src/Keypad.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-6-mKeypad/src/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -DSPARK_PLATFORM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=6 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=0.7.0 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../services/inc -I../communication/src -I../hal/inc -I../hal/shared -I../hal/src/photon -I../hal/src/stm32f2xx -I../hal/src/stm32 -I../hal/src/photon/api -I../hal/src/photon/include -I../hal/src/photon/wiced/security/BESL/host/WICED/ -I../hal/src/photon/wiced/security/BESL/include -I../hal/src/photon/wiced/security/BESL -I../hal/src/photon/wiced/security/BESL/crypto -I../hal/src/photon/wiced/WWD/include/ -I../hal/src/photon/wiced/platform/include/ -I../hal/src/photon/wiced/platform/GCC/ -I../hal/src/photon/wiced/security/BESL/supplicant/ -I../hal/src/photon/libraries/crypto -I../platform/shared/inc -I../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F2xx/CMSIS/Include -I../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../dynalib/inc -Isrc -I./libraries -Ilib/Keypad/src -I. -MD -MP -MF ../build/target/user/platform-6-mKeypad/src/Keypad.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DBOOTLOADER_SDK_3_3_0_PARTICLE -DPARTICLE_DCT_COMPATIBILITY -DSPARK_PLATFORM_NET=BCM9WCDUSI09 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=5 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,207 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY=""app"" -fno-exceptions -fno-rtti -fcheck-new -std=gnu++11 -c -o ../build/target/user/platform-6-mKeypad/src/Keypad.o lib/Keypad/src/Keypad.cpp
In file included from ../wiring/inc/spark_wiring_usbkeyboard.h:33:0,
from ./inc/application.h:51,
from lib/Keypad/src/Key.h:35,
from lib/Keypad/src/Keypad.h:36,
from lib/Keypad/src/Keypad.cpp:32:
../wiring/inc/spark_wiring_usbkeyboard_scancode.h:15:26: error: expected identifier before '=' token
KEY_H = 0x0B, // Keyboard h and H
^
../wiring/inc/spark_wiring_usbkeyboard_scancode.h:15:26: error: expected '}' before '=' token
../wiring/inc/spark_wiring_usbkeyboard_scancode.h:15:26: error: expected unqualified-id before '=' token
../wiring/inc/spark_wiring_usbkeyboard_scancode.h:403:1: error: expected declaration before '}' token
} UsbKeyboardScanCode;
^
../build/module.mk:279: recipe for target '../build/target/user/platform-6-mKeypad/src/Keypad.o' failed
make[2]: Leaving directory '/firmware/user'
make[2]: *** [../build/target/user/platform-6-mKeypad/src/Keypad.o] Error 1
../../../build/recurse.mk:11: recipe for target 'user' failed
make[1]: Leaving directory '/firmware/modules/photon/user-part'
make[1]: *** [user] Error 2
../build/recurse.mk:11: recipe for target 'modules/photon/user-part' failed
make: *** [modules/photon/user-part] Error 2

Useful info

Build is via the WebIDE, and on different PC's running windows 7 (A desk top and my laptop)

Core is running Device OS 0.7.0, but I've tried various and no problem.
The Photon is running Device OS 0.7.0 and I've tried 1.0, still tonnes of errors.
The keypad works fine on an Arduino, and as I say on a core...

I've scouted for historical problems and the found relatively little that helped, but most people seem to have the reverse issue, IE they have no problem using the Keypad.h lib on the photon, but problems on the core.

It is a well used lib, so not sure whats going on.... and yes I have scoured my code for syntax errors... Some people have reported similar errors and I have looked at the libary code and can not see anything related to the reported line numbers, infact I'm not sure the error codes actually refer to the libary itself....

I can actually use the core for my task at hand, infact it will give it a perminate task to perform, but going forward it would be nice to use an electron....

I've experimented with the Keypad_Particle lib, but thats thrown up a whole load of other odd stuff.... so lets look at one problem at a time.

And I am betting myself half a packet of custard creams that Scruff solves this in two clicks of a mouses tail :slight_smile:

Hopefully that all makes sence, fingers crossed.

Liam

What is hidden behind this chevron?
image
If you clap that open, we can see what device OS version you are targeting

But I think there was a poor choice in that library to use KEY_H as guard against multi inclusion since KEY_H is already taken by the USBKeyboard key map for the H key.
The compiler doesn’t really like redefinitions of that kind :wink:

You’ll probably need to copy/paste the code of that library into your own project, change that definition and try again.
You could also file a GitHub issue on the library (providing it’s still maintained by the original contributor).


Update:
I just checked and there already is such an issue filed


and even a PR to solve that issue, but the contributor hasn’t picked up on that since June 2017

Hi Scruff,

The photon was being targeted with Device OS 0.7.0 and already had 0.7.0 on it… I did mention that,… I tought.

I’ll have a look at the KEY_H definition… and see if I can get anywere with that.

I thought that the Keypad_Particle.h libary had addressed that and a few other issues… But strangely that has worked if I use the example code, but if I try to add that libary, I get another error saying that the libary can not be found, and I note the the use count is zero…

But I’ll look at the definition thing…

Thanks

Liam

That counter has been broken for a while now, but noone took the time to repair it yet :pensive:

You mentioned the device was running 0.7.0 but that doesn't immediately mean that Web IDE will also be building for that version.

Hi Scruff,

I have tried addressing the KEY_H issue but and still getting the same errors.

https://go.particle.io/shared_apps/5c89a274f64a05000cdae9ac

I cheated a bit but copying out the code in the Keypad_Particle libary, in to notepad++ and searched for KEY_H to ensure it was removed.

Then created local cpp and h tabs and pasting them in. I tried both variations of #include<> and #include"" and both chuck out the original errors… if you get a moment take a look at my atempt.

Thanks

Liam

For one, you still have the library with the offensive #define in your project, you need to get rid of that.
This works for me
https://go.particle.io/shared_apps/5c89f650f64a05000cdaeef1

Hi Scruff,

Ok, I pulled down your edit and up it complies on my end as well… Thanks…

But I am REALLY struggling to see the changes you made.

I’ve spotted the changes in Key_Particle. were your change KeyPad_Particle_H to_KeyPad_Particle_H_

and in MyKey.H your changed MyKey_H to_Mykey_H_

But making those changes still leaves my code throwing out errors… I am really trying to find the #define statements casuing the issue. I’ve copied your ino file to notepad++ and fliped between my Keypad2.ino file and for the life of me can not see the fix…

In a respectful, and as the student asking the master way, I have to admit I’m beaten.

liam

The reason why the changes didn't make any difference on your side probably are two fold

First what I already mentioned

Included libraries mustnot have that library in there otherwise it will be compiled again

And secondly, in some cases, even after removing source files (or libraries) respective object files resulting from previous compiler runs will not be deleted with the sources.
To work around that you need to start a completely new project.

The leading/trailing underscores for the multi-inclusion guard #define is just a habit and convention that will help prevent inadvertend collisions with "functional" defines as the latter should never feature that.

Hi Scruff,

Thanks a million for your help, and I have got it working, using a local library of the Keypad_particle. both for the core and the photon. I’m expect to get it going for the electron.

On my mistakes, I see now that I had left in the included library, which I why I could not spot the error in the code! (Hommer Simpson noise). But I ‘thought’ I had taken care of that as an issue by trying I thought to use the #include<> and #include"" variations to tell the compiler were to find the library. After all that’s what I thought they were for, I learnt that after an old Arduino project I was doing kept compiling for the wrong library, because I was using the wrong deceleration. So I didn’t pay attention to the fact your version, never included the cloud library at all.

I did try removing the library, and you were right, it kept throwing errors…

So I copied and pasted everything to notepad++ created a new project and pasted it all back again and hey presto it worked, Identical code, just a new project that had never been linked to the cloud library.

Bit of a tough learning curve that one. And I thank you hugely for your help and guidance.

I am left thinking that this is something of a issue with the WebIDE, or is this a more general thing with IDE’s as a whole?

Also when I make a new tab and enter text in to the xxx.h it automatically populates the xxx.cp with the same text, and I have to delete it out. I have found myself writing code into the wrong file because I thought I was working on the other one.

I know I ought to get around to working with the workbench, but I do find the webIDE handy for particle stuff because I’m jumping from my work PC, to my home PC to my Laptop at the London Hackspace alot… And I know I should get around digging deeper in to library usage as a whole, but I started my programming learning curve on Fortan77… subroutines have there advantages. But that’s Mechanical Engineers for you we like our old hammers… and I can almost hear the intakes of breaths from modern programmers…

In summary thank you, (I tip my cap)

Liam

1 Like

You are dealing with multi module compilation here.
The include statements are only there to tell the compiler what it will be dealing with when it compiles one single module (source file), but having them there or not in one file does not impact the compile process on any other module. So when you have the module of the erronous library present in your project, the compiler will always build that module and hence trip over that error.

And once a module is built it won't be touched (rebuild or removed) as long the sources don't change. Removing a file doesn't change the file, it's just not present anymore, but the precompiled object files don't get removed unless you run a make clean (which you can't in Web IDE).

This is a known bug that won't be fixed since Web IDE should be replaced not to long from now (I hope).
When I do that, the first step I do is just entering some dummy text (e.g. // .h file and // .cpp file) in the respective file tabs and save the project before adding any meaning full code into the files. That way I won't confuse myself.