Hi,
i am very new to Arduino and i have a problem with my Code. I have a Android Application in which i want to send 4 integer values to the Arduino. I already got to work to send it as a String but i dont know what to do with the String now. The received integer values are supposed to be used as values in the loop. The Command is send via wifi to the Arduino serial port.
Maybe someone can help me with this problem, i dont know if i need to attach some code, but if needed i can attach it.
Maybe this will help.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1191880368
This has got to be prime candidate for a sticky thread, hasn't it?
Pretty please.
This has got to be prime candidate for a sticky thread, hasn't it?
Pretty please.
We have 'sticky threads' ?
If so I want to reserve one for posting with large blinking ugly colored text and possibly with jumping obnoxious GIFs, warning of the criminal behaviour of wiring leds to arduino output pins without using properly sized series current limiting resistors. I'm about to wear out the 'r' key embossing on my keyboard, having taken on the mission of indoctrinating newbies (yelling, really), and just posting a link to a sticky would be so much better and might allow my 'r' key some R&R.
Otherwise how will I ever be able to find my 'r' key when the key is finally rubbed smooth?
Lefty
Well, yes there's that, and the 'r' wear due to 'can I reset myArduino by performing a call to the reset vector?'
And how can I reset millis() back to zero without having to wait for 59 days.
And I'm still waiting for a new forum sub-topic section called "It doesn't work".
Hey thank you first but i dont get it working somehow.
i am sending my command from a java/android application in this way to a socket:
getOutputStream().write("1000".getBytes());
getOutputStream().flush();
and the arduino board is receiving the message, but can someone give me a short code, how to read the message exactly and then how to get the integer value. because when the message is received and i let it print to Serial i get:
1
000
Thank you!
You need to post the code for us to help.
Looks like you're almost there.
Okok here my current code, its used to generate a ppm signal:
int dataPin= 2;
int rxPin = 0;
int chanValue;
long summation;
int noOfChannels = 12;
int values[12] = {1700,1700,1700,1700,700,700,700,700,700,700,700,700};
char serInString[15];
void setup() {
pinMode(dataPin, OUTPUT);
Serial.begin(57600);
pinMode(rxPin, INPUT);
}
void loop()
{
readSerialString(serInString);
if( isStringEmpty(serInString) == false) {
summation=0;
for (int i = 0; i < 4 ;i++){
int value = serInString[i];
double value1 = value * (1000 / 255) + 700;
setChannelValue(value1);
}
Serial.print(serInString);
Serial.println();
for (int i = 4; i < noOfChannels ;i++){ //Do noOfChannels
setChannelValue(values[i]);
}
setChannelValueWithSynCode();
}
for (int i=0; i <= 15; i++){
serInString[i]=0;
}
}
void setChannelValue(int value) { // value : 700 to 1700
digitalWrite(dataPin, HIGH); //
delayMicroseconds(value);
digitalWrite(dataPin,LOW);
delayMicroseconds(300);
summation +=value +300;
}
void setChannelValueWithSynCode() {
double syncDelay=22500 - (summation) - 300;
digitalWrite(dataPin, HIGH); //
delayMicroseconds(syncDelay);
digitalWrite(dataPin,LOW);
delayMicroseconds(300);
}
void readSerialString (char *strArray) {
int i = 0;
if(Serial.available()) {
while (Serial.available()){
strArray[i] = Serial.read();
i++;
}
}
}
boolean isStringEmpty(char *strArray) {
if (strArray[0] == 0) {
return true;
}
else {
return false;
}
}
Serial data transmission is relatively slow. The Arduino, on the other hand, is fast. At least, relatively speaking.
When reading a packet from the serial port, you have two choices. Read all the serial data that is available. Then, wait for a while to see if some more data arrives. Maybe call delay(30000);. Then, read whatever new data has arrived, and append it to the data that has already arrived, and hope you got a complete packet.
Maybe the delay doesn't need to be quite that long...
The other solution, and one I prefer, is to have the sender application include start of packet and end of packet markers.
getOutputStream().write("[glow]<[/glow]1000[glow]>[/glow]".getBytes());
Then, the Arduino looks for a start of packet marker in the serial data. Once it finds one, it stores the remaining serial data in an array, checking each character read for the end of packet marker. If one is found, it sets a flag and breaks out of the while loop that is reading serial data.
After the while loop, check to see if the end-of-packet marker flag is true. If so, do something with the serial data received. If not, the whole packet has not yet been received.
Search the forum for "started && ended" for a complete implementation of this approach.