Go Down

### Topic: How to compress an hexadecimal number into a short string? (Read 1 time)previous topic - next topic

#### pekabo

#15
##### May 18, 2018, 10:42 amLast Edit: May 18, 2018, 10:46 am by pekabo
I tried follwing code changes. In the old code i converted it to HEX, now i get it raw.

old code
Serial.print(nano.msg[31 + x], HEX);

new code
Serial.print(nano.msg[31 + x])

Code: [Select]
`for (byte x = 0 ; x < tagEPCBytes ; x++)      {         Serial.print(nano.msg[31 + x]);        Serial.print(F(" "));      }      Serial.print(F("]"));`

I get this in Serial Monitor

Code: [Select]
`226 0 0 23 34 10 0 55 20 112 127 158226 0 0 23 34 10 0 57 20 112 127 159226 0 0 23 34 10 0 56 20 112 127 151226 0 0 23 34 10 0 81 20 112 127 189226 0 0 23 34 10 0 113 20 112 127 223`

How to store the Values in a 2 dimensional array[50][12] without duplicates and with a minimum on Bytes

#### Robin2

#16
##### May 18, 2018, 11:46 amLast Edit: May 18, 2018, 11:46 am by Robin2
Never mind about converting the bytes to something a human can read - which is the purpose of Serial.prin().

Just save the bytes into an array

Code: [Select]
`byte myArray[5][12]; // creates 5 arrays each with 12 bytes (I hope) `

Code: [Select]
`for (byte x = 0 ; x < 12 ; x++){          myArray[0][x] = nano.msg[31 + x]; // stores the values in the first of the 5 rows}`

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### pekabo

#17
##### May 18, 2018, 12:04 pm
If I try

Code: [Select]
`byte tagEPCBytes[50][12];`
Code: [Select]
`for (byte x = 0 ; x < tagEPCBytes ; x++)      {         tagEPCBytes[counter][x] = nano.msg[31 + x];        Serial.print(nano.msg[31 + x]);        Serial.print(F(" "));      }`

I get the following errors
Code: [Select]
`error: invalid types 'byte {aka unsigned char}[int]' for array subscript         tagEPCBytes[counter][x] = nano.msg[31 + x];                            ^invalid types 'byte {aka unsigned char}[int]' for array subscript`

I tried to change the type of tagEPCBytes[50][12]; to int or char. No one works.

#### Robin2

#18
##### May 18, 2018, 12:42 pm
Code: [Select]
`for (byte x = 0 ; x < tagEPCBytes ; x++)      {         tagEPCBytes[counter][x] = nano.msg[31 + x];        Serial.print(nano.msg[31 + x]);        Serial.print(F(" "));      }`

As you have not posted the complete program I can't tell how the variable counter is defined

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### pekabo

#19
##### May 18, 2018, 02:07 pm
I wrote all the code in post #7.
From then on, only the code that was changed

Code: [Select]
`int counter = 0;`

after each scanned TAG the counter is increased by 1

Code: [Select]
`Serial.println(counter++);`

I think, I've got the wrong type. I am trying to store the an int in a byte. I try to cast it to byte

Code: [Select]
`tagEPCBytes[(byte)counter][x] = nano.msg[31 + x];`
this gives me following error
Code: [Select]
`error: invalid types 'byte {aka unsigned char}[byte {aka unsigned char}]' for array subscript         tagEPCBytes[(byte)counter][x] = nano.msg[31 + x];`

now i am confused

#### Robin2

#20
##### May 18, 2018, 02:27 pm
now i am confused
So am I.

Help us to help you. Post the complete program that gave rise to the error mentioned in Reply #17 and don't expect us to stitch things together - mainly because we might make a mistake while doing so.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### gfvalvo

#21
##### May 18, 2018, 02:32 pm
Help us to help you. Post the complete program that gave rise to the error mentioned in Reply #17 and don't expect us to stitch things together - mainly because we might make a mistake while doing so.
...R
It's definitely a lot easier to copy / paste into the IDE if you only have to copy from one place.

#### pekabo

