We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi guys. i have a problem with monitoring my x values by using lcd. My problem here is the x value shown in the processing and at the lcd is not tally.. here is my processing and arduino coding.
processing:
import processing.serial.*;
Serial myPort; // Create object from Serial clas
void setup() {
size (800, 600);
String portName = Serial.list()[0];
myPort = new Serial(this,"COM3", 9600);
}
void draw() {
background(50);
fill(150);
stroke(255);
ellipse(mouseX, mouseY, 40, 40);
println(mouseX + " : " + mouseY);
myPort.write(mouseX);
printArray(Serial.list());
}
arduino:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
char val; // Data received from the serial port
int ledPin = 4;
int incomingbyte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
lcd.begin(16,2);
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingbyte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingbyte, DEC);
lcd.setCursor(0,0);
lcd.print("x:");
lcd.setCursor(3,0);
lcd.print(incomingbyte);
lcd.setCursor(0,1);
lcd.print("");
}
}
Answers
Your sketch and screen is showing your x value. What do you mean with a tally?
Check this example: https://www.arduino.cc/en/Tutorial/Dimmer
Notice your mouseX, an integer field, is converted to a byte as indicated in the previous post. A byte is limited to a range of 0 to 255. Your mouseX will reflect the width of your sketch. In your case, mouseX goes from 0 to 799.
Check previous examples here: https://forum.processing.org/two/search?Search=readbytesuntil
One last thing, to format your code in this forum, you select your code and hit ctrl+o. Ensure there is a line above and below your code block.
Kf
@kfrajer the exact value on screen and the value on the lcd is different... the value should show from 0 to 800, but on my lcd it show different value than at the processing screen.
Change the size to screen to
size(256,256);
and see if that works as expected..Kf
@kfrajer no it doesnt work as expected. if im not mistaken it show ascii character on the lcd. wht if i want to change to string character. what code should i modify.
Try
lcd.print(incomingbyte,DEC);
Kf
@kfrajer still the same
I do not have a device to reproduce your observations. This is what I would do if I were. Be mindful, I didn't have the chance to test the code so you might have some simple errors, if any (Hopefully none fatal). My intention is to send known data from processing to arduino. I am sending numbers from 0 to 800, one every second. Arduino will receive the data, dsiplay what it received and send it back to Processing. Processing will intercept this data and it will print it out in the Processing's console.
Kf
Processing sketch
Arduino code
}
serial.read () arduino reads only the first byte, and parseInt () returns the first valid (long) integer number from the serial buffer. change:
//
arduino:
https://forum.Processing.org/two/discussions/tagged/lcd