Hallo,
How can I enter Euro sign with Serial.print?
Thx
Rita
Hallo,
How can I enter Euro sign with Serial.print?
Thx
Rita
Hi,
I don't have an Arduino at hand to test, but this page seems to contain useful explanations and examples: Arduino Playground - UTF-8
Frederick
it seems you have to output Char(128) HEX 80, to the serial device and it should show
i modified the ASCII sample that comes with the IDE to print all from 0 - 255 so it will include the euro symbol
/* ASCII table Prints out byte values in all possible formats: * as raw binary values * as ASCII-encoded decimal, hex, octal, and binary values For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII The circuit: No external hardware needed. created 2006 by Nicholas Zambetti modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. <http://www.zambetti.com> */ void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); } // modified to start with 00 even though some of these may be unprintable: int thisByte = 00; // you can also write ASCII characters in single quotes. // for example. '!' is the same as 33, so you could also use this: //int thisByte = '!'; void loop() { // prints value unaltered, i.e. the raw binary version of the // byte. The serial monitor interprets all bytes as // ASCII, so 33, the first number, will show up as '!' Serial.write(thisByte); Serial.print(", dec: "); // prints value as string as an ASCII-encoded decimal (base 10). // Decimal is the default format for Serial.print() and Serial.println(), // so no modifier is needed: Serial.print(thisByte); // But you can declare the modifier for decimal if you want to. //this also works if you uncomment it: // Serial.print(thisByte, DEC); Serial.print(", hex: "); // prints value as string in hexadecimal (base 16): Serial.print(thisByte, HEX); Serial.print(", oct: "); // prints value as string in octal (base 8); Serial.print(thisByte, OCT); Serial.print(", bin: "); // prints value as string in binary (base 2) // also prints ending line break: Serial.println(thisByte, BIN); // if printed last visible character '~' or 126, stop: if (thisByte == 255) { // modified to go all the way to 255 // This loop loops forever and does nothing while (true) { continue; } } // go on to the next character thisByte++; }
or to make it really simple
void setup() { Serial.begin(9600); } Serial.println("Printing the Euro symbol"); } int thisByte = 128; void loop() { Serial.write(thisByte); delay(1000); }
Hallo Peter ,
Thanks for reply.
Rita
Can you provide the sketch you are running for this
Thanks
Hallo Peter ,
here is my sketch :
/* * RFID/NFC module for Arduino. * Calculation the total price */ uint8_t dataRX[35];//Receive buffer. uint8_t dataTX[35];//Transmit buffer. uint8_t _UID[4];// stores the UID (unique identifier) of a card. uint8_t keyAccess[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } ;// stores the key or password. uint8_t address = 0x04;//Address to read. uint8_t ATQ[2];//Answer to request uint8_t state;//state of the process uint8_t aux[16];//Auxiliar buffer. unsigned int TotalPrice = 0;// Varialbe void setup() { //Start serial port 115200 bps: Serial.begin(115200); delay(100); Serial.print("Welcome dear customer"); delay(1000); //!It is needed to launch a simple command to sycnchronize getFirmware(); configureSAM(); } int thisByte = 128; void loop() { Serial.print("\n"); ///////////////////////////////////////////////////////////// //Get the UID Identifier init(_UID, ATQ); Serial.print("\n"); ///////////////////////////////////////////////////////////// //Auntenticate a block with his keyAccess state = authenticate(_UID, address, keyAccess); Serial.print("\n"); if ( state == 0) { Serial.println("Authentication block OK"); } else { Serial.println("Authentication failed"); } ///////////////////////////////////////////////////////////// //Read from address after authentication state = readData(address, aux); Serial.print("\n"); if (state == 0) { Serial.println("Read Price ok "); } else { Serial.println("Read failed"); } Serial.print("\n"); Serial.print("Price : "); print(aux ,1); Serial.write(thisByte); Serial.print("\n"); delay(2000); // Tota l price TotalPrice = TotalPrice + aux[0]; Serial.print("TotalPrice : "); Serial.println(TotalPrice,1); Serial.write(thisByte); delay(1000); } //********************************************************************** //!The goal of this command is to detect as many targets (maximum MaxTg) // as possible in passive mode. uint8_t init(uint8_t *UID , uint8_t *ATQ) //! Request InListPassive { Serial.flush(); dataTX[0] = 0x04; // Length lengthCheckSum(dataTX); // Length Checksum dataTX[2] = 0xD4; dataTX[3] = 0x4A; // Code dataTX[4] = 0x01; //MaxTarget dataTX[5] = 0x00; //BaudRate = 106Kbps dataTX[6] = 0x00; // Clear checkSum position checkSum(dataTX); sendTX(dataTX , 7 ,23); for (int i = 17; i < (21) ; i++){ _UID[i-17] = dataRX[i]; UID[i-17] = _UID[i-17]; } ATQ[0] = dataRX[13]; ATQ[1] = dataRX[14]; if ((dataRX[9]== 0xD5) & (dataRX[10] == 0x4B) & (dataRX[11] == 0x01)) { return 0; } else { return 1; } } //********************************************************************** //!A block must be authenticated before read and write operations uint8_t authenticate(uint8_t *UID, uint8_t blockAddress, uint8_t *keyAccess) { dataTX[0] = 0x0F; lengthCheckSum(dataTX); dataTX[2] = 0xD4; dataTX[3] = 0x40; // inDataEchange dataTX[4] = 0x01; //Number of targets dataTX[5] = 0x60; // Authentication code dataTX[6] = blockAddress; for (int i = 0; i < 6 ; i++) { dataTX[i + 7] = keyAccess[i]; } dataTX[13] = UID[0]; dataTX[14] = UID[1]; dataTX[15] = UID[2]; dataTX[16] = UID[3]; dataTX[17] = 0x00; checkSum(dataTX); sendTX(dataTX , 18 ,14); if ((dataRX[9]== 0xD5) & (dataRX[10] == 0x41) & (dataRX[11] == 0x00)) { return 0; } else { return 1; } } //********************************************************************** //!Write 16 bytes in address . uint8_t writeData(uint8_t address, uint8_t *blockData) //!Writing { Serial.print(" "); dataTX[0] = 0x15; lengthCheckSum(dataTX); // Length Checksum dataTX[2] = 0xD4; dataTX[3] = 0x40;//inDataEchange CODE dataTX[4] = 0x01;//Number of targets dataTX[5] = 0xA0;//Write Command dataTX[6] = address; //Address for (int i = 0; i < 16; i++) { dataTX[i+7] = blockData[i]; } dataTX[23] = 0x00; checkSum(dataTX); sendTX(dataTX , 24 ,14); if ((dataRX[9]== 0xD5) & (dataRX[10] == 0x41) & (dataRX[11] == 0x00)) { return 0; } else { return 1; } } //********************************************************************** //!Read 16 bytes from address . uint8_t readData(uint8_t address, uint8_t *readData) //!Reading { Serial.print(" "); dataTX[0] = 0x05; lengthCheckSum(dataTX); // Length Checksum dataTX[2] = 0xD4; // Code dataTX[3] = 0x40; // Code dataTX[4] = 0x01; // Number of targets dataTX[5] = 0x30; //ReadCode dataTX[6] = address; //Read address dataTX[7] = 0x00; checkSum(dataTX); sendTX(dataTX , 8, 30); memset(readData, 0x00, 16); if ((dataRX[9]== 0xD5) & (dataRX[10] == 0x41) & (dataRX[11] == 0x00)) { for (int i = 12; i < 28; i++) { readData[i-12] = dataRX[i]; } return 0; } else { return 1; } } //********************************************************************** //!The PN532 sends back the version of the embedded firmware. bool getFirmware(void) //! It is needed to launch a simple command to sycnchronize { Serial.print(" "); memset(dataTX, 0x00, 35); dataTX[0] = 0x02; // Length lengthCheckSum(dataTX); // Length Checksum dataTX[2] = 0xD4; // CODE dataTX[3] = 0x02; //TFI checkSum(dataTX); //0x2A; //Checksum sendTX(dataTX , 5 , 17); Serial.print("\n"); Serial.print("Your Firmware version is : "); for (int i = 11; i < (15) ; i++){ Serial.print(dataRX[i], HEX); Serial.print(" "); } Serial.print("\n"); } //********************************************************************** //!Print data stored in vectors . void print(uint8_t * _data, uint8_t length) { for (int i = 0; i < length ; i++){ Serial.print(_data[i], HEX); Serial.print(" "); } Serial.print("\n"); } //********************************************************************** //!This command is used to set internal parameters of the PN532, bool configureSAM(void)//! Configure the SAM { Serial.print(" "); dataTX[0] = 0x05; //Length lengthCheckSum(dataTX); // Length Checksum dataTX[2] = 0xD4; dataTX[3] = 0x14; dataTX[4] = 0x01; // Normal mode dataTX[5] = 0x14; // TimeOUT dataTX[6] = 0x00; // IRQ dataTX[7] = 0x00; // Clean checkSum position checkSum(dataTX); sendTX(dataTX , 8, 13); } //********************************************************************** //!Send data stored in dataTX void sendTX(uint8_t *dataTX, uint8_t length, uint8_t outLength) { Serial.print(char(0x00)); Serial.print(char(0x00)); Serial.print(char(0xFF)); for (int i = 0; i < length; i++) { Serial.print(char(dataTX[i])); } Serial.print(char(0x00)); getACK(); waitResponse();// Receive response getData(outLength); } //********************************************************************** //!Wait for ACK response and stores it in the dataRX buffer void getACK(void) { delay(5); waitResponse(); for (int i = 0; i < 5 ; i++) { dataRX[i] = Serial.read(); } } //********************************************************************** //!Wait the response of the module void waitResponse(void) { int val = 0xFF; int cont = 0x00; while(val != 0x00) { //Wait for 0x00 response val = Serial.read(); delay(5); cont ++; } } //********************************************************************** //!Get data from the module void getData(uint8_t outLength) { for (int i=5; i < outLength; i++) { dataRX[i] = Serial.read();//read data from the module. } } //********************************************************************** //!Calculates the checksum and stores it in dataTX buffer void checkSum(uint8_t *dataTX) { for (int i = 0; i < dataTX[0] ; i++) { dataTX[dataTX[0] + 2] += dataTX[i + 2]; } byte(dataTX[dataTX[0] + 2]= - dataTX[dataTX[0] + 2]); } //********************************************************************** //!Calculates the length checksum and sotres it in the buffer. uint8_t lengthCheckSum(uint8_t *dataTX) { dataTX[1] = byte(0x100 - dataTX[0]); }
Regards
Rita
Your routine that is called print() always puts a new line before it exits therefor your euro symbol will always be on a new line. remove this from the print routine and put the newline statements elsewhere if you need them
also where you do this
Serial.println vs Serial.print, the first one adds a new line before executing the next line so again adding a new line before you get to send the euro symbol, the second version does not so change your statement to the second version
The other stuff is because your talking to your PN532 on the same serial as the console, or atleast that is what it seems so when you do things like sendTX(...) it will show up on the console, as this is not really printable ascii it looks like gobbledygook
Provide your wireing schematic and or a link to the exact product your connecting and I can probably help further, I am assuming your using one of the ADAFRUIT boards but you dont say and are not showing any libraries so im guessing
Peter
Hi Peter ,
Thanks for the tip I have now the Euro sign with prices in the same row.
I have RFID 13.56 MHz / NFC Module for Arduino from Cooking Hacks https://www.cooking-hacks.com/documentation/tutorials/rfid-13-56-mhz-nfc-module-arduino-raspberry-pi-tutorial/#step3
Regards
Rita
Can you mark the appropriate answers as correct / helpful, it helps me and others who help in the community attain the badges, thanks