How to Serial write integer numbers??
in
Integration and Hardware
•
11 months ago
Hi all, I'm a very rookie programmer and I need someone to help me.
I just bought Arduino UNO to build a numeric control, like a drawing or cutting plotter. Since I need to read lines from a GCode file containing alphabetic 'rules' and numeric coordinates, I'm trying to learn how to communicate integer numbers through serial port from Processing to Arduino.
Thanks the Arduino's Serial Monitor I could test that this sketch works, so that I think that's the Processing one that does not..
Here are the little sketches I compiled:
- Arduino:
Here is the Processing sketch that prints correctly numbers from 100 to 1000, but not through the serial port. Whats's wrong??
Thank you, bye.
I just bought Arduino UNO to build a numeric control, like a drawing or cutting plotter. Since I need to read lines from a GCode file containing alphabetic 'rules' and numeric coordinates, I'm trying to learn how to communicate integer numbers through serial port from Processing to Arduino.
Thanks the Arduino's Serial Monitor I could test that this sketch works, so that I think that's the Processing one that does not..
Here are the little sketches I compiled:
- Arduino:
- String inString="";
- void setup () {
- for (int i=1;i<14;i++) {
- pinMode (i, OUTPUT);
- }
- Serial.begin (9600);
- }
- void loop () {
- if (Serial.available() ) {
- int inChar = Serial.read();
- if (inChar == '\n') {
- int t = inString.toInt();
- Serial.println (t);
- LHigh();
- delay(t);
- LLow();
- delay(t);
- inString="";
- }
- else {
- if(isDigit(inChar)) {
- inString += (char)inChar;
- }
- }
- }
- }
- void LHigh() {
- for (int pin=1;pin<14;pin++) {
- digitalWrite (pin, HIGH);
- }
- }
- void LLow() {
- for (int pin=1;pin<14;pin++) {
- digitalWrite (pin, LOW);
- }
- }
Here is the Processing sketch that prints correctly numbers from 100 to 1000, but not through the serial port. Whats's wrong??
- import processing.serial.*;
- Serial myPort;
- void setup () {
- String portName = Serial.list()[0];
- myPort = new Serial(this, portName, 9600);
- }
- void draw() {
- for (int DTIME=100; DTIME<1001;DTIME +=100) {
- myPort.write (DTIME);
- println (DTIME);
- }
- noLoop();
- }
Thank you, bye.
1