#22
##### May 18, 2018, 02:39 pm
This code
Code: [Select]
`#include <SoftwareSerial.h> SoftwareSerial softSerial(2, 3); #include "SparkFun_UHF_RFID_Reader.h" RFID nano; #define BUZZER1 10#define BUZZER2 9boolean tagDetected; long lastSeen = 0; int counter = 0; void setup(){  Serial.begin(115200);  pinMode(BUZZER1, OUTPUT);  pinMode(BUZZER2, OUTPUT);  digitalWrite(BUZZER2, LOW);   while (!Serial);   if (setupNano(38400) == false)   {    Serial.println(F("Das Modul hat nicht reagiert. Bitte überprüfen Sie die Anschlüsse."));    while (1);   }  nano.setRegion(REGION_NORTHAMERICA);     nano.setReadPower(2700);     nano.startReading();   Serial.println("Scannprozess läuft!");  lowBeep();   tagDetected = false;}void loop(){  byte myEPC[12];   byte myEPClength;  byte responseType = 0;  byte tagEPCBytes[50][12];  if (nano.check() == true)   {    byte responseType = nano.parseResponse();     if (responseType == RESPONSE_IS_TAGFOUND)    {            long timeStamp = nano.getTagTimestamp();       byte tagEPCBytes = nano.getTagEPCBytes();       Serial.print(F("RFID-Tag detektiert: "));      Serial.println(counter++);                 Serial.print(F("RFID-Daten EPC["));      for (byte x = 0 ; x < tagEPCBytes ; x++)      {        if (nano.msg[31 + x] < 0x10) Serial.print(F("0"));         Serial.print(nano.msg[31 + x], HEX);        Serial.print(F(" "));      }            Serial.println(F(" "));            Serial.print(F("Bin-Daten["));      for (byte x = 0 ; x < tagEPCBytes ; x++)      {         tagEPCBytes[(byte *) &counter][x] = nano.msg[31 + x];        Serial.print(nano.msg[31 + x]);        if (x != 11) Serial.print(F(" "));      }      Serial.print(F("] "));            if (tagDetected == false)       {        tagDetected = true;        highBeep();      }      else if (millis() - lastSeen > 250)       {        highBeep();      }      lastSeen = millis();    }  }  if (tagDetected == true && (millis() - lastSeen) > 1000)  {    Serial.println(F("Kein RFID-Tag gefunden..."));    tagDetected = false;    lowBeep();  }    if (Serial.available())  {    nano.stopReading();     Serial.read();     Serial.println("Scannen angehalten. Drücken Sie die Taste, um fortzufahren.");    while (!Serial.available());    Serial.read();     nano.startReading();   }}boolean setupNano(long baudRate){  nano.begin(softSerial);         softSerial.begin(baudRate);   while (!softSerial);     while (softSerial.available()) softSerial.read();  nano.getVersion();  if (nano.msg[0] == ERROR_WRONG_OPCODE_RESPONSE)  {        nano.stopReading();    Serial.println(F("Modul liest kontinuierlich. Modul soll kontinuierlich lesen beenden...."));    delay(1500);  }  else  {        softSerial.begin(115200);     nano.setBaud(baudRate);     softSerial.begin(baudRate);   }    nano.getVersion();  if (nano.msg[0] != ALL_GOOD) return (false);     nano.setTagProtocol();   nano.setAntennaPort();   return (true); }void lowBeep(){  tone(BUZZER1, 130, 150);   }void highBeep(){  tone(BUZZER1, 2093, 150);   }`

gives me following Error

Code: [Select]
`error: invalid types 'byte {aka unsigned char}[byte {aka unsigned char}]' for array subscript         tagEPCBytes[(byte *) &counter][x] = nano.msg[31 + x];                                         ^exit status 1invalid types 'byte {aka unsigned char}[byte {aka unsigned char}]' for array subscript`

#### Robin2

#23
##### May 18, 2018, 03:02 pmLast Edit: May 18, 2018, 03:02 pm by Robin2
First off the line should simple be like this
Code: [Select]
`tagEPCBytes[counter][x] = nano.msg[31 + x];`

but the real reason you are having a problem is because tagEPCBytes is not an array. It is defined on line 63 as a byte variable.

...R

PS ... I hope you now see the value of posting a complete program every time.
Two or three hours spent thinking and reading documentation solves most programming problems.

#### BulldogLowell

#24
##### May 18, 2018, 03:07 pmLast Edit: May 18, 2018, 03:09 pm by BulldogLowell Reason: image
Code: [Select]
`  byte tagEPCBytes[50][12]; //<<<<<<<<<<<<<<<<<<<<<<<<  if (nano.check() == true)   {    byte responseType = nano.parseResponse();     if (responseType == RESPONSE_IS_TAGFOUND)    {            long timeStamp = nano.getTagTimestamp();       byte tagEPCBytes = nano.getTagEPCBytes();  //<<<<<<<<<<<<<<<<<<<<<<<<`

Code: [Select]
`warning: unused variable 'tagEPCBytes' [-Wunused-variable]   byte tagEPCBytes[50][12];`

set your compiler warnings to ALL

#25

#### pekabo

#26
##### May 18, 2018, 03:22 pm
Error with compiler warnings to ALL

