How to send the hex values from processing through serial ?.

edited December 2016 in Arduino

I need to send this 11 Series bytes(0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x01,0x00,0x05) from processing to serial.

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 got error while using this byte data type

Which data type I need to use for this kind of HEX values ?.

Tagged:

Answers

  • Have you tried making collect an int[]?

  • No. wait I will check and update

  • I receive like this ïÿÿÿÿ

  • edited December 2016

    baud rate is same. but I got like this ïÿÿÿÿ

    import processing.serial.*;
    int value = 0;
    Serial myPort;  
    int val;        
    int 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;
      }
    }
    

    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 57600 bps
      mySerial.begin(57600); // Software Serial communication at 57600 bps. read other port what actually going 
    }
    
    void loop() {
      while (Serial.available()) { // If data is available to read,
         mySerial.write(Serial.read()); // read it and store it in val
      }
    }
    
  • You need to learn how to format your code in the forum.
    Press the gear icon to edit your post, select your code and press ctrl + o. Leave a line above and below.

  • Thank you very much for this info. I used arduino forum. This forum is new for me. thank you. Now I edited Please and guide me. Thank you

  • Well, start by checking if the Arduino part of the code works.
    Instead of just relaying whatever the Arduino receives from Processing, remove processing all together and trigger the sending of data using a button in Arduino.

  • Yes. I tested it is working manually

  • And it works with lower baud rates?

  • No, I checked all baud rates. different error.

  • I was checked from 4800.

  • even if I send 0xEF single byte. that also displaying like this 'i.

  • That would appear to be correct!? That looks like the letter for that hex code in UTF-8 http://www.utf8-chartable.de/

    What are you expecting to see? What is on the receiving end?

  • I need same bytes. If I send 0xEF then I need same at another end

  • As I said, it looks like you're receiving the same bytes! How are you receiving and displaying them?

  • And how do you know it isn't? As neilcsmith says, it appears to be correct.

  • Quick follow up after reading some of your earlier comments. Your initial sequence of bytes is

    0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x03,0x01,0x00,0x05

    If you ignore the bytes that don't relate to visible characters in UTF-8 then the remaining sequence is

    0xEF,0xFF,0xFF,0xFF,0xFF

    That as a String is ïÿÿÿÿ That's not a coincidence! ;-)

Sign In or Register to comment.