Send raw binary data from text input box?

edited November 2014 in Arduino

greetings,

I've just downloaded Processing 2.2.1. Tried a few examples with serial library, controlP5, etc... But can't figure out how to take some binary or hex number value from a text input box and send it over Serial in raw binary format.

e.g. I type into the text box 0xF8 or equivalent in binary 11111000 , press submit and the code sends the byte over serial just as I typed in.

here's a sample from the controlP5 library that I modified, but it does not send anything over Serial:

import processing.serial.*;
Serial myPort;  // Create object from Serial class

import controlP5.*;
ControlP5 cp5; 

String url1, url2;

void setup() {
 size(700, 400);
 cp5 = new ControlP5(this);
 cp5.addTextfield("textInput_1").setPosition(20, 100).setSize(200, 40).setAutoClear(false);
 cp5.addTextfield("textInput_2").setPosition(20, 170).setSize(200, 40).setAutoClear(false);
 cp5.addBang("Submit").setPosition(240, 170).setSize(80, 40); 

 myPort = new Serial(this, "COM3", 31250); //Arduino UNO connected to COM3
  }


void draw () {
 background(0);
}

void Submit() {
 print("the following text was submitted :");
 url1 = cp5.get(Textfield.class,"textInput_1").getText();
 url2 = cp5.get(Textfield.class,"textInput_2").getText();
 print(" textInput 1 = " + url1);
 print(" textInput 2 = " + url2);

 myPort.write(url1); // This does not write anything to the Serial COM3 port

}

thanks for any input

Answers

  • Hi. I don't know if this helps or not, but you are doing something that I was trying to do, which was specifically to use a Bang object to send data from a Textfield. I copied this and cut it down so that I am only sending output from textInput_1. Anyway, the bottom line is that it works fine for me as long as I am sending single characters (e.g. toggling a LED on and off) Eventually I am going to send an integer as a setpoint so I need to work on the data types in the code. In other words, the fundamental MyPort.write mechanism works fine, but you probably need to look deeper into the data format if you wish to send and receive as binary, etc.

Sign In or Register to comment.