How to send hex values from Processing through serial

Dear Friends,

I want to send the hex value from processing software to my Arduino UNO through serial communication.

For Example I want to send this data through serial to adruino
0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x01,0x00,0x05

this is for collect the finger image in finger print module.

I already done using arduino programming. Now I want to implement in GUI format. So I am using processing software to create a GUI.

I just making simple example but I cant send the hex value through serial.

So how to send the HEX values through serial to arduino.

In processing have no uint8_t data type so I just used string

Processing code:

import processing.serial.*;
int value = 0;
Serial myPort;  
int val;        
String collect[] = {"0xEF","0x01","0xFF","0xFF","0xFF","0xFF","0x01","0x00","0x03","0x01","0x00","0x05"};

void setup() 
{
  size(200, 200);
  myPort = new Serial(this, "COM6", 57600);
}

void draw() {
  fill(value,0,255);
  rect(25, 25, 50, 50);
}

void mouseClicked() {
  if (value == 0) {
    value = 255;
    myPort.write(collect[0]);
    myPort.write(collect[1]);
    myPort.write(collect[2]);
    myPort.write(collect[3]);
    myPort.write(collect[4]);
    myPort.write(collect[5]);
    myPort.write(collect[6]);
    myPort.write(collect[7]);
    myPort.write(collect[8]);
    myPort.write(collect[9]);
    myPort.write(collect[10]);
    myPort.write(collect[11]);
  } else {
    value = 0;
  }
}

Arduino Code

#include <SoftwareSerial.h>

char val; // Data received from the serial port
int ledPin = 13; // Set the pin to digital I/O 4

SoftwareSerial mySerial(2,3);


void setup() {
 pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
 Serial.begin(57600); // Start serial communication at 9600 bps
 mySerial.begin(57600);
}
 
void loop() {
 while (Serial.available()) { // If data is available to read,
 mySerial.write(Serial.read()); // read it and store it in val
 }
 }

Finger print module connected with pin 2,3

I want to send the hex value from processing software to my Arduino UNO through serial communication.

The VALUE that you send is in binary, not HEX, not decimal, not base 27.

Sending the data FROM Processing TO the Arduino, to have a GUI doesn't make sense.

You are not sending a HEX value. You are sending an array of strings.

 mySerial.write(Serial.read()); // read it and store it in val

Absolutely stupid comment. That is NOT what that code does.

The instance name is stupid, too. You do NOT have a mySerial connected to the Arduino. Why doesn't the name match the actual hardware?

The Serial.read() method returns an int/ The write() method does not have an overload that takes an int, so the actual overload that is called truncates the data somehow. YOU need to understand how it does that.

You CAN take control:

   if(Serial.available() > 0)
   {
       char letter = Serial.read();
       mySerial.write(letter);

}

But, it is extremely unlikely that whatever is connected to the Arduino is expecting the STRING of characters "0xEF0x010xFF0xFF0xFF0xFF0x010x000x030x010x000x05", which is what you are sending.

PaulS JI,

Just I edit the example codes from processing in serial library. (I forgot to delete the command line)

Yes I know that is the array of string. I cant send the HEX value through serial.
(I tried in many ways like using uint8_t data types in processing that said error) So that is why I using string array;

In Processing side
myPort.write(0xEF);
function send exact hex value ?.

In my hardware side I just hook up my finger print module with my UNO(pin2 and pin3). using software serial.

That is my question How to send the hex value form processing through serial.

SureshKumar2610:
(I tried in many ways like using uint8_t data types in processing that said error)

How about using ‘byte’ as a datatype?

Whandall:
How about using 'byte' as a datatype?

OK.

uint8_t is the data type is it or not ?.

HOW TO SEND HEX VALUES FROM PROCESSING THROUGH SERIAL

Stop shouting at us.

 mySerial.write(Serial.read()); // read it and store it in val

That isn’t storing anything anywhere.

SureshKumar2610:
PaulS JI,

I understand that “JI” is a mark of respect but no-one else is doing it on this forum. Please stop, as it is confusing for people who don’t know what it is about. To the uninitiated it looks like you got their surname wrong. I call PaulS “PaulS” and I call Robin “Robin” and so on. It does not imply lack of respect.

    myPort.write(collect[0]);

myPort.write(collect[1]);
   myPort.write(collect[2]);
   myPort.write(collect[3]);
   myPort.write(collect[4]);
   myPort.write(collect[5]);
   myPort.write(collect[6]);
   myPort.write(collect[7]);
   myPort.write(collect[8]);
   myPort.write(collect[9]);
   myPort.write(collect[10]);
   myPort.write(collect[11]);

I suggest you read up on how to use loops.

String collect[] = {"0xEF","0x01","0xFF","0xFF","0xFF","0xFF","0x01","0x00","0x03","0x01","0x00","0x05"};

These aren't hex characters. Each one is a string. You may as well have put in:

String collect[] = {"Lorem","ipsum","dolor","sit","amet","consectetur","adipiscing","elit"};

This would be hex:

byte collect[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x01,0x00,0x05};

Ok. I am not going to use JI word.

But I am always giving respect to you people. that is it,

I already done to interface the finger print module with my arduino. but I need to create a gui based. that is why I moved to processing. before I need to know the processing. So I studied and run examples, manually send the data from my processing when i click the mouse button. that time I face this problem. On that time I asking help with you guys,

I was going step by step. And I also little beginner in C++ and java.

import processing.serial.*;
int value = 0;
Serial myPort;  
int val;        
byte collect[] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x01,0x00,0x05};

void setup() 
{
  size(200, 200);
  myPort = new Serial(this, "COM6", 57600);
}

void draw() {
  fill(value,0,255);
  rect(25, 25, 50, 50);
}

void mouseClicked() {
  if (value == 0) {
    value = 255;
    for(int i=0;i<=11;i++){
      myPort.write(collect[i]);
    }
  } else {
    value = 0;
  }
}

I was using byte. But I got error in my processing

Idea;;;
If we send the character here then we can convert this string to hex at arduino code side ?.

I had a similar problem. Reading through http://forum.arduino.cc/index.php?topic=443971.0 might help.