Teensy 3.2 Hellokeypad sketch compile errors - keypad

I'm getting a compiler error when I try and compile the HelloKeypad demo sketch.
I'm on a Windows 7 machine using a Teensy 3.2 board.
I bought a keypad like this one: https://www.adafruit.com/products/1824
I downloaded the keypad.zip file from here:
https://www.pjrc.com/teensy/td_libs_Keypad.html
and I'm using the example sketch from the same web page:
/* #file HelloKeypad.pde
|| #version 1.0
|| #author Alexander Brevig
|| #contact alexanderbrevig#gmail.com
||
|| #description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key){
Serial.println(key);
}
}
Here is the compiler message.
Arduino: 1.6.6 (Windows 7), TD: 1.26, Board: "Teensy 3.2 / 3.1, Serial + Keyboard + Mouse + Joystick, 96 MHz optimized (overclock), US English"
In file included from C:\Users\FRESH1~1\AppData\Local\Temp\arduino_827e3ed6878980f03915bd59f832243c\HelloKeypad.ino:10:0:
C:\Users\fresh1011\Documents\Arduino\libraries\Keypad/Keypad.h:80:27: error: expected class-name before '{' token
class Keypad : public Key {
^
C:\Users\fresh1011\Documents\Arduino\libraries\Keypad/Keypad.h:90:2: error: 'Key' does not name a type
Key key[LIST_MAX];
^
C:\Users\fresh1011\Documents\Arduino\libraries\Keypad/Keypad.h:95:2: error: 'KeyState' does not name a type
KeyState getState();
^
C:\Users\fresh1011\Documents\Arduino\libraries\Keypad/Keypad.h:119:28: error: 'KeyState' has not been declared
void transitionTo(byte n, KeyState nextState);
^
Multiple libraries were found for "Keypad.h"
Used: C:\Users\fresh1011\Documents\Arduino\libraries\Keypad
Not used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Keypad
exit status 1
Error compiling.
Is the Keypad.zip file out of date?
Thanks for any help.

Maybe use Arduino IDE 1.6.3 instead of 1.6.6.
According to the following post in the pjrc forum it solves the problem for the library support.

Related

I can only send to Arduino 33 BLE 4 bytes via Flutter Blue

I'm trying to send a telephone number and a code (I'm using de code to read it in Arduino and know if this number is for one contact or other, because I'm gonna save different telephone numbers) vía ble from a Flutter app to a Arduino device (device: BLE 33). I'm using the ArduinoBLE library and the flutter_blue library.
For sending the number I need 6 bytes: for example for the number 112233445 one byte is for 11, second byte is for 22, third byte is for 33, 4º byte 44 and 5º byte is 5. And the code f.e. 4, is in another byte.
In Arduino, the function that I'm using to read is settingsCharacteristic.readValue(buffer, size_of_buffer). And in Flutter is characteristic.write(List).
I would like to send "04112233445" -> 4 is the code and the rest is the number.
The problem is that in Arduino I only receive 4 bytes.
Flutter code:
void sendTelephoneNumber(BluetoothCharacteristic characteristic) {
String exampleCode = "01";
characteristic
.write(utf8
.encode(exampleCode + myController.text));
}
(myController is the controller for a TextField where I write the number)
Arduino code:
void t5Callback()
{
BLEDevice central = BLE.central();
if (central && central.connected())
{
if (settingsCharacteristic.written())
{
byte buffer[6];
settingsCharacteristic.readValue(buffer, 6);
for (int i = 0; i < 6; i++)
{
Serial.println(buffer[i]);
}
int code = buffer[0];
unsigned long telephone = 0;
telephone = (buffer[1] + 512 << 32) | (buffer[2] << 24) | (buffer[3] << 16) | (buffer[4] << 8) | (buffer[5]);
Serial.printf("Code: %d\n", code);
Serial.printf("Telephone: %lu\n", telephone);
switch (code) {
case 7:
saveTelephone1(telephone);
break;
case 8:
saveTelephone2(message);
break;
default:
//todo
break;
}
}
}
yield();
}
Finally I tried using a event handler for the characteristic and now it works.
Before this I tried with apps like LightBlue and nRF Connect but I still receive not more than 4 bytes.
I don't know why with the event handler works...

Encrypt message using RSA on ESP32

What I try to achieve here is to encrypt a message inside ESP32 app built using PlatformIO + Arduino framework.
After some searchings, I found this repo: https://github.com/espressif/arduino-esp32
There is a tool inside it seems able to help me achieve what I want https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/include/mbedtls/mbedtls/rsa.h
I imported the library "mbedtls" at https://platformio.org/lib/show/10874/mbedtls to the PlatformIO project and start work from there.
Question: How to load private key file in the app and encrypt the message using the RSA tool?
What I have currently is:
int ret = 1;
char buf[1024];
mbedtls_pk_init(&pk);
memset(buf, 0, sizeof(buf));
mbedtls_mpi_init(&N);
mbedtls_mpi_init(&P);
mbedtls_mpi_init(&Q);
mbedtls_mpi_init(&D);
mbedtls_mpi_init(&E);
mbedtls_mpi_init(&DP);
mbedtls_mpi_init(&DQ);
mbedtls_mpi_init(&QP);
ret = mbedtls_pk_parse_key(&pk, vendorPrivateKey, sizeof(vendorPrivateKey), NULL, NULL);
if (ret != 0) {
Serial.print(" failed! mbedtls_pk_parse_key returned: ");
Serial.print(-ret);
Serial.println();
}
if (mbedtls_pk_get_type(&pk) == MBEDTLS_PK_RSA) {
mbedtls_rsa_context *rsa = mbedtls_pk_rsa(pk);
if ((ret = mbedtls_rsa_export(rsa, &N, &P, &Q, &D, &E)) != 0
|| (ret = mbedtls_rsa_export_crt(rsa, &DP, &DQ, &QP)) != 0) {
Serial.println(" failed! could not export RSA parameters.");
}
}
For now I import the private key content directly in char* form (I'm not sure how to import a pem key file into app.) through the header file:
const unsigned char *vendorPrivateKey = reinterpret_cast<const unsigned char *>(VENDOR_PRIVATE_KEY);
where the value is stored inside secrets.h
Then when I ran the program, it yields the following error message for me:
failed! mbedtls_pk_parse_key returned: 15616
According to the pk.h file description, this error code 15616 in hexa is 3D00 which indicates /**< Invalid key tag or value. */
Is there any website that provides format checking and see if my private key file fits the requirements of the mbedtls?

