"Building" a PDE / IDE connection to pass ongoing and changing data from PC (W10/64) to an Arduino board with an LCD. Eventual goal is an LCD-display clock. *My existing code succeeds,up to a point.*.
In the test set-up the send / receive. exchange works for about 25 cycles (1 second per cycle). The display then repeatedly displays an unchanging character from the string, usually the inital character. If I restart the PDE (using the "play" icon) the send / received / display cycle restarts.
I use the LCD display output for two reasons: (1) The goal is an LCD display, (2) This reduces the problem of a COM port clash between the PDE and IDE; both use COMM 5.
Code pasted below, I hope with proper easy-to-read format
.
Tom Kane> please format code with </> button * homework policy * asking questions
------------------ PDE --------------------------------
</>// PDE to send-to-port one character for IDE to read and display.
import processing.serial.*;
Serial myPort;
float background_color;
int loop_Count;
char count_Text;
String write_String;
String slc;
void setup () {
size (500, 500); // Size of the serial window (adjust as wish)
myPort = new Serial (this, “COM5”, 9600); // Set the com port and baud
myPort.bufferUntil ( ‘\n’ ); // Receiving the data from the Arduino IDE
loop_Count = 0;
}
void SerialEvent (Serial myPort) {
background_color = float (myPort.readStringUntil ( ‘\n’ ));
}
void draw (){
background (150, 50, background_color); // inital background colour . . .
loop_Count = loop_Count + 1;
String slc = ""+loop_Count;
write_String = slc + " WED";
// write_String = “WED”;
myPort.write (write_String); // send a character to the COMM port
delay(10000);
}
----------------- IDE ---------------------------
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char recv_Char = ‘K’;
int analogPin = A0;
int buffer_avail;
void setup() {
Serial.begin(9600);
// Initialise the LCD
lcd.begin(16, 2); //Initialize the 16x2 LCD
}
void loop() {
lcd.clear();
lcd.print(“Read from comm”);
delay(3000);
// variety of codes to try reading from the port
// pick one by üncommented it.
// recv_Char = analogRead(analogPin);
recv_Char = Serial.read();
//
lcd.clear();
lcd.setCursor(0,0);
lcd.print("recv_Char: ");
lcd.print(recv_Char);
delay(10000);
}