Code: [Select]
`Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Uno"D:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware D:\Program Files (x86)\Arduino\hardware -hardware AppData\Local\Arduino15\packages -tools D:\Program Files (x86)\Arduino\tools-builder -tools D:\Program Files (x86)\Arduino\hardware\tools\avr -tools AppData\Local\Arduino15\packages -built-in-libraries D:\Program Files (x86)\Arduino\libraries -libraries \Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path AppData\Local\Temp\arduino_build_354337 -warnings=all -build-cache AppData\Local\Temp\arduino_cache_815643 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2 -prefs=runtime.tools.arduinoOTA.path=AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.1.1 -prefs=runtime.tools.avrdude.path=AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9 -verbose RFID-Array.inoD:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware D:\Program Files (x86)\Arduino\hardware -hardware AppData\Local\Arduino15\packages -tools D:\Program Files (x86)\Arduino\tools-builder -tools D:\Program Files (x86)\Arduino\hardware\tools\avr -tools AppData\Local\Arduino15\packages -built-in-libraries D:\Program Files (x86)\Arduino\libraries -libraries \Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path AppData\Local\Temp\arduino_build_354337 -warnings=all -build-cache AppData\Local\Temp\arduino_cache_815643 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2 -prefs=runtime.tools.arduinoOTA.path=AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.1.1 -prefs=runtime.tools.avrdude.path=AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9 -verbose RFID-Array.inoUsing board 'uno' from platform in folder: AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21Using core 'arduino' from platform in folder: AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21Detecting libraries used..."AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\variants\standard" "AppData\Local\Temp\arduino_build_354337\sketch\RFID-Array.ino.cpp" -o "nul""AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\variants\standard" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SoftwareSerial\src" "AppData\Local\Temp\arduino_build_354337\sketch\RFID-Array.ino.cpp" -o "nul""AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\variants\standard" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SoftwareSerial\src" "-I\Arduino\libraries\SparkFun_Simultaneous_RFID_Tag_Reader_Library-master\src" "AppData\Local\Temp\arduino_build_354337\sketch\RFID-Array.ino.cpp" -o "nul"Using cached library dependencies for file: AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SoftwareSerial\src\SoftwareSerial.cpp"AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\variants\standard" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SoftwareSerial\src" "-I\Arduino\libraries\SparkFun_Simultaneous_RFID_Tag_Reader_Library-master\src" "\Arduino\libraries\SparkFun_Simultaneous_RFID_Tag_Reader_Library-master\src\SparkFun_UHF_RFID_Reader.cpp" -o "nul"Generating function prototypes..."AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\variants\standard" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SoftwareSerial\src" "-I\Arduino\libraries\SparkFun_Simultaneous_RFID_Tag_Reader_Library-master\src" "AppData\Local\Temp\arduino_build_354337\sketch\RFID-Array.ino.cpp" -o "AppData\Local\Temp\arduino_build_354337\preproc\ctags_target_for_gcc_minus_e.cpp""D:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "AppData\Local\Temp\arduino_build_354337\preproc\ctags_target_for_gcc_minus_e.cpp"Sketch wird kompiliert..."AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\variants\standard" "-IAppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SoftwareSerial\src" "-I\Arduino\libraries\SparkFun_Simultaneous_RFID_Tag_Reader_Library-master\src" "AppData\Local\Temp\arduino_build_354337\sketch\RFID-Array.ino.cpp" -o "AppData\Local\Temp\arduino_build_354337\sketch\RFID-Array.ino.cpp.o"RFID-Array.ino: In function 'void loop()':RFID-Array:99: error: invalid types 'byte {aka unsigned char}[byte {aka unsigned char}]' for array subscript         tagEPCBytes[(byte *) &counter][x] = nano.msg[31 + x];                                         ^RFID-Array.ino:79:12: warning: unused variable 'timeStamp' [-Wunused-variable]       long timeStamp = nano.getTagTimestamp(); //Liefert die Zeit (ms) seit der letzten Keep-Alive-Meldung.            ^RFID-Array.ino:67:8: warning: unused variable 'myEPC' [-Wunused-variable]   byte myEPC[12]; //Die meisten EPCs sind 12 Bytes groÃŸ.        ^RFID-Array.ino:68:8: warning: unused variable 'myEPClength' [-Wunused-variable]   byte myEPClength;        ^RFID-Array.ino:69:8: warning: unused variable 'responseType' [-Wunused-variable]   byte responseType = 0;        ^RFID-Array.ino:71:8: warning: unused variable 'tagEPCBytes' [-Wunused-variable]   byte tagEPCBytes[50][12];        ^Bibliothek SoftwareSerial in Version 1.0 im Ordner: AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\SoftwareSerial  wird verwendetBibliothek SparkFun_Simultaneous_RFID_Tag_Reader_Library-master in Version 1.0.4 im Ordner: \Arduino\libraries\SparkFun_Simultaneous_RFID_Tag_Reader_Library-master  wird verwendetexit status 1invalid types 'byte {aka unsigned char}[byte {aka unsigned char}]' for array subscript`

#### Robin2

#27
##### May 18, 2018, 05:23 pmLast Edit: May 18, 2018, 06:51 pm by Robin2
The problem is that you have two variable using the same name. Give them different names.

You have an global array local to the loop function
Code: [Select]
`byte tagEPCBytes[50][12];`
and a local byte with the same name local to that block of code
Code: [Select]
`byte tagEPCBytes = nano.getTagEPCBytes();`
and the local variable in the block takes precedence.

The byte variable tagEPCBytes is used to hold the number of bytes in the tag so maybe it would be better called tagEPCByteCount

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### BulldogLowell

#28
##### May 18, 2018, 06:30 pm
You have an global array local to the loop function
Code: [Select]
` byte tagEPCBytes[50][12];`
and a local byte with the same name local to that block of code
the array name acts like a pointer... thus your errors/warnings

#### Robin2

#29
##### May 18, 2018, 06:52 pm
@BulldogLowell, thanks for spotting that. I have updated my Reply.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up