Sending more than 3 characters to arduino
in
Integration and Hardware
•
8 months ago
Hi !
Actually we are working on a science-based application using Processing and Arduino, we control valves and pumps by sliders and buttons from Processing sending something like :
For Digital Data :
For example, we try to send " 10220 "
10 corresponds to Digital Data
22 corresponds to the pin number
0 correspond to the value (0 = LOW, 1 = HIGH)
10[numPin][value]
For Analog Data :
From 11[numPin]0 to 11[numPin]255
11 corresponds to Analog Data
22 corresponds to the pin number
0-255 corresponds the the value
___________________________________________________________
Sadly we discovered we couldn't send more than 3 characters from Processing to Arduino using
Actually we are working on a science-based application using Processing and Arduino, we control valves and pumps by sliders and buttons from Processing sending something like :
For Digital Data :
For example, we try to send " 10220 "
10 corresponds to Digital Data
22 corresponds to the pin number
0 correspond to the value (0 = LOW, 1 = HIGH)
10[numPin][value]
For Analog Data :
From 11[numPin]0 to 11[numPin]255
11 corresponds to Analog Data
22 corresponds to the pin number
0-255 corresponds the the value
___________________________________________________________
Sadly we discovered we couldn't send more than 3 characters from Processing to Arduino using
- //corresponds to Digital Value (10) on the 22 pin sending 0 (LOW)
- port.write(10220);
so we decided to hash our code such as :
- port.write(10); //or 11
- port.write(22); //numPin needed
- port.write(0); //or 1 for Digital, 0-255 for Analog
We use the following code in Arduino to receive data with our new method (hashing one)
-
void loop()
{
if(stringComplete)
{
Serial.println(inputString);
typeDonnee = inputString.substring(0, 2);
numPin = inputString.substring(2, 4);
value = inputString.substring(4, 5);
if(typeDonnee == "10")
{
if(value == "1")
digitalWrite(numPin.toInt(), HIGH);
else if(value == "0")
digitalWrite(numPin.toInt(), LOW);
}
inputString = "";
stringComplete = false;
} //Method use to receive data from RX port
void serialEvent()
{
while(Serial.available())
{
char inChar = (char)Serial.read();
inputString += inChar;
if(inChar == '*')
{
stringComplete= true;
}
}
}
Using the hasing method (sending 10, then 0, then 22 then *) from the arduino serial monitor, it works. But while sending data from Processing it doesn't.
Do you have any idea about how we could send data from processing to Arduino ?
Thanks in advance ! :)
Do you have any idea about how we could send data from processing to Arduino ?
Thanks in advance ! :)
1