Function was not declared in the scope

I do not know why my program throws me error that I do not have defined functions even though I have them in the program. This happened after adding the code INA219 monitor;
My code:
#include "BNO055_ESP32.h"
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include <INA219.h>
#define SHUNT_MAX_V 0.02 /* Rated max for our shunt is 75mv for 50 A current:
we will mesure only up to 20A so max is about 75mV*20/50 lets put some more*/
#define BUS_MAX_V 5 /* with 12v lead acid battery this should be enough*/
#define MAX_CURRENT 5 /* In our case this is enaugh even shunt is capable to 50 A*/
#define SHUNT_R 0.1 /* Shunt resistor in ohm */
#define SERVICE_UUID "6E40180D-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID
#define CHARACTERISTIC_UUID "6E402A37-B5A3-F393-E0A9-E50E24DCCA9E"
// BLE variables
bool deviceConnected = false;
BLECharacteristic *pCharacteristic;
INA219 monitor;
void setup() {
Wire.begin(21, 22, 400000);
Serial.begin(115200); //opens serial terminal
monitor.begin();
monitor.configure(INA219::RANGE_16V, INA219::GAIN_1_40MV, INA219::ADC_16SAMP , INA219::ADC_16SAMP , INA219::CONT_SH_BUS);
monitor.calibrate(SHUNT_R, SHUNT_MAX_V, BUS_MAX_V, MAX_CURRENT);
BLEDevice::init("SMART HELMET");
//----------BLE INITIALIZATION-------------
// Create the BLE Server
BLEServer *pServer = BLEDevice::createServer();
}
void loop() {
readQuatData(BNO055_quatCount);
// Calculate the quaternion values
BNO055_quat[0] = (float)(BNO055_quatCount[0]) / 16384.;
BNO055_quat[1] = (float)(BNO055_quatCount[1]) / 16384.;
BNO055_quat[2] = (float)(BNO055_quatCount[2]) / 16384.;
BNO055_quat[3] = (float)(BNO055_quatCount[3]) / 16384.;
pCharacteristic->setValue((uint8_t*)BNO055_quat, 16);
pCharacteristic->notify(); // Send the value to the app!
}
void readQuatData(int16_t * destination)
{
uint8_t rawData[8]; // x/y/z gyro register data stored here
readBytes(BNO055_ADDRESS, BNO055_QUA_DATA_W_LSB, 8, &rawData[0]); // Read the six raw data registers sequentially into data array
destination[0] = ((int16_t)rawData[1] << 8) | rawData[0] ; // Turn the MSB and LSB into a signed 16-bit value
destination[1] = ((int16_t)rawData[3] << 8) | rawData[2] ;
destination[2] = ((int16_t)rawData[5] << 8) | rawData[4] ;
destination[3] = ((int16_t)rawData[7] << 8) | rawData[6] ;
}
Error I am getting:
C:\Users\Boris\Documents\Arduino\pokus_BNO055_ESP32\BNO_jedna_charka\BNO_jedna_charka.ino: In function 'void loop()':
BNO_jedna_charka:216:36: error: 'readQuatData' was not declared in this scope
readQuatData(BNO055_quatCount);
^
C:\Users\Boris\Documents\Arduino\pokus_BNO055_ESP32\BNO_jedna_charka\BNO_jedna_charka.ino: In function 'void readQuatData(int16_t*)':
BNO_jedna_charka:282:66: error: 'readBytes' was not declared in this scope
readBytes(BNO055_ADDRESS, BNO055_QUA_DATA_W_LSB, 8, &rawData[0]); // Read the six raw data registers sequentially into data array
^
C:\Users\Boris\Documents\Arduino\pokus_BNO055_ESP32\BNO_jedna_charka\BNO_jedna_charka.ino: In function 'bool initBNO055()':
BNO_jedna_charka:346:64: error: 'writeByte' was not declared in this scope
writeByte(BNO055_ADDRESS, BNO055_OPR_MODE, BNO055_CONFIGMODE );
^
C:\Users\Boris\Documents\Arduino\pokus_BNO055_ESP32\BNO_jedna_charka\BNO_jedna_charka.ino: In function 'void accelgyroCalBNO055(float*, float*)':
BNO_jedna_charka:390:49: error: 'writeByte' was not declared in this scope
writeByte(BNO055_ADDRESS, BNO055_PAGE_ID, 0x00);
^
BNO_jedna_charka:401:65: error: 'readBytes' was not declared in this scope
readBytes(BNO055_ADDRESS, BNO055_ACC_DATA_X_LSB, 6, &data[0]); // Read the six raw data registers into data array
^
BNO_jedna_charka:430:65: error: 'readBytes' was not declared in this scope
readBytes(BNO055_ADDRESS, BNO055_GYR_DATA_X_LSB, 6, &data[0]); // Read the six raw data registers into data array
^
C:\Users\Boris\Documents\Arduino\pokus_BNO055_ESP32\BNO_jedna_charka\BNO_jedna_charka.ino: In function 'void magCalBNO055(float*)':
BNO_jedna_charka:530:64: error: 'writeByte' was not declared in this scope
writeByte(BNO055_ADDRESS, BNO055_OPR_MODE, BNO055_CONFIGMODE );
^
exit status 1
'readQuatData' was not declared in this scope
C:\Users\Boris\Documents\Arduino\ina219_pokus_stackoverflow\ina219_pokus_stackoverflow.ino: In function 'void loop()':
ina219_pokus_stackoverflow:45:32: error: 'readQuatData' was not declared in this scope
readQuatData(BNO055_quatCount);
^
C:\Users\Boris\Documents\Arduino\ina219_pokus_stackoverflow\ina219_pokus_stackoverflow.ino: In function 'void readQuatData(int16_t*)':
ina219_pokus_stackoverflow:63:66: error: 'readBytes' was not declared in this scope
readBytes(BNO055_ADDRESS, BNO055_QUA_DATA_W_LSB, 8, &rawData[0]); // Read the six raw data registers sequentially into data array
^
exit status 1
'readQuatData' was not declared in this scope
Thanks for any help.
Boris
In C and C++ you have to declare functions before you call them.
You can either do that by defining the function like you did here:
void readQuatData(int16_t * destination)
{
uint8_t rawData[8]; // x/y/z gyro register data stored here
readBytes(BNO055_ADDRESS, BNO055_QUA_DATA_W_LSB, 8, &rawData[0]); // Read the six raw data registers sequentially into data array
destination[0] = ((int16_t)rawData[1] << 8) | rawData[0] ; // Turn the MSB and LSB into a signed 16-bit value
destination[1] = ((int16_t)rawData[3] << 8) | rawData[2] ;
destination[2] = ((int16_t)rawData[5] << 8) | rawData[4] ;
destination[3] = ((int16_t)rawData[7] << 8) | rawData[6] ;
}
Or you can do it by using a function declaration like this:
void readQuatData(int16_t * destination);
You're calling readQuatData() before you declare it, so you're getting this error.
You can either move your definition of the function before the places that you use it, or you can declare it before you use it, like so:
INA219 monitor;
void readQuatData(int16_t * destination);
void setup() {
I placed it before the call to setup() as declaring everything you need to declare at the start of the file, before the code, is usually cleaner and more maintainable than scattering declarations throughout the code.
You'll need to do this for writeByte() and readBytes(). These seem to be missing from the code you shared, so you're on your own with them, but you'd do the same sort of thing - either define them before you use them, or add a declaration for them before you use them.

Creating a lookup table in CHISEL

I am trying to create a lookup table in Chisel of width 72 bits and 1024 entries. These 1024 entries are stored separately in a file, which I read into my code. The code I have written so far is:
import Chisel._
import scala.io.Source._
module mdlNm {
// function to read entries from file 'omega_i.dat'
def fileRead() = {
val fileIn = fromFile("omega_i.dat").getLines.toList
val num = fileIn.map(i => BigInt(i, 16)) // converting the hexadecimal entries from string to BigInt
val uInt = num.map(i => UInt(i, width = 72)) // converting BigInt entries to UInt of width 72
ROM (uInt) // Chisel construct for creating an LUT for fixed entries
}
// The above LUT is later read as follows:
val in = Bits("h123") // Any 10-bit input to the LUT
val lutOut = fileRead().read(in) // Value read from the LUT
}
The above code throws up many errors of the form:
cppBackend//sinCos.cpp:2407:23: error: ‘T1785’ was not declared in this scope
{ T425.put(1018, 0, T1785[0]); T425.put(1018, 1, T1785[1]);}
^
cppBackend//sinCos.cpp:2408:23: error: ‘T1786’ was not declared in this scope
{ T425.put(1019, 0, T1786[0]); T425.put(1019, 1, T1786[1]);}
^
cppBackend//sinCos.cpp:2409:23: error: ‘T1787’ was not declared in this scope
{ T425.put(1020, 0, T1787[0]); T425.put(1020, 1, T1787[1]);}
^
cppBackend//sinCos.cpp:2410:23: error: ‘T1788’ was not declared in this scope
{ T425.put(1021, 0, T1788[0]); T425.put(1021, 1, T1788[1]);}
^
cppBackend//sinCos.cpp:2411:23: error: ‘T1789’ was not declared in this scope
{ T425.put(1022, 0, T1789[0]); T425.put(1022, 1, T1789[1]);}
^
cppBackend//sinCos.cpp:2412:23: error: ‘T1790’ was not declared in this scope
{ T425.put(1023, 0, T1790[0]); T425.put(1023, 1, T1790[1]);}
However, when I change the width of uInt to any number <= 64, no such issues arise and the code works properly.
Is there an alternative way to create an LUT of the size I specified above, in Chisel? Or am I doing something wrong in the above code?
Please help.
In chisel3,, the current version, this would be constructed a little bit differently. VecInit is used instead of ROM
I would recommend the creation of an intermediate value lut to hold the rom created by buildLookupTable
because each call to buildLookupTable would read the file again and create another rom.
import chisel3._
import chisel3.util._
import firrtl.FileUtils
class SomeModule extends MultiIOModule {
def buildLookupTable(): Vec[UInt] = {
VecInit(FileUtils.getLines("file1.dat").map { s => BigInt(s, 16).U })
}
val lut = buildLookupTable()
// The above LUT is later read as follows:
val in = 0x123.U // Any 10-bit input to the LUT
val lutOut = lut(in) // Value read from the LUT
// rest of module
...
}
I don't know what the problem with lengths you had but I have tested the above with UInts with widths of 500 and it works fine.

DragDrop setting SelectionData format

I am playing a little with drag and drop under gtk#.
When calling
protected virtual void OnDragDataGet (object o, Gtk.DragDataGetArgs args)
{
byte[] data = GetSomeData();
args.SelectionData.Set(args.Context.Targets[0], 0, data);
}
an error occurs:
Gtk-CRITICAL **: _gtk_selection_request: assertion `(data.format >= 8) && (data.format % 8 == 0)' failed
however setting the format to 8 works fine:
protected virtual void OnDragDataGet (object o, Gtk.DragDataGetArgs args)
{
byte[] data = GetSomeData();
args.SelectionData.Set(args.Context.Targets[0], 8, data);
}
I have found some examples on drag and drop, all use 8 as the format for sending the data. (Using 0 was acually a typo.) However I have not found what this format does, or why 8 works, whereas 0 does not.
Can someone explain what "fomat" does ?
From
http://www.go-mono.com/docs/index.aspx?link=M%3aGtk.SelectionData.Set%28Gdk.Atom%2cSystem.Int32%2cSystem.Byte[]%29:
format (number of bits in a unit) - set this to 8 and encode your data as UTF-8